Elamur Research

How Contextual are Contextualized Word Representations? Comparing the Geometry of BERT, ELMo, and GPT-2 Embeddings

Paper · 2019 · Kawin Ethayarajh

Summary

A word can keep its spelling while doing different work in different sentences. A conventional set of word embeddings assigns that word one vector for every use. ELMo, BERT, and GPT-2 can produce a different vector for each occurrence. The paper asks how much these vectors actually change and whether the changes are mostly a matter of choosing among familiar word senses. It compares the input and hidden layers of the pretrained systems using sentences from the SemEval Semantic Textual Similarity tasks. The authors track repeated words across sentences, compare each word in a sentence with the sentence’s average vector, and test how much of a word’s variation a single direction can capture.

An important complication is that unrelated word vectors can already point in similar directions. The authors call this concentration anisotropy and use random samples to estimate its effect in each layer. Every hidden layer they study shows anisotropy. The effect is especially strong in GPT-2’s final layer, where even randomly drawn word occurrences have nearly perfect cosine similarity, a measure of directional alignment. Once the authors account for the layer’s background similarity, occurrences of the same word grow less alike higher up in all three systems. Common words such as the and of show some of the largest changes, suggesting that variation in use matters even for words with few readily distinguishable senses.

Context changes the geometry inside a sentence in different ways. In upper layers of ELMo, words align more closely with their sentence’s average vector. In BERT, that alignment generally weakens with depth, although it stays above the random-word reference. In most GPT-2 layers, the sentence measure lies close to that reference. Strong sensitivity to context can therefore coexist with little extra directional similarity among words that occur together.

The paper’s final test finds that, after subtracting the random-sample baseline, the best single direction for a word accounts for less than 5% of the variation on average in every layer examined. This is a geometric result about what a fixed vector preserves. The authors also put those fixed vectors to a different test, asking how well they handle word-level benchmarks. Vectors extracted from early layers, especially the first hidden layer of BERT, often outperform GloVe and FastText there. A compact vocabulary can retain useful information about words even when a single entry preserves little of the way a word’s representation changes from sentence to sentence.

Deep dive: How Contextual are Contextualized Word Representations? Comparing the Geometry of BERT, ELMo, and GPT-2 Embeddings

The paper measures how context changes word vectors in BERT, ELMo, and GPT-2, and tests what remains when each word gets a single vector. · about 32 minutes to read

The problem and its context

One entry for a word, many uses in sentences

A word vector gives a system a numerical representation it can compare with others. Directional proximity can then serve as evidence of a relationship between words. The usual static vocabulary gives every occurrence of a word the same entry. This is convenient because the entry can be stored and reused. It also fixes the representation before the surrounding sentence is available. If a word has several meanings, every meaning begins with the same vector.

The paper places this convention in the tradition of learning from co-occurrence. In the account it gives, Skip-gram with negative sampling and GloVe both produce a separate vector for each word. Earlier analyses showed how their training can be understood as implicitly factoring a matrix of word-and-context statistics. The patterns that went into a vector can thus come from many uses of a word, even though the finished entry is shared by all of them. Context has a role in building the vocabulary, and that contribution is combined into a single representation for each word. This is the connection the paper draws to earlier work in distributional semantics.

Contextualized representations place that computation at the level of individual uses. The vector associated with a word is an internal output obtained when a sentence is processed. The word at a given position is one part of the input that determines the output. Other available words in the sentence can also influence it. Each hidden layer gives a distinct set of outputs, so contextuality is a property that can be measured at successive stages of the computation. The paper takes these stages as its objects of study.

The change mattered because using contextualized vectors had improved performance on tasks as different as question answering and coreference resolution. As the paper describes it, the wider practice was to pretrain on a language objective and adapt the resulting system to particular tasks. Its internal representations could therefore contain linguistic information useful beyond the task used to produce them. Those gains motivated a closer look at what information a fixed vocabulary gives up and what the contextual computation adds.

A possible explanation is that a contextual system selects a suitable sense for each occurrence. Under a simple version of that explanation, a word would have a small inventory of representations. The sentence would help the system choose an entry, and uses assigned to the same sense would tend to receive the same representation. A more flexible explanation gives context a role even among uses a reader would group under the same sense. A representation could change with the word’s local role or surroundings. Those explanations motivate a geometric question about variation alongside the familiar linguistic problem of word sense disambiguation.

Even establishing that a vector changes leaves important questions open. If a sense switches, the vector might move substantially. If the sense stays stable and the surrounding words change, the vector could also move. A measurement of direction can capture both effects. The paper therefore needs evidence that goes beyond the fact of movement. It asks how movement changes with layer depth, how occurrences of common words behave, and how much a best-fitting fixed direction can retain.

What probing had established

Earlier studies examined internal representations by training a simple predictor on top of them. The original representations could remain frozen while the predictor learned to recover a property, such as a word’s part of speech or a relation between words. A successful linear probe gave evidence that the property was accessible to a simple readout. As the paper recounts, probes for some linguistic properties performed close to the strongest systems available for those properties. That made probing an established way to study what contextual representations encode.

A probe score answers a question about a particular target. A predictor for part of speech can succeed when occurrences sharing a tag occupy many different positions, provided it can recover the tag from them. The score leaves open how widely the vectors for an individual word are scattered, how much of that scatter is associated with the sentence, and which aspects could survive in a fixed entry. That distinction is especially important when a word has the same tag in many uses. Its tag can remain easy to recover while its representation varies substantially across those uses.

Earlier geometric analysis of static embeddings gave the authors a closer precedent. The units of comparison in the present paper are angles, directions, and the spread of vectors, together with the identities and sentence positions of the words they represent. This approach can investigate changes before choosing a linguistic property to predict. The later lexical evaluation brings task scores back into the study for a more specific purpose, testing the utility of the fixed vectors obtained from the analysis.

