上下文嵌入(Bert詞向量): 什麼時候值得用?
ACL 2018
預訓練詞向量 (上下文嵌入Bert,上下文無關嵌入Glove, 隨機)詳細分析文章
1 背景

圖1 Bert
優點 | 效果顯著 |
缺點 | 成本昂貴 (Memory,Time, Money) (GPT-3,1700億的引數量) |
困惑 | 線上環境,資源受限(記憶體 CPU GPU) bert不一定是最佳 選擇 用word2vec, glove等詞向量有時候也能取得近似效果 但什麼時候可以近似,需要實驗說明,於是作者設計了實驗 |
2 三種詞向量

圖2 三種詞向量
型別 | 說明 | 實驗 |
---|---|---|
上下文詞嵌入 | BERT XLNet | 作者實驗中選BERT 768維 |
上下文詞無關嵌入 | Glove Word2Vec FastText | 作者實驗中選Glove 300維 |
隨機嵌入 | n*d矩陣 (n是詞彙量, d是嵌入維度) | 作者實驗中選迴圈隨機嵌入 800維, 空間複雜度O(nd) => O(n) |
3 實驗和結論
任務 | 模型 |
---|---|
命名實體識別 (NER) | BiLSTM |
情感分析 (sentiment analysis) | TextCNN |
3.1 影響因素一:訓練資料規模

圖3 影響因素一:訓練資料規模 01

圖4 影響因素一:訓練資料規模 02
在許多工中,供充足的資料,GloVe這些詞向量可匹配BERT
3.2 影響因素二:語言的特性
3.2.1 Complexity of setence structure
NER: 實體佔據幾個token (George Washington)

圖5 NER中的句子複雜度
Sentiment analysis:句子依存分析中依賴標記對之間的平均距離

圖6 Sentiment analysis中的句子複雜度
3.2.2 Ambiguity in word usage
NER: 實體有幾個標籤(George Washington可以作為人名、地名、組織名)

圖7 NER中的句子複雜度
Sentiment analysis:
\begin{array}{l}
H\left( {\frac{1}{{\left| S \right|}}\sum\limits_{w \in S} {p\left( { + 1\left| w \right.} \right)} } \right) \
{\rm{where }}H\left( p \right) = - p{\log _2}\left( p \right) - \left( {1 - p} \right){\log _2}\left( {1 - p} \right) \
\end{array}

圖8 Sentiment analysis中的句子複雜度
3.2.3 Prevalence of unseen words
NER: token出現次數得倒數

圖9 NER中的句子複雜度
Sentiment analysis:
給定一個句子,句子中未在訓練集中出現token佔比

圖10 Sentiment analysis中的句子複雜度

圖11 Bert和隨機向量對比

圖12 Bert和Glove對比
文字結構複雜度高和單詞歧義性方面: BERT更好
未登入詞方面: GloVe 更好
總結
大量訓練資料和簡單語言的任務中,考慮算力和裝置等,GloVe 代表的 Non-Contextual embeddings 是個不錯的選擇
對於文字複雜度高和單詞語義歧義比較大的任務,BERT代表的 Contextual embeddings 有明顯的優勢。
未登入詞方面: GloVe 更好