未验证 提交 1174e3bf 编写于 作者: A Aston Zhang 提交者: GitHub

Merge pull request #143 from astonzhang/rnn

idx md
......@@ -79,19 +79,9 @@ vocab_size = len(char_to_idx)
print('vocab size:', vocab_size)
```
```{.json .output n=1}
[
{
"name": "stdout",
"output_type": "stream",
"text": "vocab size: 1465\n"
}
]
```
我们使用onehot来将字符索引表示成向量。
```{.python .input n=2}
```{.python .input}
def get_inputs(data):
return [nd.one_hot(X, vocab_size) for X in data.T]
```
......@@ -100,7 +90,7 @@ def get_inputs(data):
以下部分对模型参数进行初始化。参数`hidden_dim`定义了隐含状态的长度。
```{.python .input n=3}
```{.python .input n=5}
import mxnet as mx
# 尝试使用GPU
......@@ -141,16 +131,6 @@ def get_params():
return params
```
```{.json .output n=3}
[
{
"name": "stdout",
"output_type": "stream",
"text": "Will use gpu(0)\n"
}
]
```
## 定义模型
我们将前面的模型公式翻译成代码。
......@@ -192,16 +172,6 @@ utils.train_and_predict_rnn(rnn=gru_rnn, is_random_iter=False, epochs=200,
idx_to_char=idx_to_char, char_to_idx=char_to_idx)
```
```{.json .output n=None}
[
{
"name": "stdout",
"output_type": "stream",
"text": "Epoch 20. Training perplexity 275.049316\n - \u5206\u5f00 \u6211\u4e0d\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\n - \u4e0d\u5206\u5f00 \u6211\u4e0d\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\n - \u6218\u4e89\u4e2d\u90e8\u961f \u6211\u4e0d\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\u7684\u6211\n\nEpoch 40. Training perplexity 106.707302\n - \u5206\u5f00 \u6211\u60f3\u4f60\u8fd9\u6837\u6211 \u4f60\u4e0d\u662f\u6211\u60f3\u4f60\u5f00\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u4f60 \u6211\u4e0d\u8981\n - \u4e0d\u5206\u5f00 \u6211\u60f3\u4f60\u8fd9\u6837\u6211\u7684\u53ef\u7231\u4eba \u6211\u60f3\u4f60\u4f60\u60f3\u4f60\u5f00\u7740\u6211\u8981\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u7740\u6211\u4e0d\u8981\u6211\u60f3\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u7740\u6211\u4e0d\u8981\u6211\u60f3\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u7740\u6211\u4e0d\u8981\u6211\u60f3\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u7740\u6211\u4e0d\u8981\u6211\u60f3\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u7740\u6211\u4e0d\u8981\u6211\u60f3\u4f60 \u6211\u4e0d\n - \u6218\u4e89\u4e2d\u90e8\u961f \u6211\u60f3\u4f60\u8fd9\u6837\u6211\u7684\u53ef\u7231\u5973\u4eba \u6211\u60f3\u4f60\u4f60\u60f3\u4f60\u5f00\u7740\u6211\u8981\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u7740\u6211\u4e0d\u8981\u6211\u60f3\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u7740\u6211\u4e0d\u8981\u6211\u60f3\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u7740\u6211\u4e0d\u8981\u6211\u60f3\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u7740\u6211\u4e0d\u8981\u6211\u60f3\u4f60 \u6211\u4e0d\u8981\u6211\u60f3\u4f60\u5f00\u7740\u6211\u4e0d\u8981\u6211\u60f3\u4f60 \u6211\n\n"
}
]
```
可以看到一开始学到简单的字符,然后简单的词,接着是复杂点的词,然后看上去似乎像个句子了。
## 结论
......
# 循环神经网络
```{.python .input .eval_rst}
```eval_rst
.. toctree::
:maxdepth: 2
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册