現今 NMT 訓練皆使用 backpropogation
及 gradient-based optimizers
(e.g., Adam) 搭配 cross-entropy loss
架構如 transformer
, ConvS2S
, RNN
搭配 LSTM
, GRU
來防止一些訓練問題,例如 vanishing gradients
但有實驗證明,這些 optimizer 仍然不能充分引出 NMT system 的潜力,經常會卡在 suboptima (local optima)
- 實驗中一樣架構、訓練資料、參數的 NMT model,結果卻差異到 1 BLEU 之多
Neural machine translation of rare words with subword units
- 各種實驗都發現將多個模型進行 ensembling 後效果變很好,這可能代表只用單個模型獲得成效是有困難的
所以 training 還是一個熱門且多樣的主題! 這個篇章主要針對 training 相關的方法做介紹
首先了解一下什麼是 cross-entropy
NMT training 的 loss function
通常都是使用 cross-entropy loss
,在給定 (x, y) 訓練句子,要求出最佳化的 model parameters 可以表達成以下式子:
在實作中,會將多個 training pairs 包成 batches,然後求出每個 batch 的 loss 平均
我們可以用很多方式來表達 loss function
,這些方式做法雖然不同,但意思相同:
- Maximizing the likelihood of the training data.
- Minimizing an estimate of the cross-entropy to the real
sequence-level
distribution - Minimizing an estimate of the cross-entropy to the real
token-level
distribution - Minimizing the cross-entropy to the
Dirac distribution
In particular, we emphasize the equivalence between the sequence-level and the token-level estimation since cross-entropy loss is often characterized as token-level objective in the literature whereas the term sequence-level training somewhat misleadingly usually refers to risk-based training under BLEU
首先了解一下什麼是 residual training
及 ResNet
越深的網路被證實比傳統的淺層網路 (shallow neural network) 要好,但深層的網路容易出現 overfitting
, vanishing gradient
甚至是 degradation
的問題,解決辦法通常為:
- Regularization
- Dropout
- Residual connections
- Batch Normalization
- Layer Normalization
Batch normalization
是用來解決 vanishing gradient
的主要方法之一,他的進階版是 layer normalization
,廣泛用於 deep NLP models 例如 transformer
要了解 batch normalization 先了解 mini-batch gradient descent
再來就是 batch normalization:
- Optimization:優化深度學習模型的技巧(下)- Batch Normalization
- 什么是 Batch Normalization 批标准化 (深度学习 deep learning)
- Batch Normalization (“batch norm”) explained
最後是 layer normalization:
近期的 NMT 皆有大量參數 (over-parameterized) 的趨勢來幫助訓練,例如一個 subword-level Transformer
就可以有 200-300 million 的參數,過多的參數可能造成 over-fitting
最簡單解決 over-fitting
的方法就是 regularizers
,常見的有 L1
和 L2 regularization
,訂一些懲罰讓 outliers 的權重變為 0 並限制他們的重要性
而 NMT 也有三大 regularization 的技巧,分別是 early stopping
, dropout
和 label smoothing
Early stopping
在 validation 變差時就結束訓練,避免繼續訓練造成 overfittingDropout
讓一些 neurons 機率性停機,讓整個網路的 weights 都有較好的訓練成效
而 label smoothing 則是從 label 下手,對 one-hot encoding
的 label 進行 "軟化" 的動作,讓 one-hot encoding
變得較為平滑,可以減緩 over-fitting
的問題,詳細的作法參考:
其他用來 "smooth" output distribution 的方法還有:
- Explicit entropy penalization
- Knowledge distillation (13. model-size)
- Subword regularization
- SwitchOut
- Noisy back-translation
隨著 GPU 能力的提升,容量提升與平行化讓 large batch training
的效能線性的提升,而 large batches
往往比 small batches
能夠有更好的 gradient estimation
在 Don’t decay the learning rate, increase the batch size
就提到增加 batch size
能取得和 learning rate decay
類似的功效,想知道更多 large batch training
的討論請參考: An empirical model of large-batch training
在 GPU 效能還沒有很強的時候,無法將 large batch data
裝入 GPU memory,所以在 Multi-representation ensembles and delayed SGD updates improve syntax-based NMT
提出了 delayed SGD
能夠解決 batch size
和 GPU 的問題
MLE training 有一些問題:
- NMT training 跟 decoding 之間有
exposure bias
- 解決方法可以在訓練初期使用真實的 label,然後漸進式換成產生出來的 target tokens
Training loss function
和evalution metric
的不匹配- 在訓練時用的是 word-level cross-entropy
- 在測試時用的是 sentence- 或 document-level 的 BLEU
- 什麼是 exposure bias? (需要先有 teacher forcing 和 autoregressive 的知識)
- 什麼是 teacher forcing?
- 什麼是 autoregressive?
- 什麼是 non-autoregressive?
這些問題可透過 reinforcement learning
改善,以下簡單介紹 reinforcement learning
:
Agent
會透過選擇action
來和environment
互動- 其中是透過
policy
選擇action
- 目標是學習到一個最好的
policy
來獲得最多的reward
用 NMT 的視角來看 reinforcement learning
的話:
agent
=NMT model
environment
= source sentence+ translation history
action
= choose next wordpolicy
=
用 reinforcement learning
訓練的 NMT 有一個好處,就是 reward 不需要滿足可微分,也就是能使用 BLEU
或 GLEU
等 metrics,但這會讓 training 非常昂貴,所以通常還是使用 cross-entropy loss
雖然 reinforcement learning
在其他領域取得巨大成就,但目前還是無法在 MT 方法突破一些 baseline (e.g., SOTA NMT architecture, back-translation)
Google’s neural machine translation system: Bridging the gap between human and machine translation
就指出他們採用 BLEU
做為 reward 的 reinforcement learning
無法取得好的成果
我們都知道 NMT 就是在給予 source sentence x
和 target sentence y
然後訓練模型學會 的分布,但這只考慮到了單個方向 (source to target)
根據 chain rule 可以得到:
通常上面的 和
在 trained independently 情況下是不成立的,而 dual Supervised Learning 會利用
dual supervised learning loss
來讓兩者有所關聯:
另一種方法是使用 agreement-based approach: Agreement-based joint training for bidirectional attention-based neural machine translation
Generative adversarial networks (GANs) 在電腦視覺非常熱門,先了解一下什麼是 GANs
- Generator 會使用一堆 noise 來創造跟 real data 相似的東西
- Discriminator 會像一般的 CNN 模型來分類是 generator 創造的東西或是 real data 內的東西
- Discriminator 會將所學的東西告訴 generator
- Generator 的 loss 來自 discriminator,而 discriminator 的 loss 就是一般分類的 loss
- Generator 訓練時會凍結 discriminator,而 discriminator 訓練時會凍結 generator
以上最常見的做法是在 G, D 都使用 CNN 的 deep convolutional generative adversarial networks
(DCGAN)
但這個做法中 generator 所產生的東西都是隨機的,我們可以給 G, D 都加入 condition 來指導他產生出更有意義的東西,例如一個依賴文字敘述來產生圖片的 CGAN 模型,可以給他沒看過的文字並生成圖片
在電腦視覺任務中,因為可以對生成圖片的梯度進行 back-propogation 因此能同時訓練 G, D,但在 NLP 卻不行,因為文字通常為一堆離散符號,所以大多只能使用 reinforcement learning
來生成文字的樣本或直接對 generator 的 hidden activations
做處理
目前 adversarial training
用於 NLP 的做法還非常少!