Fantastic Semantics and Where to Find Them: Investigating Which Layers of Generative LLM s Reflect Lexical Semantics (2024)

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.

## introduction gpt-like large language models (llms) @xcite have recently demonstrated impressive performance on various understanding and generative tasks, shifting from the pretraining-then-finetuning approach employed by bert-like models @xcite . however, existing research @xcite suggests that the contextual representations of gpt-like models exhibit subpar performance in downstream tasks, struggling to fully capture the semantic nuances of words. this discrepancy raises a crucial research question: to what extent and through which layers do llms encode lexical semantics? previous research on intermediate layer representations in bert has revealed important linguistic information, including its hierarchy. for instance, bert encodes surface features at the bottom, syntactic features in the middle, and semantic features at the top @xcite . however, contextual representations in llms have received less attention due to structural differences and challenges, as illustrated in figure 1 . firstly, llms employ a decoder-only strategy, which restricts their ability to access only preceding context during inference. consequently, llms struggle to differentiate between homonymous meanings of words such as "bank" in the case of "the bank of the river" and "the bank to save money," due to the shared left context "the". furthermore, llms are trained to predict the next token, resulting in varying degrees of comprehension of historical and predictive contexts across layers @xcite . in contrast, bert focuses on masked word restoration through mask language modeling (mlm), where both understanding and prediction processes are targeted for the same word. in addition, the extraction of contextual word representations from generative large language models (llms) often proves to be more beneficial than those derived from models akin to bert in certain scenarios. firstly, as generative llms are increasingly recognized for their robustness and prevalence as foundational models @xcite , we only obtain "autoregressive embeddings" without compromising their generative capabilities. secondly, these llms are consistently trained with billions of parameters across expansive webscale datasets, thereby exhibiting a significantly greater potential and anticipated superior performance compared to their much lighter counterparts, such as bert-like models. given these observations, we hypothesize that gpt-like llms encode lexical semantics in lower layers while making predictions, potentially leading to the forgetting of information related to current tokens in higher layers. 1 this hierarchical behavior suggests a dynamic interaction between understanding and prediction in generative llms, as indicated by the view of information flow in recent studies @xcite . to validate our hypothesis, this study delves into the examination of lexical semantics in llms by analyzing how the hidden states at each layer reflect word meanings. in particular, we investigate the understanding of lexical semantics in the popular open-source llm, llama2 @xcite , utilizing the word in context benchmark @xcite . we employ various input transformation and prompting strategies to fully utilize the contextual information. the results suggest that lower layers of llama2 capture lexical semantics, while higher layers prioritize prediction tasks. these findings offer practical insights into determining which layers of hidden states to utilize as representations of the meaning of the current word in gpt-like llms. ## results and analysis in terms of parts-of-speech, nouns generally exhibit higher accuracy than verbs, as evidenced by a 7.1 advantage gap in llama2_repeat. we also observe that in the base setting, verbs exhibit significantly lower accuracy, with decreases of 8.1 points compared to nouns. this decline is attributed to the fact that disambiguating verbs requires more context, which is often lacking in real data preceding the verbs. for instance, target verbs positioned at the beginning of sentences, where there is no prior context to aid in disambiguation, account for 19.2% of cases, in contrast to 14.3% for nouns. these observations align with previous studies that have concluded that verbs are more challenging to disambiguate @xcite . ## conclusion this study investigates how llama2's layer-wise representations encode lexical semantics using the wic dataset. our experiments reveal that optimal performance is achieved at lower layers for generative tasks, while predictive accuracy improves in higher layers. this suggests that llama2 prioritizes understanding before prediction as information flows from lower to higher layers. these findings offer practical guidance on extracting representations for lexical semantics tasks in engineering applications. for example, we would opt to utilize representations from the lower layers for lexicalrelated tasks, such as pos tagging and word sense disambiguation. conversely, those from the higher layers could be employed for prediction-related or generative tasks, including text summarization and dialogue generation. furthermore, it also sheds light on the interpretability of llms from a topdown perspective.