Skip to content

Commit a87fed9

Browse files
📝 更新Transformer文档,修正词表构建部分的注释
- 在词表构建的代码中增加了对“我”字的独热编码示例注释,提升了代码的可读性和理解性。 - 确保文档内容更加清晰,便于用户理解Encoder-Decoder结构的实现细节。
1 parent e5a6efe commit a87fed9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

docs/docs/机器学习/Transformer/Encoder-Decoder结构.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ title: 🚧Encoder-Decoder结构
3232
| \<PAD\> | 0.00 | 0.00 | 0.00 | 0.00 |
3333
| \<UNK\> | 0.12 | -0.51 | 0.32 | 0.89 |
3434
|| 0.87 | 0.42 | -0.26 | 0.35 |
35-
|| 0.65 | 0.71 | 0.38 | -0.15 |
3635
| 机器 | 0.32 | 0.52 | 0.75 | 0.22 |
3736
| 学习 | 0.45 | 0.68 | 0.21 | 0.37 |
37+
|| 0.65 | 0.71 | 0.38 | -0.15 |
38+
3839

3940
当输入一个句子"我爱学习机器学习"时,会被分词为["我", "爱", "学习", "机器", "学习"],然后每个词在嵌入矩阵中查找对应的向量,得到一系列向量表示:
4041

@@ -77,7 +78,9 @@ embedding_matrix = np.array([
7778
def word_to_onehot(word, vocab_size):
7879
onehot = np.zeros(vocab_size)
7980
if word in vocab:
80-
onehot[vocab[word]] = 1 # 对应下标位置的值为1,其他为0.
81+
onehot[vocab[word]] = 1
82+
# 以 “我”这个字为例,vocab[“我”] 为2,对应下标位置的值为1,其他为0.
83+
# onehot[2] = 1 即[0,0,1,0,0,.....,0]
8184
else:
8285
onehot[vocab["<UNK>"]] = 1 # 即未知为1.其他为0 [0,1,0,0,0,.....,0]
8386
return onehot # 形状为 :1,5000

0 commit comments

Comments
 (0)