From 169f6512170121255d0fa0f4a4c858d2cd7e1f55 Mon Sep 17 00:00:00 2001 From: peterzhang2029 Date: Wed, 29 Nov 2017 13:06:00 +0800 Subject: [PATCH] add sum eval for to caculate ppl --- generate_sequence_by_rnn_lm/network_conf.py | 2 +- generate_sequence_by_rnn_lm/train.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/generate_sequence_by_rnn_lm/network_conf.py b/generate_sequence_by_rnn_lm/network_conf.py index f1aceb0b..f2e59a94 100644 --- a/generate_sequence_by_rnn_lm/network_conf.py +++ b/generate_sequence_by_rnn_lm/network_conf.py @@ -57,4 +57,4 @@ def rnn_lm(vocab_dim, else: cost = paddle.layer.classification_cost(input=output, label=target) - return cost, output + return cost diff --git a/generate_sequence_by_rnn_lm/train.py b/generate_sequence_by_rnn_lm/train.py index d8bffd48..19883582 100644 --- a/generate_sequence_by_rnn_lm/train.py +++ b/generate_sequence_by_rnn_lm/train.py @@ -43,9 +43,14 @@ def train(topology, # create parameters parameters = paddle.parameters.create(topology) + # create sum evaluator + sum_eval = paddle.evaluator.sum(topology) # create trainer trainer = paddle.trainer.SGD( - cost=topology, parameters=parameters, update_equation=adam_optimizer) + cost=topology, + parameters=parameters, + update_equation=adam_optimizer, + extra_layers=sum_eval) # define the event_handler callback def event_handler(event): -- GitLab