未验证 提交 5ecfe40d 编写于 作者: D dzhwinter 提交者: GitHub

Merge pull request #583 from JiabinYang/book04_refine

Refine the presentation format for '04.word2vect'
...@@ -204,6 +204,7 @@ from functools import partial ...@@ -204,6 +204,7 @@ from functools import partial
import math import math
import os import os
import sys import sys
from __future__ import print_function
``` ```
然后,定义参数: 然后,定义参数:
...@@ -311,7 +312,7 @@ def train(use_cuda, train_program, params_dirname): ...@@ -311,7 +312,7 @@ def train(use_cuda, train_program, params_dirname):
feed_order=['firstw', 'secondw', 'thirdw', 'fourthw', 'nextw']) feed_order=['firstw', 'secondw', 'thirdw', 'fourthw', 'nextw'])
avg_cost = outs[0] avg_cost = outs[0]
print "Step %d: Average Cost %f" % (event.step, avg_cost) print("Step %d: Average Cost %f" % (event.step, avg_cost))
# If average cost is lower than 5.8, we consider the model good enough to stop. # If average cost is lower than 5.8, we consider the model good enough to stop.
# Note 5.8 is a relatively high value. In order to get a better model, one should # Note 5.8 is a relatively high value. In order to get a better model, one should
...@@ -337,7 +338,7 @@ def train(use_cuda, train_program, params_dirname): ...@@ -337,7 +338,7 @@ def train(use_cuda, train_program, params_dirname):
- `trainer.train`将会开始训练。从`event_handler`返回的监控情况如下: - `trainer.train`将会开始训练。从`event_handler`返回的监控情况如下:
```python ```text
Step 0: Average Cost 7.337213 Step 0: Average Cost 7.337213
Step 10: Average Cost 6.136128 Step 10: Average Cost 6.136128
Step 20: Average Cost 5.766995 Step 20: Average Cost 5.766995
...@@ -394,8 +395,7 @@ def infer(use_cuda, inference_program, params_dirname=None): ...@@ -394,8 +395,7 @@ def infer(use_cuda, inference_program, params_dirname=None):
在经历3分钟的短暂训练后,我们得到如下的预测。我们的模型预测 `among a group of` 的下一个词是`a`。这比较符合文法规律。如果我们训练时间更长,比如几个小时,那么我们会得到的下一个预测是 `workers` 在经历3分钟的短暂训练后,我们得到如下的预测。我们的模型预测 `among a group of` 的下一个词是`a`。这比较符合文法规律。如果我们训练时间更长,比如几个小时,那么我们会得到的下一个预测是 `workers`
```text
```python
[[0.00106646 0.0007907 0.00072041 ... 0.00049024 0.00041355 0.00084464]] [[0.00106646 0.0007907 0.00072041 ... 0.00049024 0.00041355 0.00084464]]
6 6
a a
......
...@@ -222,6 +222,7 @@ from functools import partial ...@@ -222,6 +222,7 @@ from functools import partial
import math import math
import os import os
import sys import sys
from __future__ import print_function
``` ```
- Configure parameters and build word dictionary. - Configure parameters and build word dictionary.
...@@ -328,7 +329,7 @@ def train(use_cuda, train_program, params_dirname): ...@@ -328,7 +329,7 @@ def train(use_cuda, train_program, params_dirname):
# We output cost every 10 steps. # We output cost every 10 steps.
if event.step % 10 == 0: if event.step % 10 == 0:
print "Step %d: Average Cost %f" % (event.step, avg_cost) print("Step %d: Average Cost %f" % (event.step, avg_cost))
# If average cost is lower than 5.8, we consider the model good enough to stop. # If average cost is lower than 5.8, we consider the model good enough to stop.
# Note 5.8 is a relatively high value. In order to get a better model, one should # Note 5.8 is a relatively high value. In order to get a better model, one should
......
...@@ -246,6 +246,7 @@ from functools import partial ...@@ -246,6 +246,7 @@ from functools import partial
import math import math
import os import os
import sys import sys
from __future__ import print_function
``` ```
然后,定义参数: 然后,定义参数:
...@@ -353,7 +354,7 @@ def train(use_cuda, train_program, params_dirname): ...@@ -353,7 +354,7 @@ def train(use_cuda, train_program, params_dirname):
feed_order=['firstw', 'secondw', 'thirdw', 'fourthw', 'nextw']) feed_order=['firstw', 'secondw', 'thirdw', 'fourthw', 'nextw'])
avg_cost = outs[0] avg_cost = outs[0]
print "Step %d: Average Cost %f" % (event.step, avg_cost) print("Step %d: Average Cost %f" % (event.step, avg_cost))
# If average cost is lower than 5.8, we consider the model good enough to stop. # If average cost is lower than 5.8, we consider the model good enough to stop.
# Note 5.8 is a relatively high value. In order to get a better model, one should # Note 5.8 is a relatively high value. In order to get a better model, one should
...@@ -379,7 +380,7 @@ def train(use_cuda, train_program, params_dirname): ...@@ -379,7 +380,7 @@ def train(use_cuda, train_program, params_dirname):
- `trainer.train`将会开始训练`event_handler`返回的监控情况如下 - `trainer.train`将会开始训练`event_handler`返回的监控情况如下
```python ```text
Step 0: Average Cost 7.337213 Step 0: Average Cost 7.337213
Step 10: Average Cost 6.136128 Step 10: Average Cost 6.136128
Step 20: Average Cost 5.766995 Step 20: Average Cost 5.766995
...@@ -436,8 +437,7 @@ def infer(use_cuda, inference_program, params_dirname=None): ...@@ -436,8 +437,7 @@ def infer(use_cuda, inference_program, params_dirname=None):
在经历3分钟的短暂训练后我们得到如下的预测我们的模型预测 `among a group of` 的下一个词是`a`。这比较符合文法规律如果我们训练时间更长比如几个小时那么我们会得到的下一个预测是 `workers`。 在经历3分钟的短暂训练后我们得到如下的预测我们的模型预测 `among a group of` 的下一个词是`a`。这比较符合文法规律如果我们训练时间更长比如几个小时那么我们会得到的下一个预测是 `workers`。
```text
```python
[[0.00106646 0.0007907 0.00072041 ... 0.00049024 0.00041355 0.00084464]] [[0.00106646 0.0007907 0.00072041 ... 0.00049024 0.00041355 0.00084464]]
6 6
a a
......
...@@ -264,6 +264,7 @@ from functools import partial ...@@ -264,6 +264,7 @@ from functools import partial
import math import math
import os import os
import sys import sys
from __future__ import print_function
``` ```
- Configure parameters and build word dictionary. - Configure parameters and build word dictionary.
...@@ -370,7 +371,7 @@ def train(use_cuda, train_program, params_dirname): ...@@ -370,7 +371,7 @@ def train(use_cuda, train_program, params_dirname):
# We output cost every 10 steps. # We output cost every 10 steps.
if event.step % 10 == 0: if event.step % 10 == 0:
print "Step %d: Average Cost %f" % (event.step, avg_cost) print("Step %d: Average Cost %f" % (event.step, avg_cost))
# If average cost is lower than 5.8, we consider the model good enough to stop. # If average cost is lower than 5.8, we consider the model good enough to stop.
# Note 5.8 is a relatively high value. In order to get a better model, one should # Note 5.8 is a relatively high value. In order to get a better model, one should
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册