Skip to content

Commit 06690cf

Browse files
committed
add l2 regularization to reduce the probability of fpe exception
1 parent dbe96a4 commit 06690cf

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

demo/seqToseq/api_train_v2.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import paddle.v2 as paddle
23

34

@@ -104,7 +105,9 @@ def main():
104105
parameters = paddle.parameters.create(cost)
105106

106107
# define optimize method and trainer
107-
optimizer = paddle.optimizer.Adam(learning_rate=1e-4)
108+
optimizer = paddle.optimizer.Adam(
109+
learning_rate=5e-5,
110+
regularization=paddle.optimizer.L2Regularization(rate=1e-3))
108111
trainer = paddle.trainer.SGD(cost=cost,
109112
parameters=parameters,
110113
update_equation=optimizer)
@@ -125,8 +128,11 @@ def main():
125128
def event_handler(event):
126129
if isinstance(event, paddle.event.EndIteration):
127130
if event.batch_id % 10 == 0:
128-
print "Pass %d, Batch %d, Cost %f, %s" % (
131+
print "\nPass %d, Batch %d, Cost %f, %s" % (
129132
event.pass_id, event.batch_id, event.cost, event.metrics)
133+
else:
134+
sys.stdout.write('.')
135+
sys.stdout.flush()
130136

131137
# start to train
132138
trainer.train(

0 commit comments

Comments
 (0)