Inference and Verbalization Functions During In-Context Learning

Junyi Tao, Xiaoyin Chen, Nelson F. LiuEMNLP 2024

Abstract

Recent research into Large Language Models (LLMs) reveals that In-Context Learning (ICL) operates through a distinct two-step internal pipeline. This process involves an initial inference function that computes an abstract task solution, followed by a verbalization function that maps this solution to specific output tokens. By employing interchange intervention techniques, this study demonstrates that internal task representations are often invariant to the specific label words used in the prompt.

Introduction

In-Context Learning (ICL) allows LLMs to perform new tasks based solely on a few examples provided in the prompt. A puzzling observation in prior work is that ICL remains effective even when labels are replaced with semantically unrelated words (e.g., using "cat" for "positive"). This suggests that models might not be merely matching surface patterns but performing abstract reasoning.

This paper investigates the causal mechanisms behind this behavior, proposing three primary hypotheses regarding the model's internal architecture:

  1. Causal Mechanism (H1): The model infers a task representation and then verbalizes it.
  2. Invariance (H2): The inference process is shared across different label sets for the same task.
  3. Localization (H3): These functions are consistently localized within specific model layers.
Overview of the ICL setting and the proposed hypotheses regarding inference and verbalization functions.

Methodology: Interchange Intervention

To test these hypotheses, the authors use Interchange Intervention (a form of activation patching). The method involves two parallel model instances: a "Source" model prompted with standard labels (e.g., "true/false") and an "Intervened" model prompted with remapped labels (e.g., "cat/dog").

By "transplanting" hidden state activations from a specific layer $l$ of the Source model into the Intervened model, researchers can observe if the output "flips" to the corresponding remapped label. A successful flip indicates that the representation at layer $l$ contains task-relevant information that is independent of the final verbalization.

Results and Key Insights

The experimental results across various benchmarks (NLI, Sentiment Analysis, Topic Classification) and models (Gemma, Mistral, Llama) strongly support the proposed two-stage pipeline.

The experimental setup for interchange intervention and the resulting flip rates across model layers, showing localization in middle layers.

Functional Localization and Label Invariance

The study found that the "verbalization" logic typically peaks in the middle-to-late layers. For instance, in Gemma-7B, interventions at layers 18–20 yielded flip rates exceeding 90%. This confirms that the model's internal "thought" regarding the task is fully formed before it is mapped to a specific output word. This "inference" stage is remarkably robust and invariant to changes in the label space.

Discussion and Limitations

While the findings provide a clear modular view of classification tasks, several questions remain. The study focuses on discrete label spaces; it is yet to be determined if this pipeline exists for open-ended generation. Additionally, because the method requires access to internal activations, it is currently limited to open-source models. Future work will explore how the "Inference" function itself is constructed in the earlier layers and whether these findings generalize to more complex, non-classification reasoning tasks.

Summary updated

BibTeX
@inproceedings{tao2024inference,
  author = {Junyi Tao and Xiaoyin Chen and Nelson F. Liu},
  title = {{Inference and Verbalization Functions During In-Context Learning}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.findings-emnlp.957},
}
Figure