Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Laurence001
d2l-zh
提交
790ed226
D
d2l-zh
项目概览
Laurence001
/
d2l-zh
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,体验更适合开发者的 AI 搜索 >>
提交
790ed226
编写于
12月 07, 2021
作者:
A
Aston Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bert
上级
e8473558
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
5 addition
and
5 deletion
+5
-5
chapter_natural-language-processing-pretraining/bert-dataset.md
...r_natural-language-processing-pretraining/bert-dataset.md
+1
-1
chapter_natural-language-processing-pretraining/bert-pretraining.md
...tural-language-processing-pretraining/bert-pretraining.md
+2
-2
d2l/mxnet.py
d2l/mxnet.py
+1
-1
d2l/torch.py
d2l/torch.py
+1
-1
未找到文件。
chapter_natural-language-processing-pretraining/bert-dataset.md
浏览文件 @
790ed226
...
...
@@ -110,7 +110,7 @@ def _replace_mlm_tokens(tokens, candidate_pred_positions, num_mlm_preds,
masked_token = tokens[mlm_pred_position]
# 10%的时间:用随机词替换该词
else:
masked_token = random.
randint(0, len(vocab) - 1
)
masked_token = random.
choice(vocab.idx_to_token
)
mlm_input_tokens[mlm_pred_position] = masked_token
pred_positions_and_labels.append(
(mlm_pred_position, tokens[mlm_pred_position]))
...
...
chapter_natural-language-processing-pretraining/bert-pretraining.md
浏览文件 @
790ed226
...
...
@@ -108,7 +108,7 @@ def _get_batch_loss_bert(net, loss, vocab_size, tokens_X,
```
{.python .input}
def train_bert(train_iter, net, loss, vocab_size, devices, num_steps):
trainer = gluon.Trainer(net.collect_params(), 'adam',
{'learning_rate':
1e-3
})
{'learning_rate':
0.01
})
step, timer = 0, d2l.Timer()
animator = d2l.Animator(xlabel='step', ylabel='loss',
xlim=[1, num_steps], legend=['mlm', 'nsp'])
...
...
@@ -151,7 +151,7 @@ def train_bert(train_iter, net, loss, vocab_size, devices, num_steps):
#@tab pytorch
def train_bert(train_iter, net, loss, vocab_size, devices, num_steps):
net = nn.DataParallel(net, device_ids=devices).to(devices[0])
trainer = torch.optim.Adam(net.parameters(), lr=
1e-3
)
trainer = torch.optim.Adam(net.parameters(), lr=
0.01
)
step, timer = 0, d2l.Timer()
animator = d2l.Animator(xlabel='step', ylabel='loss',
xlim=[1, num_steps], legend=['mlm', 'nsp'])
...
...
d2l/mxnet.py
浏览文件 @
790ed226
...
...
@@ -1729,7 +1729,7 @@ def _replace_mlm_tokens(tokens, candidate_pred_positions, num_mlm_preds,
masked_token
=
tokens
[
mlm_pred_position
]
# 10%的时间:用随机词替换该词
else
:
masked_token
=
random
.
randint
(
0
,
len
(
vocab
)
-
1
)
masked_token
=
random
.
choice
(
vocab
.
idx_to_token
)
mlm_input_tokens
[
mlm_pred_position
]
=
masked_token
pred_positions_and_labels
.
append
(
(
mlm_pred_position
,
tokens
[
mlm_pred_position
]))
...
...
d2l/torch.py
浏览文件 @
790ed226
...
...
@@ -1828,7 +1828,7 @@ def _replace_mlm_tokens(tokens, candidate_pred_positions, num_mlm_preds,
masked_token
=
tokens
[
mlm_pred_position
]
# 10%的时间:用随机词替换该词
else
:
masked_token
=
random
.
randint
(
0
,
len
(
vocab
)
-
1
)
masked_token
=
random
.
choice
(
vocab
.
idx_to_token
)
mlm_input_tokens
[
mlm_pred_position
]
=
masked_token
pred_positions_and_labels
.
append
(
(
mlm_pred_position
,
tokens
[
mlm_pred_position
]))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录