diff --git a/machine_translation/README.md b/machine_translation/README.md index b7514dafbde6d04310a2f28c1035420327c89612..620ed7eea62643047c51a30f3e192e8f28e890f0 100644 --- a/machine_translation/README.md +++ b/machine_translation/README.md @@ -220,6 +220,7 @@ cd data ```python # 加载 paddle的python包 +import sys import paddle.v2 as paddle # 配置只使用cpu,并且使用一个cpu进行训练 @@ -405,7 +406,9 @@ for param in parameters.keys(): 根据优化目标cost,网络拓扑结构和模型参数来构造出trainer用来训练,在构造时还需指定优化方法,这里使用最基本的SGD方法。 ```python - 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) @@ -414,12 +417,16 @@ for param in parameters.keys(): 2. 构造event_handler 可以通过自定义回调函数来评估训练过程中的各种状态,比如错误率等。下面的代码通过event.batch_id % 10 == 0 指定没10个batch打印一次日志,包含cost等信息。 + ```python 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() ``` 3. 启动训练: @@ -431,12 +438,15 @@ for param in parameters.keys(): num_passes=10000, feeding=feeding) ``` - 训练开始后,可以观察到event_handler输出的日志如下: - ```text - Pass 0, Batch 0, Cost 247.408008, {'classification_error_evaluator': 1.0} - Pass 0, Batch 10, Cost 212.058789, {'classification_error_evaluator': 0.8737863898277283} - ... - ``` + +训练开始后,可以观察到event_handler输出的日志如下: + +```text +Pass 0, Batch 0, Cost 148.444983, {'classification_error_evaluator': 1.0} +......... +Pass 0, Batch 10, Cost 335.896802, {'classification_error_evaluator': 0.9325153231620789} +......... +``` ## 应用模型 diff --git a/machine_translation/index.html b/machine_translation/index.html index 5c52eaf7e07a7aba612a36bcf4916c4861f076f5..2ea81796c657c677f4e2e3ba58a829ebf9fb5d36 100644 --- a/machine_translation/index.html +++ b/machine_translation/index.html @@ -262,6 +262,7 @@ cd data ```python # 加载 paddle的python包 +import sys import paddle.v2 as paddle # 配置只使用cpu,并且使用一个cpu进行训练 @@ -447,7 +448,9 @@ for param in parameters.keys(): 根据优化目标cost,网络拓扑结构和模型参数来构造出trainer用来训练,在构造时还需指定优化方法,这里使用最基本的SGD方法。 ```python - 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) @@ -456,12 +459,16 @@ for param in parameters.keys(): 2. 构造event_handler 可以通过自定义回调函数来评估训练过程中的各种状态,比如错误率等。下面的代码通过event.batch_id % 10 == 0 指定没10个batch打印一次日志,包含cost等信息。 + ```python 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() ``` 3. 启动训练: @@ -473,12 +480,15 @@ for param in parameters.keys(): num_passes=10000, feeding=feeding) ``` - 训练开始后,可以观察到event_handler输出的日志如下: - ```text - Pass 0, Batch 0, Cost 247.408008, {'classification_error_evaluator': 1.0} - Pass 0, Batch 10, Cost 212.058789, {'classification_error_evaluator': 0.8737863898277283} - ... - ``` + +训练开始后,可以观察到event_handler输出的日志如下: + +```text +Pass 0, Batch 0, Cost 148.444983, {'classification_error_evaluator': 1.0} +......... +Pass 0, Batch 10, Cost 335.896802, {'classification_error_evaluator': 0.9325153231620789} +......... +``` ## 应用模型