What depth and direction of context contribute

ELMo constructs token representations from a bidirectional recurrent network. At a layer, its representation joins internal states from computations that work through the sequence in opposite directions. BERT and GPT-2 instead use attention to combine information across positions. BERT can use words on both sides of a position, while GPT-2’s computation proceeds in one direction. This affects what counts as available context for a word even when all three systems receive the same sentence. BERT and GPT-2 share the Transformer architecture.

The layer-by-layer view allows the paper to compare an input representation with the hidden representations built from it. A static input can already carry a great deal of information about word identity. The hidden layers can preserve some of that information, add information about the sentence, and change how strongly the resulting vectors align. Measuring only the final output would combine all of those developments into a single comparison. Measuring the intermediate layers makes it possible to ask where the geometry changes and whether the same pattern appears under different architectures.

Direction matters here in another sense. The paper’s principal similarity score depends on where a vector points. If many vectors point roughly the same way for reasons shared across the whole layer, even two random occurrences may look similar. A high score for two uses of a particular word could then reflect ordinary alignment in the space. The analysis needs both a way to compare the word with itself and a reference that shows what scores ordinarily look like in its layer.

The method, step by step

Collect repeated words and their layer outputs

The authors start with sentences from the SemEval Semantic Textual Similarity tasks for 2012 - 2016. The source tasks concern semantic similarity between texts. For this study, the sentences provide repeated uses of words in different contexts. The measures operate on the sentence text and the resulting vectors. A pair’s similarity judgment plays no role in the formulas. The sentence sources include the SemEval-2012 Semantic Textual Similarity pilot, SemEval-2014 Task 10, and SemEval-2015 Task 2.

The authors index the sentences by word. An entry records the sentences containing a word and the positions at which it appears. As an example, the paper compares uses of dog in a sentence about a panda dog running along a road and a sentence about a dog trying to remove bacon from its back. The spelling stays constant while the words around it change. The authors retain words appearing in at least 5 distinct contexts, so the across-context comparison has several observations for each eligible word.

The sentences go through pretrained ELMo, base cased BERT, and GPT-2, obtained through an earlier version of PyTorch-Transformers. The study uses the systems as pretrained on their respective language objectives. The contextuality measurements require neither a new language-training run nor a classifier trained on the SemEval labels. ELMo has 2 hidden layers. The BERT and GPT-2 versions examined have 12 each. The paper chooses base cased BERT for its comparability to GPT-2 in depth and vector dimensionality.

The authors also collect the input vectors and designate them layer 0. This puts the state before contextual computation on the same footing as the hidden outputs for the purpose of the measurement. ELMo’s input is particularly direct as a reference because it uses the characters of the word independently of surrounding words and position. The authors then track selected occurrences through the layers, so a comparison of depth concerns different representations of the same kind of input.

From repeated word uses to layerwise comparisons

The steps in order.

From repeated word uses to layerwise comparisonsStep 1: Collect sentences from the SemEval similarity tasks1. Collect sentences from the SemEval similarity tasksStep 2: Index repeated words and their positions2. Index repeated words and their positionsStep 3: Extract input and hidden vectors from pretrained systems3. Extract input and hidden vectors from pretrained systemsStep 4: Measure agreement across contexts and within sentences4. Measure agreement across contexts and within sentencesStep 5: Find the strongest direction for each word5. Find the strongest direction for each wordStep 6: Subtract layerwise references estimated from random occurrences6. Subtract layerwise references estimated from random occurrencesStep 7: Evaluate fixed vectors on lexical benchmarks7. Evaluate fixed vectors on lexical benchmarks

Compare a word with itself across sentences

The first measure, self-similarity, fixes the word and varies its context. Imagine putting the vector for every retained occurrence of dog in one group, using outputs from the same layer. Compare the direction of each vector with the direction of every other vector in that group, then average the comparisons. That average expresses how much of the word’s directional identity persists across the sampled uses.

The comparison uses cosine similarity. It measures the alignment of two vectors through the angle between them and is insensitive to their lengths. Vectors pointing in the same direction have a cosine similarity of 1. A lower score indicates less directional agreement. In particular, length changes alone leave this measure unchanged. The choice of cosine makes the definition of context-specificity in this part of the paper a definition about direction.

SelfSimℓ(w) = [1 / (n² − n)] ∑ⱼ ∑ₖ:ₖ≠ⱼ cos(fℓ(sⱼ, iⱼ), fℓ(sₖ, iₖ))

SelfSimℓ(w) is the raw self-similarity of word w in layer ℓ. The function fℓ(s, i) retrieves the vector at position i in sentence s at that layer. There are n distinct contexts for w. The sentence sⱼ contains the word at position iⱼ, and sₖ contains it at iₖ. The index j runs over the occurrences and the index k runs over the same set while excluding j. The symbol ∑ denotes a sum, ≠ excludes the same occurrence, and cos gives the cosine similarity. The denominator n² − n counts the ordered comparisons left after each occurrence’s comparison with itself is removed.

The exclusion matters because comparison with itself would give each vector a perfect score regardless of how much it changed across sentences. The paper instead asks for agreement between separate observations of the word. In this definition, identical outputs across contexts attain the raw maximum. The same maximum also applies to outputs that differ only in length. A word’s raw score is then interpreted alongside the background agreement in the layer, because even high agreement may be ordinary for unrelated vectors.

Compare a sentence’s words with their mean

The second measure, intra-sentence similarity, fixes the sentence and considers its different positions. It first constructs a representative vector by averaging the word outputs for that sentence. Each word is compared with this common vector. Averaging those comparisons gives an indication of how strongly the sentence’s vectors align around their own center.

