From 06690cfb015ebc11d4190d751f98971f350d8316 Mon Sep 17 00:00:00 2001 From: qiaolongfei Date: Wed, 8 Mar 2017 22:39:10 +0800 Subject: [PATCH] add l2 regularization to reduce the probability of fpe exception --- demo/seqToseq/api_train_v2.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/demo/seqToseq/api_train_v2.py b/demo/seqToseq/api_train_v2.py index 6efd254e7a4..5d138a8c4f9 100644 --- a/demo/seqToseq/api_train_v2.py +++ b/demo/seqToseq/api_train_v2.py @@ -1,3 +1,4 @@ +import sys import paddle.v2 as paddle @@ -104,7 +105,9 @@ def main(): parameters = paddle.parameters.create(cost) # define optimize method and trainer - optimizer = paddle.optimizer.Adam(learning_rate=1e-4) + optimizer = paddle.optimizer.Adam( + learning_rate=5e-5, + regularization=paddle.optimizer.L2Regularization(rate=1e-3)) trainer = paddle.trainer.SGD(cost=cost, parameters=parameters, update_equation=optimizer) @@ -125,8 +128,11 @@ def main(): def event_handler(event): if isinstance(event, paddle.event.EndIteration): if event.batch_id % 10 == 0: - print "Pass %d, Batch %d, Cost %f, %s" % ( + print "\nPass %d, Batch %d, Cost %f, %s" % ( event.pass_id, event.batch_id, event.cost, event.metrics) + else: + sys.stdout.write('.') + sys.stdout.flush() # start to train trainer.train( -- GitLab