Sunday, November 07, 2021

ConvS2S(四):Appendix

  ConvS2S(四):Appendix

2021/10/27

-----


-----

Outline

1. ConvS2S
2. I/O Embedding
3. Padding and Mask
4. GLU
5. Encoder
6. Decoder
7. Multi-Hop Attention
8. Details

-----

ConvS2S

Figure 1. Illustration of batching during training. The English source sentence is encoded (top) and we compute all attention values for the four German target words (center) simultaneously. Our attentions are just dot products between decoder context representations (bottom left) and encoder representations. We add the conditional inputs computed by the attention (center right) to the decoder states which then predict the target words (bottom right). The sigmoid and multiplicative boxes illustrate Gated Linear Units.

圖 1. 訓練期間批處理的圖示。 英語源句子被編碼(頂部),我們同時計算四個德語目標詞(中心)的所有注意力值。 我們的注意力只是解碼器上下文表示(左下)和編碼器表示之間的點積。 我們將注意力(右中)計算的條件輸入添加到解碼器狀態,然後預測目標詞(右下)。 sigmoid 和乘法框說明了門控線性單元。

# ConvS2S。

--



-----

I/O Embedding

one hot encoding 壓縮成 768。

768 轉成 512 或 1024 或 2048。

https://zhuanlan.zhihu.com/p/27234078

https://www.telesens.co/2019/04/21/understanding-incremental-decoding-in-fairseq/

-----



-----


Modified from # ConvS2S

Modified from # ConvS2S

Padding 的部分,由於使用一維的 Conv3,Encoder 端的 They agree,除了先加上句末的標記 </s>,另外還要補上兩個 <p>。Decoder 端的德文 Sie stimmen zu,除了句首的標記 <s>,也要補上兩個 <p>。Attention 的矩陣可以看到 <s> Sie stimmen tu 與 They agree </s> 的權重對應。


Mask 的部分,可以看到 Decoder 端跟 Encoder 端藍色部分形狀不同。Decoder 端在預測下一個字的時候,不會用到未來的訊息。

--


Modified from # ConvS2S

-----

GLU



# GLU。

說明:

句子的向量,先分別經過兩個一維卷積的運算。上半部經過 sigmoid 的運算,讓它具有 LSTM 的門的作用。然後再與另一半點乘。

-----


# ConvS2S

-----


# ConvS2S

說明:

ConvS2S 的 GLU 會加上殘差連結。

https://zhuanlan.zhihu.com/p/27464080

-----


# ConvS2S

-----

Encoder


Modified from # ConvS2S

說明:

Encoder 最後一層的輸出,作為 Decoder 每一層(共八層) attention 的參考來源。

https://reniew.github.io/44/

-----

Decoder


Modified from # ConvS2S

說明:

會用到 Attention 的權重來決定 Encoder 端每個字的份量。

https://reniew.github.io/44/

Encoder 一次讀完,Decoder 逐字輸出。每次吐出一個字。

https://ycts.github.io/weeklypapers/convSeq2seq/

-----


Modified from # ConvS2S

-----

QKV


Modified from # ConvS2S

C = QKV

last layer:encoder output 的最後一層。

每吐完四個字,hidden state 重新作為下一層的輸入。

https://deeplearning.hatenablog.com/entry/convs2s

-----


# Short Attention。

說明:

Yt = [h(t-L) ... h(t-1)]。previous L。

1 是每個值都為 1 的向量,維度為 L。

T 是轉置。

(1)計算隱藏層的輸出。

(2)計算權重。

(3)Yt 與權重得到上下文向量。

(4)上下文向量跟 ht 得到 ht*。

(5)將 ht* 轉成 yt,也就是 |v| 個字應該輸出哪一個字的機率分布。

-----


# Short Attention。

說明:

(6)ht 的維度為 2k,kt、vt 的維度皆為 k。

(7)k 分量代替 Yt。

(8)此公式不變。

(9)v 分量代替 Yt。

(10)vt 代替 ht。

-----


# Short Attention。

說明:

