第三遍閱讀(精讀)
精讀的過程要把每個細(xì)節(jié)都鉆研透,不留有死角。各種維度參數(shù)已經(jīng)在“理論+實戰(zhàn)(二)”中說清楚了,若之后還有疑問我再補(bǔ)上。
三、參考文章或視頻鏈接 |
---|
[1] 【超強(qiáng)動畫,一步一步深入淺出解釋Transformer原理!】 |
3.1 Attention和Self-Attention的區(qū)別?
3.1 參考文章或視頻鏈接 |
---|
[1] What’s the difference between Attention vs Self-Attention? What problems does each other solve that the other can’t? |
[2] What’s the Difference Between Self-Attention and Attention in Transformer Architecture? |
3.2 Transformer是如何進(jìn)行堆疊的?
原文提到了Encoder與Decoder是可以進(jìn)行 N × N\times N× 堆疊的,那么堆疊之后的結(jié)構(gòu)是什么?可以看到這就是堆疊之后的結(jié)構(gòu),這里的features是中間編碼,6層decoder,每一層都需要拿features作為輸入的一部分,這種設(shè)計思想也類似于ResNet。

圖1 —— 來自參考文章[1]
再看到原始的Transformer結(jié)構(gòu)圖中,對Outputs提到了一個(shifted right),這是什么意思?參考文章[4]中的動圖詮釋了這一點,shifted right是說不停的拿最新的預(yù)測詞作為Outputs的輸入,其實仔細(xì)想想,你寫文章也絕對不可能是寫下一個詞語而不依賴上一句,一定是有前文的信息作為輸入,才能讓你流暢的寫出下一個詞語的,聊天在一定程度上就是拽著話頭,話趕話。

圖2 —— 來自參考文章[4]
3.5 參考文章或視頻鏈接 |
---|
[1] Transformer’s Encoder-Decoder Let’s Understand The Model Architecture |
[2] What is purpose of stacking N=6 blocks of encoder and decoder in transformer? |
[3] Stacked encoder and decoder blocks used in Transformers |
[4] The Transformer Model - A Step by Step Breakdown of the Transformer’s Encoder-Decoder Architecture |
3.3 如何理解Positional Encoding?
“需要使用Positional Encoding的原因也很簡單,因為 Transformer 擯棄了 RNN 的結(jié)構(gòu),因此需要一個東西來標(biāo)記各個字之間的時序,換言之,也即位置關(guān)系,而這個東西,就是位置嵌入”[2],文章[2]又說,理想情況下,位置嵌入的設(shè)計應(yīng)該滿足以下條件:
- 它應(yīng)該為每個字輸出唯一的編碼
- 不同長度的句子之間,任何兩個字之間的差值應(yīng)該保持一致
- 它的值應(yīng)該是有界的
先來看到文章中的Positional Encoding公式:
P
E
(
p
o
s
,
2
i
)
=
s
i
n
(
p
o
s
1000
0
2
i
d
m
o
d
e
l
)
PE(pos, 2i)=sin(\frac{pos}{10000^\frac{2i}{d_{model}}})
PE(pos,2i)=sin(10000dmodel?2i?pos?)
P
E
(
p
o
s
,
2
i
+
1
)
=
c
o
s
(
p
o
s
1000
0
2
i
d
m
o
d
e
l
)
PE(pos, 2i+1)=cos(\frac{pos}{10000^\frac{2i}{d_{model}}})
PE(pos,2i+1)=cos(10000dmodel?2i?pos?)
- d m o d e l = 512 d_{model}=512 dmodel?=512是作者規(guī)定好的,代表編碼長度。應(yīng)該也可以修改的更長以提升性能?我不清楚,這里取何值較為合適呢?肯定有一個最優(yōu)值。
- i i i 是指維度的下標(biāo),結(jié)合式子 2 i d m o d e l \frac{2i}{d_{model}} dmodel?2i?中的分母 d m o d e l d_{model} dmodel?理解,應(yīng)該有 i ∈ [ 0 , d m o d e l ? 1 2 ] i \in [0, \frac{d_{model}-1}{2}] i∈[0,2dmodel??1?],這是因為Word Embedding的維度大小是 d m o d e l d_{model} dmodel?,所以為了Positional Embedding能與Word Embedding相加,肯定要能夠一一對應(yīng)。
p o s pos pos 為某句話中,這個Word所處的位置。
But using binary values would be a waste of space in the world of floats. 看英文原文有這么一句,
Positional Embedding 與 Word Embedding可以分開做concat拼接,但concat不一定有優(yōu)勢,初看這個東西我一定覺得作者在裝神弄鬼,看完我理解了Positional Embedding的作用。
但是對于Word Embedding與Positional Embedding二者相加后,這個位置信息是如何體現(xiàn)出來的,則不甚明了,因為這就像兩種顏色的墨水進(jìn)行混合,Word Embedding是黑墨水,Positional Embedding是紅墨水,兩種數(shù)據(jù)直接相加就像把兩種顏色的墨水混合到一起,那么要如何在相加之后的混合結(jié)果中體現(xiàn)Positional信息,則是我感到疑惑的。文章來源:http://www.zghlxwxcb.cn/news/detail-819223.html
Why do we mix two different concepts into the same multi-dimensional space? How can a model distinguish between word embeddings and positional encodings? [3] 兩件毫不相干的事情怎么能相加到一個空間中,model要如何區(qū)分他們呢?
The model can learn to use the positional information without confusing the embedding (semantic) information. It’s hard to imagine what’s happening inside the network, yet it works. model可以在不混淆word embedding的情況下學(xué)到位置信息,你很難想象網(wǎng)絡(luò)中究竟發(fā)生了,什么然而它就是工作了。然而,這是個什么解釋? 所謂ai的黑箱模型,恐怕說的就是這一點,神經(jīng)網(wǎng)絡(luò)的擬合能力太過強(qiáng)大了,以至于我們都不知道內(nèi)部究竟發(fā)生了什么。文章來源地址http://www.zghlxwxcb.cn/news/detail-819223.html
3.6 參考文章或視頻鏈接 |
---|
[1] Positional Encoding |
重點閱讀:[2] 中文版:《Transformer 中的 Positional Encoding》 英文版:Transformer Architecture: The Positional Encoding |
[3] Transformer’s Positional Encoding |
3.x 文章涉及的其它知識盲區(qū)
問題 | 總結(jié) | 參考文章 |
---|---|---|
什么是BLEU(Bilingual Evaluation Understudy,雙語評估替換分?jǐn)?shù))? | 一種機(jī)器翻譯任務(wù)的評價指標(biāo) | [1] 《BLEU詳解》- 知乎 |
到了這里,關(guān)于論文閱讀筆記AI篇 —— Transformer模型理論+實戰(zhàn) (三)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!