Quantifying the Contextualization of Word Representations with Semantic Class Probing (2020)

Abstract: Pretrained language models achieve state-of-the-art results on many NLP tasks, but there are still many open questions about how and why they work so well. We investigate the contextualization of words in BERT. We quantify the amount of contextualization, i.e., how well words are interpreted in context, by studying the extent to which semantic classes of a word can be inferred from its contextualized embedding. Quantifying contextualization helps in understanding and utilizing pretrained language models. We show that the top layer representations support highly accurate inference of semantic classes; that the strongest contextualization effects occur in the lower layers; that local context is mostly sufficient for contextualizing words; and that top layer representations are more task-specific after finetuning while lower layer representations are more transferable. Finetuning uncovers task-related features, but pretrained knowledge about contextualization is still well preserved.

## introduction pretrained language models like elmo @xcite , bert @xcite , and xl-net @xcite are top performers in nlp because they learn contextualized representations, i.e., representations that reflect the interpretation of a word in context as opposed to its general meaning, which is less helpful in solving nlp tasks. as stated, pretrained language models contextualize words, is clear qualitatively; there has been little work on investigating contextualization, i.e., to which extent a word can be interpreted in context, quantitatively. we use bert @xcite as our pretrained language model and quantify contextualization by investigating how well bert infers semantic classes (s-classes) of a word in context, e.g., the s-class organization for "apple" in "apple stock rises" vs. the s-class food in "apple juice is healthy". we use s-class inference as a proxy for contextualization since accurate s-class inference reflects a successful contextualization of a word: an effective interpretation of the word in context. we adopt the methodology of probing @xcite @xcite @xcite @xcite : diagnostic classifiers are applied to pretrained language model embeddings to determine whether they encode desired syntactic or semantic features. by probing for s-classes we quantify directly where and how contextualization happens in bert. e.g., we find that the strongest contextual interpretation effects occur in the lower layers and that the top two layers contribute little to contextualization. we also investigate how the amount of context available affects contextualization. in addition, since pretrained language models in practice need to be finetuned on downstream tasks @xcite , we further investigate the interactions between finetuning and contextualization. we show that the pretrained knowledge about contextualization is well preserved in finetuned models. we make the following contributions: (i) we investigate how accurately bert interprets words in context. we find that bert's performance is high (almost 85% f 1 ), but that there is still room for improvement. (ii) we quantify how much each additional layer in bert contributes to contextualization. we find that the strongest contextual interpretation effects occur in the lower layers. the top two layers seem to be optimized only for the pretraining objective of predicting masked words @xcite and only add small increments to contextualization. (iii) we investigate the amount of context bert needs to exploit for interpreting a glove bert suits suits lawsuit suited filed lawsuit lawsuits ##suit sued lawsuits complaint slacks jacket 47th ## motivation and methodology the key benefit of pretrained language models @xcite @xcite ) is that they produce contextualized embeddings that are useful in nlp. the top layer contextualized word representations from pretrained language models are widely utilized; however, the fact that pretrained language models implement a process of contextualizationstarting with a completely uncontextualized layer of wordpieces at the bottom -is not well studied. thus, there is no difference in this respect between bert's wordpiece embeddings and uncontextualized word embeddings like glove @xcite . pretrained language models start out with an uncontextualized representation at the lowest layer, then gradually contextualize it. this is the process we analyze in this paper. for investigating the contextualization process, one possibility is to use word senses and to tap resources like the wordnet (wn) @xcite based word sense disambiguation benchmarks of the senseval series @xcite words comb's contexts train 35,399 62,184 2,178,895 dev 8,850 15,437 542,938 test 44,250 77,706 2,722,893 ## conclusion we presented a quantitative study of the contextualization of words in bert by investigating bert's semantic class inference capabilities. we focused on two key factors for successful contextualization by bert: layer index and context size. by comparing pretrained and finetuned models, we showed that word-level tasks like part-of-speech tagging bring more noticeable changes than sentence-level tasks like paraphrase classification; and top layers of bert are more sensitive to the finetuning objective than lower layers. we also found that bert's pretrained knowledge about contextualizing words is still well retained after finetuning. we showed that exploiting the full context may be unnecessary in applications where the quadratic complexity of full-sentence attention is problematic. future work may evaluate this phenomenon on more datasets and downstream tasks.