Table of Contents
Fetching ...

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

Zhu Liu, Cunliang Kong, Ying Liu, Maosong Sun

TL;DR

The paper addresses which layers of GPT-like LLMs encode lexical semantics, focusing on Llama2 and using the Word in Context benchmark. By probing end-of-layer hidden states under multiple input variants and applying anisotropy removal, it uncovers a bottom-up semantic evolution: lexical semantics peak in lower layers while higher layers prioritize next-token prediction. The results contrast with MLM-based models and provide practical guidance for selecting layer representations for lexical tasks versus generative tasks. This work advances interpretability of LLMs and informs engineering choices for leveraging layer-specific semantics in real-world applications.

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. Our codes are available at https://github.com/RyanLiut/LLM_LexSem.

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

TL;DR

The paper addresses which layers of GPT-like LLMs encode lexical semantics, focusing on Llama2 and using the Word in Context benchmark. By probing end-of-layer hidden states under multiple input variants and applying anisotropy removal, it uncovers a bottom-up semantic evolution: lexical semantics peak in lower layers while higher layers prioritize next-token prediction. The results contrast with MLM-based models and provide practical guidance for selecting layer representations for lexical tasks versus generative tasks. This work advances interpretability of LLMs and informs engineering choices for leveraging layer-specific semantics in real-world applications.

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. Our codes are available at https://github.com/RyanLiut/LLM_LexSem.
Paper Structure (18 sections, 3 figures, 3 tables)

This paper contains 18 sections, 3 figures, 3 tables.

Figures (3)

  • Figure 1: Key Differences between BERT and Llama2 Language Models. Blue and red lines indicate the information flows of understanding and predicting. The "understanding" refers to capture the lexical semantics by leveraging context. The blue line from the context to the current word indicates the flow of understanding.
  • Figure 2: Layer-wise accuracy for different settings and models (Llama2 and BERT_large). Star shows the best value.
  • Figure 3: Layer-wise accuracy of Llama2 representations (repeat and prompt setting), as well as the previous token in the repeat setting (repeat_prev). The increasing trends observed in repeat_prev and prompt accuracies, as well as the non-monotonic trend observed in repeat accuracy, suggest that while the understanding ability may be weakening, the predictive ability is improving.