(11)ht 的維度為 3k,kt、vt、pt 的維度各為 k。

(12)ht*、rt、pt 的維度都是 k。

-----


Modified from # ConvS2S

-----

Multi-hop attention


# ConvS2S

說明:

八層 Attention。

一、三、六:線性。

二、八:整個來源句的資訊。

四:名詞。

五、七:建立。配合德文(文法結構)的翻譯。

--


# ConvS2S

--

byte-pair encoding (BPE)

「BPE 最早由 Philip Gage 提出,用來做數據壓縮上。它的原理是將常見連續的兩個符號以另一個符號表達。例如 ababab 中 a 後面很常接著 b 我們就用 c 表達 ab,並得到一個新的序列 ccc,c = ab 。」

https://theblackcat102.github.io/BPE/

--

「Layer 1, 3 and 6 exhibit a linear alignment. The first layer shows the clearest alignment, although it is slightly off and frequently attends to the corresponding source word of the previously generated target word. 」

第 1、3 和 6 層呈現線性排列。 第一層顯示了最清晰的對齊方式,儘管它略微偏離並且經常關注先前生成的目標詞的相應源詞。

「Layer 2 and 8 lack a clear structure and are presumably collecting information about the whole source sentence. 」

第 2 層和第 8 層缺乏清晰的結構,可能正在收集有關整個源語句的信息。

「The fourth layer shows high alignment scores on nouns such as “festival”, “way” and “work” for both the generated target nouns as well as their preceding words. Note that in German, those preceding words depend on gender and object relationship of the respective noun. 」

第四層顯示了對生成的目標名詞及其前面的詞的“節日”、“方式”和“工作”等名詞的高對齊分數。 請注意,在德語中,前面的詞取決於相應名詞的性別和賓語關係。

「Finally, the attention scores in layer 5 and 7 focus on “built”, which is reordered in the German translation and is moved from the beginning to the very end of the sentence. One interpretation for this is that as generation progresses, the model repeatedly tries to perform the re-ordering. “aufgebaut” can be generated after a noun or pronoun only, which is reflected in the higher scores at positions 2, 5, 8, 11 and 13.」

最後,第 5 層和第 7 層的注意力分數集中在“built”上,它在德語翻譯中重新排序,並從句子的開頭移到結尾。 對此的一種解釋是,隨著生成的進行,模型會反复嘗試執行重新排序。 “aufgebaut”可以僅在名詞或代詞之後生成,這反映在位置 2、5、8、11 和 13 的較高分數中。

-----


Modified from # ConvS2S。

-----


Modified from # ConvS2S。

-----


Modified from # ConvS2S。

-----

Details

https://zhuanlan.zhihu.com/p/60524073

https://norman3.github.io/papers/docs/fairseq.html

-----



Table 4. Effect of removing position embeddings from our model in terms of validation perplexity (valid PPL) and BLEU.

表 4. 從我們的模型中移除位置嵌入對驗證困惑度(有效 PPL)和 BLEU 的影響。

# ConvS2S

-----

PPL

Perplexity(困惑度)

PPL 越低表示模型越好。

https://towardsdatascience.com/perplexity-intuition-and-derivation-105dd481c8f3

https://blog.csdn.net/blmoistawinde/article/details/104966127

https://medium.com/nlp-tsupei/perplexity%E6%98%AF%E4%BB%80%E9%BA%BC-426f52897513

https://www.youtube.com/watch?v=8s56yyL-EfQ

-----

References

# ConvS2S。被引用 1772 次。

Gehring, Jonas, et al. "Convolutional sequence to sequence learning." arXiv preprint arXiv:1705.03122 (2017).

https://arxiv.org/pdf/1705.03122.pdf


# GLU

Dauphin, Yann N., et al. "Language modeling with gated convolutional networks." Proceedings of the 34th International Conference on Machine Learning-Volume 70. JMLR. org, 2017.

https://arxiv.org/pdf/1612.08083.pdf

-----

The Star Also Rises: NLP(四):ConvS2S

https://hemingwang.blogspot.com/2019/04/convs2s.html

-----

No comments: