Skip to content

Commit

Permalink
Merge pull request PaddlePaddle#1580 from jacquesqiao/improve-fpe-pro…
Browse files Browse the repository at this point in the history
…blem

add l2 regularization to reduce the probability of fpe exception
  • Loading branch information
helinwang authored Mar 8, 2017
2 parents 33e54c4 + 06690cf commit 7e98163
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions demo/seqToseq/api_train_v2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import paddle.v2 as paddle


Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down

0 comments on commit 7e98163

Please sign in to comment.