Note 5: BERT

BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding (Devlin et al., 2018)

Fig. 1 Devlin et al., (2018)

  1. BERT (Bidirectional Encoder Representations from Transformers) is designed to pretrain deep bidirectional representations from unlabeled text by jointly conditioning on both left and right context in all layers.

2. Two-steps Framework

  • Pre-training: The model is trained on unlabeled data over different pre-training tasks.
  • Fine-tuning: The initialized BERT model is fine-tuned using labeled data from the downstream tasks, while each downstream task has its own tuned model.
  • Fig. 2 Overall (Devlin et al., 2018)

3. Input/Output Representations

  • Although the down-stream tasks are different, the input representation is able to unambiguously represent both a single sentence and a pair of sentences (e.g., \langleQuestion, Answer\rangle) in one token sequence.
  • [CLS]: It is always the first token of every sequence. Especially in classification tasks, it can be used as the aggregate representation of a sequence.
  • [SEP]: It can separate pairs of sentences. Furthermore, we can add a learned segment embedding to each token indicating which sentence it belongs to.
  • For a given token, its input representation is constructed by summing the corresponding token, segment and position embeddings.
  • Fig. 3 Input representation (Devlin et al., 2018)

4. Pre-training

  • Masked LM: Mask some percentage of input tokens at random and then predict these masked tokens.
    • Mask 15% of all tokens in each sequence at random.
    • However, it induces a mismatching problem between pre-training and fine-tuning since the fine-tuning stage dose not have the [MASK] token.
    • To mitigate this problem, if the i-th token is chosen, BERT replaces it with:
      • the [MASK] token 80% of the time
      • a random token 10% of the time
      • the unchanged i-th token 10% of the time
    • Merits: As the model dose not know whether the input token has been replaced, it force the model to keep a distributional contextual representation of every input token.
  • Next sentence prediction (NSP) is a binarized task which can train a model to understand sentence relationships.
    • The training samples can be generated from any monolingual corpus.
    • Label IsNext: 50% of samples are actual sentence A followed by sentence B.
    • Label NotNext: 50% of samples are randomly selected from corpus.
    • The special symbol [CLS]'s output C is used for NSP classification, as shown in Fig. 2.
  • Pre-training data is a document-level corpus rather than a shuffled sentence-level corpus.

5. Fine-tuning BERT

  • BERT encodes a concatenated text pair with self-attention effectively includes bidirectional cross attention between two sentences.
  • Input: above mentioned sentence A and sentence B are analogous to
    • sentence pairs in paraphrasing,
    • hypothesis-premise pairs in entailment,
    • question-passage pairs in question answering,
    • a degenerate text-? pair in text classification or sequence tagging.
  • Output:
    • the token representations are fed into an output layer for token-level tasks, such as sequence tagging or question answering.
    • the [CLS] representation is fed into an output layer for classification, such as entailment or sentiment analysis.

6. BERT vs. GPT vs. ELMo

  • BERT uses a bidirectional Transformer. OpenAI GPT (Radford et al., 2018) uses a left-to-right Transformer. ELMo (Peters et al., 2018) uses the concatenation of independently trained left-to-right and right-to-left LSTMs to generate features for downstream tasks.
  • BERT and OpenAI GPT are fine-tuning approaches, while ELMo is a feature-based approach.


    Differences in pre-training model architectures (Devlin et al. 2018)

Reference

Devlin, J., Chang, M. W., Lee, K., & Toutanova, K. (2018). Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805.
Radford, A., Narasimhan, K., Salimans, T., & Sutskever, I. (2018). Improving language understanding by generative pre-training.
Peters, M. E., Neumann, M., Iyyer, M., Gardner, M., Clark, C., Lee, K., & Zettlemoyer, L. (2018). Deep contextualized word representations. arXiv preprint arXiv:1802.05365.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末陷遮,一起剝皮案震驚了整個濱河市棉姐,隨后出現(xiàn)的幾起案子桑孩,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,406評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異锹漱,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)慕嚷,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,395評論 3 398
  • 文/潘曉璐 我一進(jìn)店門哥牍,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人喝检,你說我怎么就攤上這事砂心。” “怎么了蛇耀?”我有些...
    開封第一講書人閱讀 167,815評論 0 360
  • 文/不壞的土叔 我叫張陵辩诞,是天一觀的道長。 經(jīng)常有香客問我纺涤,道長译暂,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,537評論 1 296
  • 正文 為了忘掉前任撩炊,我火速辦了婚禮外永,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘拧咳。我一直安慰自己伯顶,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,536評論 6 397
  • 文/花漫 我一把揭開白布骆膝。 她就那樣靜靜地躺著祭衩,像睡著了一般。 火紅的嫁衣襯著肌膚如雪阅签。 梳的紋絲不亂的頭發(fā)上掐暮,一...
    開封第一講書人閱讀 52,184評論 1 308
  • 那天,我揣著相機(jī)與錄音政钟,去河邊找鬼路克。 笑死,一個胖子當(dāng)著我的面吹牛养交,可吹牛的內(nèi)容都是我干的精算。 我是一名探鬼主播,決...
    沈念sama閱讀 40,776評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼碎连,長吁一口氣:“原來是場噩夢啊……” “哼灰羽!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,668評論 0 276
  • 序言:老撾萬榮一對情侶失蹤谦趣,失蹤者是張志新(化名)和其女友劉穎疲吸,沒想到半個月后座每,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體前鹅,經(jīng)...
    沈念sama閱讀 46,212評論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,299評論 3 340
  • 正文 我和宋清朗相戀三年峭梳,在試婚紗的時候發(fā)現(xiàn)自己被綠了舰绘。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,438評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡葱椭,死狀恐怖捂寿,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情孵运,我是刑警寧澤秦陋,帶...
    沈念sama閱讀 36,128評論 5 349
  • 正文 年R本政府宣布,位于F島的核電站治笨,受9級特大地震影響驳概,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜旷赖,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,807評論 3 333
  • 文/蒙蒙 一顺又、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧等孵,春花似錦稚照、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,279評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至咐熙,卻和暖如春雕憔,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背糖声。 一陣腳步聲響...
    開封第一講書人閱讀 33,395評論 1 272
  • 我被黑心中介騙來泰國打工斤彼, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人蘸泻。 一個月前我還...
    沈念sama閱讀 48,827評論 3 376
  • 正文 我出身青樓琉苇,卻偏偏與公主長得像,于是被迫代替她去往敵國和親悦施。 傳聞我的和親對象是個殘疾皇子并扇,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,446評論 2 359

推薦閱讀更多精彩內(nèi)容