s⃗ℓ = (1 / n) ∑ᵢ fℓ(s, i)

Here s⃗ℓ denotes the mean vector for sentence s at layer ℓ. The arrow marks it as a vector. In this formula n counts the word positions in the sentence. The index i runs over those positions, and fℓ(s, i) is the corresponding output. The sum adds the word vectors coordinate by coordinate. Multiplication by 1 / n turns the sum into their mean.

IntraSimℓ(s) = (1 / n) ∑ᵢ cos(s⃗ℓ, fℓ(s, i))

IntraSimℓ(s) is the raw intra-sentence similarity for s in layer ℓ. The term cos(s⃗ℓ, fℓ(s, i)) compares the direction of the mean with that of the word at position i. The sum covers all n positions, and 1 / n gives each comparison equal weight in the sentence score. Each position contributes both to the mean and to the comparison with that mean.

The two cosine measures answer different questions about the same representations. Suppose a word loses directional similarity to its other uses and at the same time gains alignment with the words around it. The pattern would be consistent with the sentence supplying a common component for its words. A word can also move away from its other uses without moving towards the sentence mean. In that case, the outputs would show sensitivity to context without the same tendency to gather around a shared direction. The authors use the association of the two measures to distinguish these patterns.

Find the strongest fixed direction for a word

The third measure is maximum explainable variance, abbreviated MEV. Here the authors gather all of a word’s occurrence vectors from one layer into a matrix. They ask how much of the matrix’s variation can be captured by a single direction chosen especially for that word. The chosen direction is the first principal component, the direction that receives the greatest share under the decomposition. The procedure gives the fixed representation the advantage of fitting the same set of occurrences it is intended to summarize.

The paper specifies the score using singular values. These are quantities from a matrix decomposition that rank the contributions of the directions it identifies. A large leading singular value relative to the rest indicates that the occurrence vectors have much of their variation along a dominant direction. If their variation is distributed across several directions, the share associated with the leading one becomes smaller.

MEVℓ(w) = σ₁² / ∑ᵢ σᵢ²

MEVℓ(w) is the raw maximum explainable variance for word w at layer ℓ. The occurrence matrix has the vectors for that word as its columns, with each column taken from its recorded sentence and position. The σᵢ are the singular values of that matrix, from the first through the m values in the decomposition used by the definition. The index i now ranges over singular values. The numerator σ₁² is the square of the leading value, and the denominator ∑ᵢ σᵢ² sums the squared values. Their quotient is the leading direction’s share under the paper’s definition.

There are two uses of this computation. As a diagnostic, the share measures how much a single direction can capture before the authors account for common structure across the layer. As an extraction method, the direction itself gives a vector for the word. That vector can be looked up without a sentence and compared with other fixed entries. Its usefulness on a lexical task is a separate experimental question from the size of the share it explains.

Estimate a background separately for each layer

Anisotropy gives the raw measurements a moving reference. Consider the paper’s illustrative case of a raw self-similarity of 0.95. If random vectors are spread evenly in direction, such a value would indicate unusually strong agreement between occurrences of the word. If randomly sampled words instead have a mean similarity of 0.99, the same word score would be below the ordinary agreement in that layer. These figures illustrate the reason to adjust the score. They describe a hypothetical comparison in the method.

For the two cosine measures, the reference is the average cosine similarity of randomly sampled word occurrences from different contexts. The paper draws uniformly. The reference for MEV applies the leading-component calculation to randomly sampled occurrence vectors, drawn without grouping them by a particular word. This estimates how much concentration the layer can display in a collection that has no deliberate common word identity.

Baseline(fℓ) = 𝔼ₓ,ᵧ ∼ U(𝒪)[cos(fℓ(x), fℓ(y))]

Baseline(fℓ) is the expected random-occurrence cosine similarity at layer ℓ. The symbol 𝒪 denotes the set of word occurrences and U(𝒪) denotes uniform sampling from that set. The variables x and y are sampled occurrences, taken from different contexts for this reference. The expression x, y ∼ U(𝒪) describes the sampling and 𝔼 denotes the expected value over those draws. In this occurrence notation, fℓ(x) retrieves the same kind of vector as the sentence-and-position notation. The cosine inside the brackets compares the two sampled vectors.

SelfSimℓ*(w) = SelfSimℓ(w) − Baseline(fℓ)

SelfSimℓ*(w) denotes the adjusted self-similarity of w at layer ℓ. The star identifies the adjusted score. The raw score is SelfSimℓ(w), and the term subtracted from it is the cosine reference for the same layer. The paper likewise subtracts the cosine reference from raw intra-sentence similarity and the random-sample component share from raw MEV. The reference is recalculated for every layer of every system under study.

The subtraction adjusts a statistic while leaving the vectors themselves in their original space. A reading near 0 means that the raw score is near its random reference. Negative values are possible when the raw score is below that reference. For MEV in particular, a negative adjusted value describes a comparison of two shares. Both raw shares remain non-negative. The adjustment lets the authors ask whether the word’s vectors concentrate more than vectors collected from the layer at large.

The general procedure describes estimates using 1K uniformly sampled word representations for the raw measurements and their references. The sentence-level analysis separately specifies 500 sentences drawn uniformly at random. The sampling units matter. The across-context question is about repeated words, the sentence question is about a local group of positions, and the random reference deliberately ignores such grouping. Keeping those roles distinct is central to reading the figures.

Experiments and results

Random vectors already agree in direction

