提交 e5022809 编写于 作者: Y Yu Yang 提交者: GitHub

Merge pull request #274 from reyoung/feature/refine_word_vectors

Use sparse update for word vectors.
...@@ -235,7 +235,8 @@ def wordemb(inlayer): ...@@ -235,7 +235,8 @@ def wordemb(inlayer):
name="_proj", name="_proj",
initial_std=0.001, initial_std=0.001,
learning_rate=1, learning_rate=1,
l2_rate=0, )) l2_rate=0,
sparse_update=True))
return wordemb return wordemb
``` ```
...@@ -301,10 +302,10 @@ cost = paddle.layer.classification_cost(input=predictword, label=nextword) ...@@ -301,10 +302,10 @@ cost = paddle.layer.classification_cost(input=predictword, label=nextword)
```python ```python
parameters = paddle.parameters.create(cost) parameters = paddle.parameters.create(cost)
adam_optimizer = paddle.optimizer.Adam( adagrad = paddle.optimizer.AdaGrad(
learning_rate=3e-3, learning_rate=3e-3,
regularization=paddle.optimizer.L2Regularization(8e-4)) regularization=paddle.optimizer.L2Regularization(8e-4))
trainer = paddle.trainer.SGD(cost, parameters, adam_optimizer) trainer = paddle.trainer.SGD(cost, parameters, adagrad)
``` ```
Next, we will begin the training process. `paddle.dataset.imikolov.train()` and `paddle.dataset.imikolov.test()` is our training set and test set. Both of the function will return a **reader**: In PaddlePaddle, reader is a python function which returns a Python iterator which output a single data instance at a time. Next, we will begin the training process. `paddle.dataset.imikolov.train()` and `paddle.dataset.imikolov.test()` is our training set and test set. Both of the function will return a **reader**: In PaddlePaddle, reader is a python function which returns a Python iterator which output a single data instance at a time.
......
...@@ -220,7 +220,8 @@ def wordemb(inlayer): ...@@ -220,7 +220,8 @@ def wordemb(inlayer):
name="_proj", name="_proj",
initial_std=0.001, initial_std=0.001,
learning_rate=1, learning_rate=1,
l2_rate=0, )) l2_rate=0,
sparse_update=True))
return wordemb return wordemb
``` ```
...@@ -290,10 +291,10 @@ cost = paddle.layer.classification_cost(input=predictword, label=nextword) ...@@ -290,10 +291,10 @@ cost = paddle.layer.classification_cost(input=predictword, label=nextword)
```python ```python
parameters = paddle.parameters.create(cost) parameters = paddle.parameters.create(cost)
adam_optimizer = paddle.optimizer.Adam( adagrad = paddle.optimizer.AdaGrad(
learning_rate=3e-3, learning_rate=3e-3,
regularization=paddle.optimizer.L2Regularization(8e-4)) regularization=paddle.optimizer.L2Regularization(8e-4))
trainer = paddle.trainer.SGD(cost, parameters, adam_optimizer) trainer = paddle.trainer.SGD(cost, parameters, adagrad)
``` ```
下一步,我们开始训练过程。`paddle.dataset.imikolov.train()``paddle.dataset.imikolov.test()`分别做训练和测试数据集。这两个函数各自返回一个reader——PaddlePaddle中的reader是一个Python函数,每次调用的时候返回一个Python generator。 下一步,我们开始训练过程。`paddle.dataset.imikolov.train()``paddle.dataset.imikolov.test()`分别做训练和测试数据集。这两个函数各自返回一个reader——PaddlePaddle中的reader是一个Python函数,每次调用的时候返回一个Python generator。
......
...@@ -277,7 +277,8 @@ def wordemb(inlayer): ...@@ -277,7 +277,8 @@ def wordemb(inlayer):
name="_proj", name="_proj",
initial_std=0.001, initial_std=0.001,
learning_rate=1, learning_rate=1,
l2_rate=0, )) l2_rate=0,
sparse_update=True))
return wordemb return wordemb
``` ```
...@@ -343,10 +344,10 @@ cost = paddle.layer.classification_cost(input=predictword, label=nextword) ...@@ -343,10 +344,10 @@ cost = paddle.layer.classification_cost(input=predictword, label=nextword)
```python ```python
parameters = paddle.parameters.create(cost) parameters = paddle.parameters.create(cost)
adam_optimizer = paddle.optimizer.Adam( adagrad = paddle.optimizer.AdaGrad(
learning_rate=3e-3, learning_rate=3e-3,
regularization=paddle.optimizer.L2Regularization(8e-4)) regularization=paddle.optimizer.L2Regularization(8e-4))
trainer = paddle.trainer.SGD(cost, parameters, adam_optimizer) trainer = paddle.trainer.SGD(cost, parameters, adagrad)
``` ```
Next, we will begin the training process. `paddle.dataset.imikolov.train()` and `paddle.dataset.imikolov.test()` is our training set and test set. Both of the function will return a **reader**: In PaddlePaddle, reader is a python function which returns a Python iterator which output a single data instance at a time. Next, we will begin the training process. `paddle.dataset.imikolov.train()` and `paddle.dataset.imikolov.test()` is our training set and test set. Both of the function will return a **reader**: In PaddlePaddle, reader is a python function which returns a Python iterator which output a single data instance at a time.
......
...@@ -262,7 +262,8 @@ def wordemb(inlayer): ...@@ -262,7 +262,8 @@ def wordemb(inlayer):
name="_proj", name="_proj",
initial_std=0.001, initial_std=0.001,
learning_rate=1, learning_rate=1,
l2_rate=0, )) l2_rate=0,
sparse_update=True))
return wordemb return wordemb
``` ```
...@@ -332,10 +333,10 @@ cost = paddle.layer.classification_cost(input=predictword, label=nextword) ...@@ -332,10 +333,10 @@ cost = paddle.layer.classification_cost(input=predictword, label=nextword)
```python ```python
parameters = paddle.parameters.create(cost) parameters = paddle.parameters.create(cost)
adam_optimizer = paddle.optimizer.Adam( adagrad = paddle.optimizer.AdaGrad(
learning_rate=3e-3, learning_rate=3e-3,
regularization=paddle.optimizer.L2Regularization(8e-4)) regularization=paddle.optimizer.L2Regularization(8e-4))
trainer = paddle.trainer.SGD(cost, parameters, adam_optimizer) trainer = paddle.trainer.SGD(cost, parameters, adagrad)
``` ```
下一步,我们开始训练过程。`paddle.dataset.imikolov.train()`和`paddle.dataset.imikolov.test()`分别做训练和测试数据集。这两个函数各自返回一个reader——PaddlePaddle中的reader是一个Python函数,每次调用的时候返回一个Python generator。 下一步,我们开始训练过程。`paddle.dataset.imikolov.train()`和`paddle.dataset.imikolov.test()`分别做训练和测试数据集。这两个函数各自返回一个reader——PaddlePaddle中的reader是一个Python函数,每次调用的时候返回一个Python generator。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册