models icon indicating copy to clipboard operation
models copied to clipboard

在mq2007数据集上训练LR模型,train cost没有呈现下降。

Open lutaojian opened this issue 9 years ago • 2 comments

常使用paddle实验LR模型,在mq2007数据集上做point wise模型,具体网络实现如下。训练过程中train cost没有呈现下降趋势,但test cost反馈出下降,无法确定是否已经收敛。

有两个问题求大神解答: 1)下文的网络实验是否与LR模型等价; 2)训练过程train cost不下降是否正常。 d9e0c3f8e0caf8a1db6cd77511e6d994

def sigmoid(input_dim): # data layer data = paddle.layer.data("data", paddle.data_type.dense_vector(input_dim))

# sigmoid
output = paddle.layer.fc(
    input=data,
    size=1,
    act=paddle.activation.Sigmoid(),
    param_attr=paddle.attr.Param(initial_std=0.01, name="output"))

return output

def lr(input_dim): # label layer label = paddle.layer.data("label", paddle.data_type.dense_vector(1))

# output layer
output = sigmoid(input_dim)

# cost layer
cost = paddle.layer.multi_binary_label_cross_entropy_cost(input=output, label=label)

return cost

def train_lr(num_passes): fill_default_train = functools.partial(paddle.dataset.mq2007.train, format="pointwise") fill_default_test = functools.partial(paddle.dataset.mq2007.test, format="pointwise") train_reader = paddle.batch(paddle.reader.shuffle(fill_default_train, buf_size=100), batch_size=100) test_reader = paddle.batch(fill_default_test, batch_size=100)

# mq2007 feature_dim = 46, dense format
feature_dim = 46
cost = lr(feature_dim)
parameters = paddle.parameters.create(cost)

trainer = paddle.trainer.SGD(
    cost=cost,
    parameters=parameters,
    update_equation=paddle.optimizer.Adam(learning_rate=2e-4))

# Define the input data order
feeding = {"label": 0, "data": 1}

#  Define end batch and end pass event handler
def event_handler(event):
    if isinstance(event, paddle.event.EndIteration):
        if event.batch_id % 100 == 0:
            print "Train with Pass %d Batch %d Cost %.9f" % (
                event.pass_id, event.batch_id, event.cost)
        else:
            sys.stdout.write(".")
            sys.stdout.flush()
    if isinstance(event, paddle.event.EndPass):
        result = trainer.test(reader=test_reader, feeding=feeding)
        print "\nTest with Pass %d Cost %.9f\n" % (event.pass_id, result.cost)
        with gzip.open("lr_params_%d.tar.gz" % (event.pass_id), "w") as f:
            parameters.to_tar(f)

trainer.train(
    reader=train_reader,
    event_handler=event_handler,
    feeding=feeding,
    num_passes=num_passes)

lutaojian avatar Jul 31 '17 09:07 lutaojian

@lutaojian 感谢反馈!

1)下文的网络实验是否与LR模型等价;

上文中的实现使用的是SGD单层dnn/感知机算法,和LR算法并不相同。

2)训练过程train cost不下降是否正常。

不正常。train cost不下降,尝试调节学习率,采用不下降就*10,逐步找到合适下降位置

dzhwinter avatar Jul 31 '17 16:07 dzhwinter

您好,此issue在近一个月内暂无更新,我们将于今天内关闭。若在关闭后您仍需跟进提问,可重新开启此问题,我们将在24小时内回复您。因关闭带来的不便我们深表歉意,请您谅解~感谢您对PaddlePaddle的支持! Hello, this issue has not been updated in the past month. We will close it today for the sake of other user‘s experience. If you still need to follow up on this question after closing, please feel free to reopen it. In that case, we will get back to you within 24 hours. We apologize for the inconvenience caused by the closure and thank you so much for your support of PaddlePaddle Group!

shanyi15 avatar Aug 15 '18 09:08 shanyi15