The SemEval sentences provide the common input for the geometric comparisons. The authors compare successive layers within a system, including its input, and compare patterns across systems with different ways of incorporating context. Every raw cosine statistic is interpreted against the random-occurrence cosine for the same space. For the variance statistic, the corresponding reference comes from the principal component of a random collection of vectors. These references are measurements of the layers as much as they are corrections to other scores.

A directionally uniform space would have an expected random-pair cosine similarity of 0. The authors find directional concentration in all the hidden layers under study. Among the input layers, ELMo’s is the reported exception to that pattern. Its character-based input uses neither the surrounding sentence nor position. The paper also recalls prior evidence of anisotropy in static Skip-gram embeddings, so contextual computation is only one possible setting in which common directions can arise.

GPT-2 provides the strongest example of why a baseline is necessary. Its average random-occurrence cosine is roughly 0.6 in layers 2 through 8. The paper describes a steep rise from layers 8 through 12, culminating in a final layer where the mean similarity of randomly drawn occurrences is almost perfect. The chart compares the reported middle-layer level with the theoretical reference for a uniform space. The latter is a reference point, and lower values on this measure indicate less shared directional alignment.

Random-occurrence cosine in SemEval sentences, GPT-2 and an isotropic reference

Random word vectors in GPT-2’s middle layers align well above the uniform-direction reference.

Random-occurrence cosine in SemEval sentences, GPT-2 and an isotropic referenceIsotropic reference (this paper): 0Isotropic reference (this paper)0GPT-2 layers 2 through 8, approximate: 0.6GPT-2 layers 2 through 8, approximate0.6
The numbers
System or settingmean cosine similarity
Isotropic reference (this paper)0
GPT-2 layers 2 through 8, approximate0.6

Across the systems, upper layers generally show stronger anisotropy than lower layers. The pattern has exceptions within a stack. BERT’s penultimate layer is more anisotropic than its final layer, for instance. The comparison supports a tendency for contextualized hidden states to have more concentrated directions than the corresponding inputs. The authors suggest that the concentration may accompany the way these systems contextualize words. The experiment observes the relationship across layers of existing systems and leaves its mechanism open.

Word identity contributes less directional similarity higher up

The adjusted self-similarity curves address what happens when the word is held constant across sentences. In ELMo, BERT, and GPT-2, the average adjusted score decreases as the analysis moves towards higher layers. Therefore, the added directional resemblance associated with being the same word gets smaller. This makes sense of an otherwise puzzling combination. GPT-2’s last layer can have very high raw directional agreement throughout the space while yielding little extra agreement for occurrences of the same word.

ELMo’s input provides a concrete reference point for interpreting the curves. Its reported self-similarity is 1.0, consistent with the same character-based representation being returned for the same word in every context. The authors treat the other end of the adjusted comparison as strong contextual specificity when a word’s uses are about as similar as random occurrences. By this reading, GPT-2 shows the most context-specific representations of the three, with the effect strongest in its last layer. The statement is about the score relative to random draws from that layer.

The authors also look beyond layer averages to the words with especially low scores. Stopwords, common words that occur in a wide range of sentences, are prominent among them. The ELMo list includes and and of, along with the, to, and the possessive ’s. These examples help explain why variation in the representation is broader than the familiar case of a spelling with several dictionary meanings. A frequently used grammatical word can occupy different surroundings and contribute to a variety of constructions. The vectors are sensitive to that variety under the paper’s measure.

This finding is evidence against a simple sense-lookup account. A small set of stable entries indexed only by recognizable word senses would give a less immediate explanation for the degree of variation seen in these words. The data favor an account in which individual uses shape the vector. Self-similarity is an average, though, so it gives no direct picture of the possible groups within a word’s occurrences. That is a separate question from whether the average stays high.

The sentence has a different geometric effect in each system

For the intra-sentence comparison, the authors draw 500 sentences uniformly at random. They compute the mean vector within each sentence at a given layer, compare the word vectors with that mean, and adjust the sentence score using the random-word cosine reference. A positive adjusted value means the word-to-mean comparisons are higher on average than the random-pair reference. The measure is useful here because it can move independently of self-similarity.

In ELMo, the word-to-mean score rises in the upper layers while across-context self-similarity falls. One way to understand the joint result is to think of different sentences contributing different common directions. Moving from one sentence to another can move a word away from its earlier representation. At the same time, the words within each individual sentence can be better aligned with that sentence’s mean. The paper relates this behavior to the intuition behind distributional approaches, extending the role of shared surroundings to words that appear together in an individual sentence.

In BERT, the adjusted intra-sentence measure generally falls as the layers get higher. Layer 12 is an exception to the downward pattern the authors point out. All layers still show more within-sentence alignment than the random reference on this measure. The two observations can hold together. The early layers establish a positive level of alignment, and many of the later layers reduce the extent of it. Meanwhile, the across-context comparisons indicate that a word’s representation is becoming more specific to its occurrence.

GPT-2’s average word-to-mean score is about as high as the random cosine baseline in most layers. The resulting adjusted score is close to 0 there. Its highest intra-sentence score occurs in the input layer, before the hidden layers add contextual processing. The paper reports adjusted averages above 0.20 for all but one layer of ELMo and BERT, underscoring how different the GPT-2 pattern is under this statistic. GPT-2 supplies the clearest case in which strong across-context change goes together with little additional alignment around the sentence mean.

The GPT-2 comparison is especially informative alongside its word and layer results. If contextuality were judged solely by how close the words in a sentence are to their mean, its hidden states would seem to show little contextual effect. Across uses of the same word, they show a strong effect. The discrepancy identifies two distinct geometric consequences that the word contextual can cover. A context can alter the vector for a particular position without making all positions in that sentence share a stronger direction.

A single direction preserves little additional occurrence variation

