Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
d2l-zh
提交
1174e3bf
D
d2l-zh
项目概览
OpenDocCN
/
d2l-zh
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
d2l-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
1174e3bf
编写于
1月 10, 2018
作者:
A
Aston Zhang
提交者:
GitHub
1月 10, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #143 from astonzhang/rnn
idx md
上级
6e85f3c5
c0b25451
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
4 addition
and
33 deletion
+4
-33
chapter_recurrent-neural-networks/gru-scratch.md
chapter_recurrent-neural-networks/gru-scratch.md
+2
-32
chapter_recurrent-neural-networks/index.md
chapter_recurrent-neural-networks/index.md
+2
-1
未找到文件。
chapter_recurrent-neural-networks/gru-scratch.md
浏览文件 @
1174e3bf
...
...
@@ -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"
}
]
```
可以看到一开始学到简单的字符,然后简单的词,接着是复杂点的词,然后看上去似乎像个句子了。
## 结论
...
...
chapter_recurrent-neural-networks/index.md
浏览文件 @
1174e3bf
# 循环神经网络
```
{.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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录