Fantastic Semantics and Where to Find Them: Investigating Which Layers of Generative LLMs Reflect Lexical Semantics

Zhu Liu, Cunliang Kong, Ying Liu, Maosong Sun

Abstract

Large language models have achieved remarkable success in general language understanding tasks. However, as a family of generative methods with the objective of next token prediction, the semantic evolution with the depth of these models are not fully explored, unlike their predecessors, such as BERT-like architectures. In this paper, we specifically investigate the bottom-up evolution of lexical semantics for a popular LLM, namely Llama2, by probing its hidden states at the end of each layer using a contextualized word identification task. Our experiments show that the representations in lower layers encode lexical semantics, while the higher layers, with weaker semantic induction, are responsible for prediction. This is in contrast to models with discriminative objectives, such as mask language modeling, where the higher layers obtain better lexical semantics. The conclusion is further supported by the monotonic increase in performance via the hidden states for the last meaningless symbols, such as punctuation, in the prompting strategy.

Introduction

In the era of "BERTology," researchers established a clear hierarchy for discriminative models: surface features are encoded in lower layers, syntax in the middle, and complex semantics at the top. However, the rise of decoder-only generative models like Llama2 has challenged this paradigm. Unlike BERT, which is trained to fill in blanks (Masked Language Modeling), generative LLMs are trained for next-token prediction. This fundamental difference in objective suggests that the internal organization of meaning—lexical semantics—might follow a different trajectory.

Methodology

To investigate where Llama2 stores the meaning of words, we utilized the Contextualized Word Identification (WiC) task. In this benchmark, the model must determine if a target word (e.g., "bank") has the same sense in two different contexts. We probed the hidden states of Llama2-7B across all 32 layers using three primary input strategies:

  1. Base: Extracting the representation at the target word's position.
  2. Repeat: Repeating the sentence twice so the model processes the full context before encountering the target word again.
  3. Prompt: Using a natural language prompt to ask the model for the word's meaning directly.

We also applied anisotropy removal to ensure that the high-dimensional vectors were properly distributed for comparison, mitigating the "cone effect" often found in LLM hidden states.

The Inverted-U Trend: Llama2 vs. BERT

Our primary finding is that generative models flip the traditional semantic script. While BERT-large shows a steady increase in semantic accuracy that peaks in its final layers (layer 22), Llama2 exhibits an inverted-U trend.

Accuracy on the WiC task across layers for Llama2 compared to BERT-large, showing the inverted-U trend in generative models.

As shown in the figure above, Llama2's semantic performance peaks early—around layers 8 to 11—and then significantly declines as it approaches the output layer. This suggests that the model's "understanding" of a word is most clear in its lower-to-middle layers, whereas the final layers are preoccupied with other tasks.

Understanding vs. Prediction

Why does semantic clarity drop in the highest layers of an LLM? We hypothesize a "division of labor" within the architecture. Lower layers are responsible for induction and understanding, where the model integrates context to resolve the meaning of the current token. Higher layers, however, shift their focus toward prediction.

Conceptual comparison of semantic alignment in BERT (aligned for current word) vs. Llama2 (misaligned due to next-token prediction objective).

In this predictive phase, the hidden state is transformed into a representation optimized for guessing the next token rather than representing the current one. This creates a semantic misalignment for the target word in the top layers, explaining the performance dip observed in the WiC task.

Key Results and Discussion

  • Peak Performance: Using the repeat strategy, Llama2 achieved a peak accuracy of 68.1% at layer 8, outperforming older baselines like Elmo (57.7%).
  • Prompting Efficacy: The prompt strategy yielded the highest overall accuracy (72.7%), but this peak occurred much later (layer 21). This indicates that while the model "knows" the meaning early on, it requires additional processing layers to translate that knowledge into a format usable by its predictive head.
  • Grammatical Variance: The model is notably better at disambiguating nouns than verbs. This is likely because verbs are more dependent on subsequent context, which causal (left-to-right) models cannot see during the initial pass.

Conclusion

Our investigation reveals that generative LLMs like Llama2 do not follow the bottom-up semantic hierarchy of their discriminative predecessors. Instead, they prioritize lexical semantics in their lower layers before shifting toward next-token prediction in the upper layers. Understanding this internal "inverted-U" dynamic is crucial for future work in model steering, factual alignment, and interpreting how these giants truly "understand" language.

Summary updated

BibTeX
@inproceedings{liu2024fantastic,
  author = {Zhu Liu and Cunliang Kong and Ying Liu and Maosong Sun},
  title = {{Fantastic Semantics and Where to Find Them: Investigating Which Layers of Generative LLMs Reflect Lexical Semantics}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  url = {https://openreview.net/forum?id=Ayq2seFH22},
}
Figure