Skip to content

Commit

Permalink
tiny finetune on translation (d2l-ai#969)
Browse files Browse the repository at this point in the history
* Update bounding-box.md

minor change about the translation

* Update anchor.md

minor update about translation

* Update nadaraya-waston.md

Add the missing Chinese char at the very beginning. i.e. "现".

* Update bert.md

Translation finetuning.

Co-authored-by: goldmermaid <goldpiggy@berkeley.edu>
  • Loading branch information
zppet and goldmermaid committed Sep 29, 2021
1 parent 36fdb71 commit 3eb7fc9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions chapter_natural-language-processing-pretraining/bert.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ mlm_Y_hat = mlm(encoded_X, mlm_positions)
mlm_Y_hat.shape
```

利用遮蔽下的预测词元`mlm_Y`的真实值`mlm_Y_hat`,我们可以计算在BERT预训练中的遮蔽语言模型任务的交叉熵损失。
通过掩码下的预测词元`mlm_Y`的真实标签`mlm_Y_hat`,我们可以计算在BERT预训练中的遮蔽语言模型任务的交叉熵损失。

```{.python .input}
mlm_Y = np.array([[7, 8, 9], [10, 20, 30]])
Expand All @@ -277,7 +277,7 @@ mlm_l.shape

尽管遮蔽语言建模能够编码双向上下文来表示单词,但它不能显式地建模文本对之间的逻辑关系。为了帮助理解两个文本序列之间的关系,BERT在预训练中考虑了一个二元分类任务——*下一句预测*。在为预训练生成句子对时,有一半的时间它们确实是标签为“真”的连续句子;在另一半的时间里,第二个句子是从语料库中随机抽取的,标记为“假”。

下面的`NextSentencePred`类使用单隐藏层的多层感知机来预测第二个句子是否是BERT输入序列中第一个句子的下一个句子。由于Transformer编码器中的自注意,特殊词元“&lt;cls&gt;的BERT表示对输入的两个句子进行编码。因此,多层感知机分类器的输出层(`self.output`)以`X`作为输入,其中`X`是多层感知机隐藏层的输出,其输入是编码的&lt;cls&gt;”词元。
下面的`NextSentencePred`类使用单隐藏层的多层感知机来预测第二个句子是否是BERT输入序列中第一个句子的下一个句子。由于Transformer编码器中的自注意力,特殊词元“&lt;cls&gt;的BERT表示已经对输入的两个句子进行了编码。因此,多层感知机分类器的输出层(`self.output`)以`X`作为输入,其中`X`是多层感知机隐藏层的输出,而MLP隐藏层的输入是编码后的&lt;cls&gt;”词元。

```{.python .input}
#@save
Expand Down

0 comments on commit 3eb7fc9

Please sign in to comment.