Using Paraphrases to Study Properties of Contextual Embeddings (2022)

Abstract: We use paraphrases as a unique source of data to analyze contextualized embeddings, with a particular focus on BERT. Because paraphrases naturally encode consistent word and phrase semantics, they provide a unique lens for investigating properties of embeddings. Using the Paraphrase Database’s alignments, we study words within paraphrases as well as phrase representations. We find that contextual embeddings effectively handle polysemous words, but give synonyms surprisingly different representations in many cases. We confirm previous findings that BERT is sensitive to word order, but find slightly different patterns than prior work in terms of the level of contextualization across BERT’s layers.

## introduction contextualized embedding algorithms, such as bert @xcite , have achieved impressive performance on a wide variety of tasks @xcite @xcite . one application of bert is using it as a measure of sentence similarity @xcite , based on the assumption that bert will produce similar representations for the words in two sentences with similar semantics. we propose to use paraphrases with alignments between words as a tool for studying how bert represents words and phrases. figure 1 shows an example. critically, when considering an aligned word pair, we can assume the context has a similar impact on both words because we know the phrases are semantically similar. previously, paraphrases have been used to probe whether compositionality is accurately captured by bert @xcite ), but we believe they can be used to explore many other questions. using the second version of the paraphrase database @xcite , we explore how consistent contextual representations are when controlling for the semantics of the context. first, we use the human-annotated portion of the ppdb data to confirm that bert consistently represents paraphrases. next, we use the highest-quality (but not all human-annotated) section of the ppdb to probe bert's behavior in more detail. looking at words, bert effectively handles variations in spelling, but does less well with spelling errors. bert also effectively handles words of varying levels of polysemy, but the representations for synonyms are surprisingly diverse, with a much broader distribution of similarity scores. these findings confirm results from prior work using other methods, while uncovering new insights about contextual embedding models. we also consider a range of other models' word representations, finding that they have similar patterns to bert, but with aligned words that are the same receiving even more consistent representations than from bert. bert gives less contextualized representations to paraphrased words than non-paraphrased words, with the exception of punctuation. finally, we re-evaluate work looking at patterns across bert's layers and find that when controlling for semantics, the later layers actually produce more similar representations (in contrast to previous work). these results show that paraphrases are a useful tool for studying representations. by controlling for meaning while presenting interesting surface variations, they provide a unique probe of behavior. ## background 2.1 bertology there has been a growing body of research studying the inner workings of bert and trying to quantify what it learns in various scenarios, dubbed "bertology" @xcite . of particular interest to this paper is work that analyzes bert's output embeddings. recent studies have found that embeddings created from the final layer of bert tend to cluster according to word senses @xcite , though this varies somewhat based on the position of a word in a sentence @xcite . the final bert layers also produce more contextualized word embeddings than the earlier layers @xcite , a finding we revisit using paraphrases in section 3.3. ## experiments in our experiments, we want to use the ppdb to examine bert's ability to consistently represent paraphrase semantics. 2 in order to do this, we consider both phrase-level and word-level embeddings. except where explicitly indicated otherwise, all experiments are run using the uncased base model of bert, using a maximum sequence length of 128 and a batch size of 8. we use the pretrained models provided by the transformers library. 3 there is a slight mismatch between the ppdb's tokenization and the format of the bert training data. the mismatch primarily occurs with contractions and apostrophes (e.g., bert expects "don't", while the ppdb is tokenized "do n't"). this does not substantially affect the results; less than 8% of the human-annotated paraphrase pairs contain apostrophes. when words are broken into multiple pieces by the wordpiece tokenizer, we use the average of the pieces as the word representation. ## conclusion paraphrases with word alignments are a useful tool for studying the behavior of contextual language models. in this paper, we used them to study several contextual models, with a particular focus on bert. where possible, we compared our results with prior work, finding patterns that are consistent with the literature. specifically, our results confirm that bert consistently represents paraphrases, even for cases with polysemous words, but that individual word representations are overly sensitive to position, particularly for punctuation. one exception is that we found that words in a sentence are more similar to each other in later layers of bert, in contrast to prior work that did not control for meaning using paraphrases. the analysis method we introduced opens up new opportunities, such as the comparison of aligned and unaligned, same and different words, which shows the sensitivity of these models to the specific word used. paraphrases have the potential to inform exploration of other representation methods, showing which way of using the output of language models most accurately captures se-mantics consistently. we hope our findings will inform future work on contextualized models, and the applications that rely on them.