For each word and layer, the authors identify the most informative fixed direction under MEV. They compare its explained share with the share for a random collection of word representations and average the adjusted scores across sampled words. In every layer examined, the average adjusted share is less than 5%. This is the paper’s main numerical result about the loss involved in representing a word by one direction. It concerns the excess above the baseline and the average over words in a layer.

The raw values give some sense of how important the correction is. The paper reports average raw MEV below 5% for ELMo and BERT, and around 30% for GPT-2 in layers 2 to 11. The larger GPT-2 value comes from a space where a random collection can also concentrate strongly along a leading direction. The authors also observe that many words have raw MEV below their layer’s random reference. For those words, fitting a component to repeated occurrences captures a smaller fraction than fitting one to the random collection.

A fixed vector can capture some common structure that remains useful whenever the word is encountered. The MEV result describes the limits of using that direction to stand in for the set of occurrence vectors. Theoretically, the choice made by the experiment is favorable to the fixed-vector approach because it uses the direction fitted to those occurrences. A vector learned by a separate method, such as GloVe, has no guarantee of matching it.

The extracted vectors succeed at lexical tasks

The authors next use the leading component itself as a static vocabulary entry. For each selected layer, the procedure makes a collection with one entry per word. The baseline systems are GloVe and FastText, and the evaluations use the Word Embeddings Benchmarks package. These comparisons ask about the quality of a fixed vocabulary on several word-level tasks.

The named word similarity evaluations include SimLex999, MEN, WS353, and RW. The analogy tests include Google and MSR. SemEval-2012 also tests similarity between relations, while BLESS and AP appear in the concept categorization evaluations. The SemEval-2012 relational benchmark has a different role from the Semantic Textual Similarity sentences used to elicit the hidden states. In the former, an embedding collection is evaluated. In the latter, the sentences supply contexts for collecting occurrence vectors.

The strongest extracted set overall comes from layer 1 of BERT. The paper reports that fixed vectors from BERT and ELMo often outperform GloVe and FastText across the lexical evaluations. For all three contextual systems, the extracted vectors tend to work better when taken from lower layers. The GPT-2 vectors perform noticeably worse than the corresponding ELMo and BERT vectors. According to the authors, the results for layers 3 through 10 lie between the results for layers 2 and 11, so they leave layers 3 through 10 out of the benchmark table.

The contrast between the two evaluations is purposeful. MEV gives a continuous measure of the share associated with a direction within one word’s occurrences. A lexical task instead depends on how a fixed entry relates to the entries for other words. An extracted vector can place its word usefully relative to other entries even if many aspects of its own contextual variants disappear. The benchmark result establishes the utility of those extracted entries for particular tasks. The geometry result explains why the same entries give only a limited account of the internal states from which they came.

What the ablations show

The paper’s controlled comparisons use existing layer outputs, sampled references, and alternative sources of fixed vectors. Its design includes no retraining ablation. The relevant evidence comes from changing what is compared while keeping a layer, a word, or a benchmark fixed. These comparisons clarify which conclusions follow from the choice of reference, which are associated with depth, and which hold when the representations are used in a different form.

Subtracting the baseline changes what a high score means

The strongest control for interpretation compares target-word occurrences with the random draw from their own layer. In GPT-2, raw cosine and layer anisotropy can make word representations look very similar whether the occurrences share a spelling or not. The adjusted self-similarity asks a narrower question about how much agreement survives after the random level is taken into account. The raw and adjusted views can thus support simultaneous statements about high overall similarity and strong context-specificity.

The same comparison has an especially visible effect for MEV. A component fitted to a GPT-2 word can capture a sizable share in raw terms. A component fitted to arbitrary occurrences can capture a sizable share as well. This shows that a leading direction may describe a property of the layer as a whole, even when estimated from a word’s occurrences. The adjustment gauges how much the word’s occurrence set adds to that general concentration. It leaves the original geometry intact, so the observed effect is evidence about interpretation of the metric and does not test the benefits of changing the representations.

Comparing hidden layers with layer 0 adds a second reference. ELMo’s character-based input supplies a case where identical word forms have identical outputs in different contexts. The subsequent decrease in self-similarity describes what happens as the recurrent layers transform those inputs. BERT and GPT-2 also show depth trends. Observing them within each pretrained system keeps the identity of that system fixed as the representations change, while leaving intact the many computations that occur between the measured layers.

Comparing the two similarity measures explains what moves

Low self-similarity by itself admits different geometric explanations. A word could move towards other words present in its sentence, or its vector could change in a way particular to its position. Intra-sentence similarity tests for the former pattern by using the sentence average as a common comparison point. When both statistics are read together, the paper can describe the ELMo pattern as movement that brings the sentence’s vectors into greater alignment. The BERT and GPT-2 patterns show other ways in which a word can move across contexts.

This comparison also explains why the authors are careful about a shared-context account of meaning. Two words can occur in the same sentence while contributing different things. Positive sentence alignment might reflect common properties of the context, and useful context-specific information can reside in distinctions between positions. ELMo and GPT-2 provide different examples of how those effects can appear in the geometry. The comparison has no direct semantic labels for the individual positions, so it characterizes their directional arrangement rather than the quality of their individual meanings.

The stopword analysis changes the unit of inspection from an average over words to the identities of some low-scoring words. A simple explanation based on dictionary polysemy makes common grammatical words an informative case. Seeing them among the lowest-scoring entries shows how much variation can occur where the authors see relatively few distinct senses. The comparison supports their view that covering many kinds of contexts is an important source of variation. Frequency and the diversity of those contexts are related in this setting, and the analysis observes them as they occur in the corpus.

Extraction compares the practical value of lower and higher layers

