Masked Language Models · Part 4 / 5
Two sentences at once
Single words are not enough. Does sentence B follow sentence A? Is it a paraphrase? For that, the model reads pairs.
Filling in a blanked-out word is about one sentence. But lots of questions live between two of them: does B follow A? Is B a paraphrase of A? Does A imply B? (That last one has a name — .)
Reading a pair
So feed the model two sentences at once. It needs to know where one ends and the other begins, and which token belongs to which. does this with two cheap tricks.
- A token sits between them (and at the very end) — a literal full-stop the model can see.
- A tags every token as segment 0 (sentence A) or segment 1 (sentence B), then gets added on — exactly like the back in Book 01.
And one special token leads the whole input: . Its final vector is trained to be a summary of everything — read both sentences, squeeze the verdict into that one slot.
Does B follow A?
: half the time B really is the next sentence; half the time it’s a random one. The model reads the [CLS] vector and calls it — IsNext or NotNext.
Try it: swap in the random B. The segment tags don’t change — but the [CLS] summary flips to NotNext. The whole verdict rides on that one front-of-the-line vector.
Next: stop predicting words, start labelling them.
Sources · 4
- Devlin, J., Chang, M.-W., Lee, K., & Toutanova, K. (2019). BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. In Proceedings of NAACL-HLT 2019 (pp. 4171–4186). arXiv:1810.04805.
- Liu, Y., Ott, M., Goyal, N., Du, J., Joshi, M., Chen, D., Levy, O., Lewis, M., Zettlemoyer, L., & Stoyanov, V. (2019). RoBERTa: A Robustly Optimized BERT Pretraining Approach. arXiv:1907.11692.
- Reimers, N., & Gurevych, I. (2019). Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks. In Proceedings of EMNLP-IJCNLP 2019. arXiv:1908.10084.
- Williams, A., Nangia, N., & Bowman, S. R. (2018). A Broad-Coverage Challenge Corpus for Sentence Understanding through Inference. In Proceedings of NAACL-HLT 2018 (pp. 1112–1122). arXiv:1704.05426.