Semantic Embeddings from Intermediate Transformer Layers

This direction is split into other directions: optimal layer selection (intermediate layer utility). Its last version stays readable and citable here.

Version 1 of 1159 papers202 conceptsfrozen 2026-10-04

In the standard pipeline for using Large Language Models (LLMs), the final layer is usually treated as the "summit" of the model's intelligence. Whether for generating text or extracting features, conventional wisdom suggests that the deeper the layer, the more sophisticated the representation.

However, a growing body of research suggests that for tasks requiring general semantic understanding—such as document retrieval, sentence similarity, and cross-lingual alignment—the final layer is often the worst place to look. Instead, the most robust "world knowledge" and conceptual meaning are found in the model's intermediate layers.

The Specialization Bottleneck

The primary reason the final layer fails as a general-purpose embedding is a phenomenon often called "lexicalization pressure." As Yicheng Xu and colleagues argue in FreeRet: MLLMs as Training-Free Retrievers, the final layers of an LLM are heavily optimized for the pre-training objective: next-token prediction.

By the time information reaches the output layer, the model is no longer focused on the broad meaning of a sentence. Instead, it is narrowing down the probability distribution to select a specific word from the vocabulary. This specialization introduces noise and task-specific bias that degrades the utility of the embedding for downstream tasks. Oscar Skean and others in Layer by Layer: Uncovering Hidden Representations in Language Models demonstrate that while the final layer is excellent at predicting the next word, intermediate layers retain a "purer" semantic essence that is more effective for clustering and classification.

The Middle Layer Sweet Spot

If the final layer is too specialized, where exactly does the "meaning" live? Research across different domains—from code generation to medical signals—consistently points to the middle-to-late layers.

  • Cross-Lingual Neutrality: Zewen Chi in InfoXLM and Chih-chan Tien in Bilingual alignment transfers to multilingual alignment found that middle layers are the most "language-agnostic." While early layers focus on syntax and final layers focus on specific vocabulary, the intermediate stages capture universal concepts that allow a model to align English and German sentences without explicit training.
  • Lexical Integrity: For tasks like finding synonyms in context, Timothy Baldwin and Takashi Wada 0001 show that intermediate layers provide superior representations. They argue that the deepest layers over-specialize on the masked language modeling objective, losing the broader lexical meaning preserved in the middle.
  • Signal vs. Noise: In specialized fields like electrocardiography, Christos Chatzichristos found that diagnostic performance peaks in the middle layers. The final layers become too focused on reconstructing raw signal details, obscuring the high-level semantic features needed for medical classification.

Inference-Time Steering and Elicitation

Recognizing that the best embeddings are "trapped" in the middle of the model, researchers have developed "plug-and-play" techniques to elicit these representations without expensive fine-tuning.

In Contrastive Prompting Enhances Sentence Embeddings in LLMs through Inference-Time Steering, Zifeng Cheng and Qing Gu introduce a method that subtracts the activations of an "irrelevant info" prompt from a standard prompt at the intermediate layers. This forces the model to ignore stopwords and focus on core semantics.

Similarly, Yuchen Fu and Zhiwei Jiang proposed Token Prepending (TP) in Token Prepending: A Training-Free Approach for Eliciting Better Sentence Embeddings from LLMs. Because decoder-only models are causal (tokens can't see the future), early tokens often lack context. TP takes the global sentence representation from an intermediate layer and feeds it back into the start of the next layer, effectively giving the model "bidirectional" context for free.

Detecting Hallucinations through Layer Analysis

The discrepancy between intermediate semantic richness and final-layer lexicalization also provides a signal for model reliability. Zeming Wei and colleagues developed Effective Rank (ER), a method to detect hallucinations by analyzing the dimensionality of hidden states in middle layers.

When a model is "confused" or likely to fabricate a fact, the semantic consistency of its intermediate representations breaks down. By extracting these signals from the mid-layers—rather than the final output—researchers can identify when a model is likely to hallucinate before the text is even generated.

Summary of Intuition

The shift toward intermediate layer extraction treats the Transformer not as a linear progression toward a "perfect" representation, but as a U-shaped journey.

  1. Early layers handle low-level syntax and surface-level features.
  2. Middle layers form a "semantic plateau" where abstract concepts and cross-lingual meanings are most stable.
  3. Final layers collapse this abstraction back into the specific, narrow constraints of the model's vocabulary and training objective.

By "exiting" the model early or pooling information across these middle layers, researchers can bypass the noise of the final layers and access the model's most robust internal world-view.

Papers in this version

Showing 60 of 159 papers.

History & citationVersion 1 · 2026-10-04

Split into other directions · Permanent link

View frozen version 1

Cite this direction

Latest version (a living page):

@misc{lacuna_semantic_embeddings_from_intermediate_tr_09de439e,
  title = {Semantic Embeddings from Intermediate Transformer Layers},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/semantic-embeddings-from-intermediate-transformer-layers/rdr_09de439ea1944184ac8d370b0b9566cc},
  note = {Latest version of a living research direction; cite a version for a fixed text. Accessed 2026-11-20},
}

This exact version (version 1, frozen text):

@misc{lacuna_semantic_embeddings_from_intermediate_tr_09de439e_v1,
  title = {Semantic Embeddings from Intermediate Transformer Layers},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/semantic-embeddings-from-intermediate-transformer-layers/rdr_09de439ea1944184ac8d370b0b9566cc/v/1},
  note = {Version 1, frozen 2026-10-04. Accessed 2026-11-20},
}