For the lexical benchmarks, the extraction recipe stays the same while the source layer changes. This makes the comparison useful for asking where a fixed vocabulary can recover information that helps on word-level tasks. The stronger performance of early layers appears in all three systems. BERT’s first hidden layer is especially successful under that common recipe. The weaker GPT-2 results show that applying the same form of reduction to a more context-specific set of outputs can yield a less useful fixed vocabulary.

Depth changes more than the amount of context-specificity, so the experiment establishes an association between these properties in the tested systems. It also narrows the practical claim. The authors test a particular representation of a word, chosen by the leading component of its occurrence vectors. Its benchmark value depends on the information that survives that extraction and the way the resulting entries relate to one another. The later-layer decline gives evidence about that reduction under the tested conditions. Many other properties of the original layers are beyond what this reduction evaluates.

The comparison with GloVe and FastText adds a broader baseline. The lookup format is shared across the benchmark entries, and the source of the vectors differs. The successful early-layer entries show that extraction can yield a competitive vocabulary without requiring contextual computation each time a stored word is used. The paper’s benchmark and geometric analyses therefore complement each other. One measures how much of the original occurrence-level geometry is retained by a leading direction. The other checks whether the directions that survive can be used productively together.

Limitations

Questions the authors leave open

The authors explicitly leave open whether the different intra-sentence patterns arise from architectural differences. ELMo uses bidirectional recurrence, and BERT and GPT-2 use attention with different access to the surrounding sequence. They are examined as pretrained systems with their own architectures and objectives. An observed difference between any pair may involve more than one of those conditions. The similarity of BERT and GPT-2 in depth and dimensionality helps make the layer comparison intelligible, while a causal claim about directionality would need a comparison designed to vary that condition independently.

They also propose testing an anisotropy penalty in the language objective. The motivation comes from earlier static-embedding work in which reducing shared directional structure improved performance on several downstream tasks. In the present experiments, the correction is made to the reported measurements. Training with a penalty would change the vectors generated by the system and poses a new empirical question about what that change would do to language performance. The high anisotropy observed here is compatible with the task gains that motivated the study.

A second direction the authors identify is extracting fixed entries to reduce the memory and runtime demands of deployment. The motivation is straightforward. A stored embedding can be retrieved independently of the sentence, whereas an occurrence vector needs the contextual computation that produces it. The evaluations demonstrate that extraction can yield competitive values on word benchmarks. The proposal about easier deployment extends that result to a possible use case. The paper gives lexical performance evidence and leaves application-level speed, memory, and performance tradeoffs for future investigation.

What the measurements leave unresolved

The data support conclusions about words recurring in the selected SemEval sentences. The requirement of at least 5 distinct contexts excludes words with sparse coverage there. A word that occurs in many different kinds of sentences has more chances to show directional variation than a word observed mainly in closely related situations. The scores therefore describe a word under the sampled distribution of uses. Another collection could represent the available contexts differently. The study’s comparison with a random sample establishes a reference for its own data and layer.

Self-similarity averages over pairs, so it can give similar readings for different distributions of occurrences. For example, a word with several tight groups of uses can have low average agreement if the groups point in different directions. A word whose uses are broadly dispersed can also have low agreement. Resolving the difference requires examining the structure within the group of vectors. The paper’s measurements support the claim that variation goes beyond what a simple fixed lexical entry captures. The existence, number, and linguistic meaning of distinct groups remain separate issues.

The principal-component result has a related limit. A collection of vectors can be poorly summarized by one direction while still being compatible with a finite set of recurring patterns. A small leading share is evidence about how much the best single direction captures. It does not identify the number of directions needed, the number of senses represented, or whether sense clusters exist. The stopword result adds a linguistic reason to doubt a simple sense inventory as a complete explanation, while a direct test of sense assignments would need data identifying how the uses should be grouped.

There is also a distinction between a share and a baseline-adjusted score. Raw MEV is a share from the singular-value formula. Adjusted MEV is the difference between the word’s share and the layer’s random reference. The statement about less than 5% is best read as a bound on that average excess in the reported comparison. In particular, the paper’s discussion of GPT-2 shows that a layer can have much larger raw shares. Its average result also leaves room for individual words to depart from the layer’s general pattern.

The interpretation of the variance measure depends on the matrix being decomposed. As displayed, the formula takes singular values from the occurrence matrix and shows no separate centering step. For a matrix of identical non-zero occurrence columns, that formula gives a single dominant direction accounting for the whole raw total. A centered matrix for those same occurrences would have no variation about its mean. This distinction is particularly relevant to ELMo’s static input and the paper’s broad statements about low raw MEV across layers. The paper does not spell out how those statements and the displayed formula should be reconciled for the static case. The background-adjusted trend in contextual layers is a more precise basis for the claim about occurrence variation.

The intra-sentence control also has a particular scope. A word in the target sentence is compared with a mean that includes that word. The random reference compares two individual word occurrences drawn from different contexts. These are different constructions, so a score above the reference measures the contrast the authors defined. A control built from means of equally sized groups of unrelated words would pose a more specific question about how much sentence membership contributes beyond the act of averaging. The relative patterns across layers and systems are the central evidence in the reported comparison.

Finally, the geometric findings do not trace downstream performance to a particular direction or to the amount of observed movement. Cosine ignores changes in length, and MEV concerns a linear description by a single direction. A task readout can depend on some aspects of the variation and disregard others. The static benchmarks provide a direct test of one use of the extracted vectors, while the geometric results offer a possible explanation for why retaining contextual vectors can help. Establishing how much of a given task gain is attributable to the measured variation would require testing that task under an intervention on its representations.

What came after

One line of later work took up the question of how to obtain usable sentence vectors from pretrained systems. The 2019 paper studies the direction of individual word vectors and uses a sentence mean as a reference for them. The sentence-embedding work makes the sentence representation itself the object of study. That change in unit is important. A geometry that registers substantial differences among word occurrences can still yield sentence vectors that are hard to compare. The later study directed expressly at this representation problem is On the Sentence Embeddings from Pre-trained Language Models.

SimCSE addresses sentence embeddings with contrastive learning. Its problem is how to learn a space for sentence comparison. This extends the concern with shared directional structure to a setting where the relative arrangement of complete sentences is itself a training concern. The earlier study supplies a reason to pay attention to the background similarity of a space. Even when a system’s internal vectors vary with context, high cosine similarity can be a property of arbitrary pairs.

Another branch connects sentence vectors to particular architectures and applications. Sentence-T5 studies scalable encoders derived from pretrained text-to-text systems. It shifts the question to making an encoder for whole sentences from a system built to operate on text sequences. SGPT takes the GPT family into sentence embeddings for semantic search. Its setting makes cross-input comparison a practical requirement. A search method needs a representation that supports useful similarity judgments among different texts, a change of purpose from measuring how strongly a word aligns with its own sentence’s mean.

There is also a direct continuation of the reduction from contextual occurrences to fixed word entries. The earlier paper uses reduction both to inspect what a single direction can retain and to build vectors for lexical tests. Later work makes that reduction an explicit approach to interpreting pretrained representations. The shared question is what becomes visible when a collection of representations tied to individual sentences is summarized at the vocabulary level. Interpreting Pretrained Contextualized Representations via Reductions to Static Embeddings

A different lexical line asks what information about word meaning is recoverable. Probing Pretrained Language Models for Lexical Semantics takes lexical semantics itself as the target of probing. This brings back the distinction that motivated the paper’s geometric approach. Recovering a lexical property and measuring the extent of change across occurrences address different aspects of a representation. An occurrence vector can carry recoverable lexical information while varying considerably with the sentence.

Work on polysemy takes up the question left open by averages over occurrences. Let’s Play Mono-Poly studies what BERT can reveal about a word’s degree of polysemy and the partitioning of its uses into senses. That is a more targeted question than whether a word has a high or low average self-similarity. Some occurrences could form meaningful groups even when a single direction describes the word poorly. Looking for partitionability makes those potential groups part of the investigation.

Finally, later geometric work studies the contribution of individual coordinates. All Bark and No Bite examines how particular dimensions can obscure representational quality. BERT Busters addresses outlier dimensions that disrupt Transformer systems. These papers pursue a more localized question than the random-pair baseline, which gives one aggregate measure of alignment for a layer. Their focus is on which dimensions matter to the geometry or operation of the system. The connection is the need to interpret similarity in light of the space that produces it, whether the comparison involves repeated words, complete sentences, or the coordinates of the vectors themselves.

Cite

Cite as Kawin Ethayarajh. 2019. How Contextual are Contextualized Word Representations? Comparing the Geometry of BERT, ELMo, and GPT-2 Embeddings. Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP).

The paper itself, not this page. BibTeX from the library's record of the work. DOI 10.18653/v1/d19-1006 · arXiv 1909.00512

@inproceedings{kawin2019how,
  title = {{How Contextual are Contextualized Word Representations? Comparing the Geometry of BERT, ELMo, and GPT-2 Embeddings}},
  author = {Kawin Ethayarajh},
  booktitle = {Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP)},
  year = {2019},
  doi = {10.18653/v1/d19-1006},
  eprint = {1909.00512},
  archivePrefix = {arXiv},
  url = {https://doi.org/10.18653/v1/d19-1006}
}

↑ back to top

This page in Markdown https://md.research.elamur.ai/free/en/papers/ethayarajh-2019-how-contextual-are-contextualized-word/

References

29 references, from the paper's own bibliography.

  1. Eneko Agirre, Carmen Banea, Claire Cardie, Daniel M Cer, Mona T Diab, Aitor Gonzalez-Agirre, Weiwei Guo, Inigo Lopez-Gazpio, Montse Maritxalar, Rada Mihalcea, et al. 2015. Semeval-2015 task 2: Semantic textual similarity, English, Spanish and pilot on interpretability. In Proceedings SemEval@ NAACL-HLT. pages 252–263. our card
  2. Eneko Agirre, Carmen Banea, Claire Cardie, Daniel M Cer, Mona T Diab, Aitor Gonzalez-Agirre, Weiwei Guo, Rada Mihalcea, German Rigau, and Janyce Wiebe. 2014. Semeval-2014 task 10: Multilingual semantic textual similarity. In Proceedings SemEval@ COLING. pages 81–91. our card
  3. Eneko Agirre, Daniel Cer, Mona Diab, Aitor Gonzalez-Agirre, and Weiwei Guo. 2013. Sem 2013 shared task: Semantic textual similarity, including a pilot on typed-similarity. In SEM 2013: The Second Joint Conference on Lexical and Computational Semantics. Association for Computational Linguistics. our card
  4. Eneko Agirre, Mona Diab, Daniel Cer, and Aitor Gonzalez-Agirre. 2012. Semeval-2012 task 6: A pilot on semantic textual similarity. In Proceedings of the First Joint Conference on Lexical and Computational Semantics-Volume 1: Proceedings of the main conference and the shared task, and Volume 2: Proceedings of the Sixth International Workshop on Semantic Evaluation. Association for Computational Linguistics, pages 385–393. our card
  5. Abdulrahman Almuhareb and Massimo Poesio. 2004. Attribute-based and value-based clustering: An evaluation. In Proceedings of the 2004 conference on empirical methods in natural language processing. OpenAlex ↗ · Scholar ↗
  6. Sanjeev Arora, Yingyu Liang, and Tengyu Ma. 2017. A simple but tough-to-beat baseline for sentence embeddings. In International Conference on Learning Representations. OpenAlex ↗ · Scholar ↗
  7. Marco Baroni and Alessandro Lenci. 2011. How we blessed distributional semantic evaluation. In Proceedings of the GEMS 2011 Workshop on GEometrical Models of Natural Language Semantics. Association for Computational Linguistics, pages 1–10. our card
  8. Elia Bruni, Nam-Khanh Tran, and Marco Baroni. 2014. Multimodal distributional semantics. Journal of Artificial Intelligence Research 49:1–47. OpenAlex ↗ · Scholar ↗
  9. Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2018. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805 . our card
  10. Lev Finkelstein, Evgeniy Gabrilovich, Yossi Matias, Ehud Rivlin, Zach Solan, Gadi Wolfman, and Eytan Ruppin. 2002. Placing search in context: The concept revisited. ACM Transactions on information systems 20(1):116–131. OpenAlex ↗ · Scholar ↗
  11. John R Firth. 1957. A synopsis of linguistic theory, 1930-1955. Studies in linguistic analysis . OpenAlex ↗ · Scholar ↗
  12. John Hewitt and Christopher D. Manning. 2019. A structural probe for finding syntax in word representations. In North American Chapter of the Association for Computational Linguistics: Human Language Technologies. Association for Computational Linguistics. our card
  13. Felix Hill, Roi Reichart, and Anna Korhonen. 2015. Simlex-999: Evaluating semantic models with (genuine) similarity estimation. Computational Linguistics 41(4):665–695. our card
  14. David A Jurgens, Peter D Turney, Saif M Mohammad, and Keith J Holyoak. 2012. Semeval-2012 task 2: Measuring degrees of relational similarity. In Proceedings of the First Joint Conference on Lexical and Computational Semantics-Volume 1: Proceedings of the main conference and the shared task, and Volume 2: Proceedings of the Sixth International Workshop on Semantic Evaluation. Association for Computational Linguistics, pages 356–364. our card
  15. Omer Levy and Yoav Goldberg. 2014a. Linguistic regularities in sparse and explicit word representations. In Proceedings of the eighteenth conference on computational natural language learning. pages 171–180. our card
  16. Omer Levy and Yoav Goldberg. 2014b. Neural word embedding as implicit matrix factorization. In Advances in Neural Information Processing Systems. pages 2177–2185. OpenAlex ↗ · Scholar ↗
  17. Nelson F. Liu, Matt Gardner, Yonatan Belinkov, Matthew E. Peters, and Noah A. Smith. 2019a. Linguistic knowledge and transferability of contextual representations. In Proceedings of the Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies. our card
  18. Yinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, and Veselin Stoyanov. 2019b. Roberta: A robustly optimized bert pretraining approach. arXiv preprint arXiv:1907.11692 . our card
  19. Thang Luong, Richard Socher, and Christopher D Manning. 2013. Better word representations with recursive neural networks for morphology. In SIGNLL Conference on Computational Natural Language Learning (CoNLL). pages 104–113. our card
  20. Tomas Mikolov, Ilya Sutskever, Kai Chen, Greg S Corrado, and Jeff Dean. 2013a. Distributed representations of words and phrases and their compositionality. In Advances in Neural Information Processing Systems. pages 3111–3119. our card
  21. Tomas Mikolov, Wen-tau Yih, and Geoffrey Zweig. 2013b. Linguistic regularities in continuous space word representations. In Proceedings of the 2013 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies. pages 746–751. our card
  22. David Mimno and Laure Thompson. 2017. The strange geometry of skip-gram with negative sampling. In Proceedings of the 2017 Conference on Empirical Methods in Natural Language Processing. pages 2873–2878. OpenAlex ↗ · Scholar ↗
  23. Jiaqi Mu, Suma Bhat, and Pramod Viswanath. 2018. All-but-the-top: Simple and effective postprocessing for word representations. In Proceedings of the 7th International Conference on Learning Representations (ICLR). OpenAlex ↗ · Scholar ↗
  24. Jeffrey Pennington, Richard Socher, and Christopher Manning. 2014. GloVe: Global vectors for word representation. In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP). pages 1532–1543. our card
  25. Matthew Peters, Mark Neumann, Mohit Iyyer, Matt Gardner, Christopher Clark, Kenton Lee, and Luke Zettlemoyer. 2018. Deep contextualized word representations. In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long Papers). pages 2227–2237. our card
  26. Alec Radford, Jeff Wu, Rewon Child, David Luan, Dario Amodei, and Ilya Sutskever. 2019. Language models are unsupervised multitask learners . OpenAlex ↗ · Scholar ↗
  27. Ian Tenney, Patrick Xia, Berlin Chen, Alex Wang, Adam Poliak, R. Thomas McCoy, Najoung Kim, Benjamin Van Durme, Samuel R. Bowman, Dipanjan Das, and Ellie Pavlick. 2019. What do you learn from context? probing for sentence structure in contextualized word representations (https://openreview.net/forum?id=SJzSgnRcKX). In International Conference on Learning Representations. https://openreview.net/forum?id=SJzSgnRcKX (https://openreview.net/forum?id=SJzSgnRcKX). our card
  28. Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, and Quoc V Le. 2019. Xlnet: Generalized autoregressive pretraining for language understanding. arXiv preprint arXiv:1906.08237 . our card
  29. Jason Yosinski, Jeff Clune, Yoshua Bengio, and Hod Lipson. 2014. How transferable are features in deep neural networks? In Advances in Neural Information Processing Systems. pages 3320–3328. our card