Skip to main content
QUICK REVIEW

[Paper Review] Language Models Implement Simple Word2Vec-style Vector Arithmetic

Jack Merullo, Carsten Eickhoff|arXiv (Cornell University)|May 25, 2023
Topic ModelingComputer Science3 citations
TL;DR

This paper demonstrates that large language models (LLMs) solve one-to-one relational tasks—such as capital_of(Poland)=Warsaw—using a simple, interpretable vector arithmetic mechanism implemented via feedforward network (FFN) outputs. The key finding is that FFN outputs act as content-independent, reusable updates (e.g., Poland→Warsaw) that can be patched into new contexts to solve analogous tasks, revealing a modular, linear mechanism underlying complex in-context learning.

ABSTRACT

A primary criticism towards language models (LMs) is their inscrutability. This paper presents evidence that, despite their size and complexity, LMs sometimes exploit a simple vector arithmetic style mechanism to solve some relational tasks using regularities encoded in the hidden space of the model (e.g., Poland:Warsaw::China:Beijing). We investigate a range of language model sizes (from 124M parameters to 176B parameters) in an in-context learning setting, and find that for a variety of tasks (involving capital cities, uppercasing, and past-tensing) a key part of the mechanism reduces to a simple additive update typically applied by the feedforward (FFN) networks. We further show that this mechanism is specific to tasks that require retrieval from pretraining memory, rather than retrieval from local context. Our results contribute to a growing body of work on the interpretability of LMs, and offer reason to be optimistic that, despite the massive and non-linear nature of the models, the strategies they ultimately use to solve tasks can sometimes reduce to familiar and even intuitive algorithms.

Motivation & Objective

  • To investigate how large language models perform in-context learning on relational tasks such as capital cities, uppercasing, and past-tensing.
  • To determine whether the mechanisms underlying these tasks are simple and interpretable, despite the models’ overall complexity.
  • To identify whether feedforward networks (FFNs) play a distinct role in factual recall versus attention mechanisms in context.
  • To test whether FFN outputs can be manipulated via intervention to transfer knowledge across tasks and models.
  • To contribute to mechanistic interpretability by identifying a processing signature and intervention method for runtime behavior auditing.

Proposed method

  • Utilized early decoding via the language modeling head to monitor next-token predictions at each layer, enabling real-time observation of residual stream updates.
  • Applied vector intervention techniques by replacing FFN output vectors ($\vec{o}$) with those extracted from a single example to test transferability.
  • Trained and analyzed models across sizes (124M to 176B parameters), focusing on GPT2-Medium and GPT-J for detailed analysis.
  • Identified a distinct processing signature in which the argument (e.g., 'Poland') is surfaced early in the residual stream, followed by a linear FFN update that encodes the relation.
  • Used ablation studies to assess the necessity of FFN components when answers are locally available in the prompt versus retrieved from pretraining.
  • Mapped the role of FFNs in encoding content-independent relational functions (e.g., 'capital_of') that generalize across inputs like 'China' or 'France'.
Figure 1: When decoding the next word, additive updates are made through the residual connections of each attention/FFN sub-layer. To decode the running prediction at every layer, the pre-trained language modeling head is applied at various points in each layer as in Geva et al. ( 2022a ); nostalgeb
Figure 1: When decoding the next word, additive updates are made through the residual connections of each attention/FFN sub-layer. To decode the running prediction at every layer, the pre-trained language modeling head is applied at various points in each layer as in Geva et al. ( 2022a ); nostalgeb

Experimental results

Research questions

  • RQ1Do large language models use a simple, linear mechanism to solve one-to-one relational tasks during in-context learning?
  • RQ2Can FFN output vectors be identified as the primary carriers of relational knowledge, and are they reusable across different inputs?
  • RQ3Is this mechanism specific to retrieval from pretraining memory, or does it also operate when answers are directly present in the prompt?
  • RQ4Does the mechanism exhibit a consistent processing signature across different model sizes and architectures?
  • RQ5Can interventions on FFN outputs successfully transfer the function to solve novel instances of the same task?

Key findings

  • A distinct processing signature emerges in the residual stream where the input argument (e.g., 'Poland') is surfaced early, followed by a content-independent FFN update that encodes the relational mapping.
  • FFN output vectors ($\vec{o}$) implement a simple vector arithmetic mechanism that can be patched into unrelated contexts to solve new instances (e.g., replacing 'Poland' with 'China' to get 'Beijing').
  • This mechanism is specific to retrieval from pretraining memory; when answers are locally available in the prompt, FFNs can be ablated with minimal performance loss.
  • The mechanism generalizes across model sizes (124M to 176B parameters), with the processing signature becoming sharper in larger models.
  • Intervention experiments on GPT2-Medium show that replacing FFN outputs with those from a single example enables accurate prediction on new relational tasks.
  • The same phenomenon is observed in GPT-J, though with weaker effects and model-specific hyperparameter dependencies, indicating potential for model-agnostic generalization with further work.
Figure 2: Decoding the next token prediction at each layer reveals distinct stages of processing. The blue box (A) shows where the model prepares an argument for transformation, the red box (B) shows the function application phase during which the argument is transformed (here with the capital_of fu
Figure 2: Decoding the next token prediction at each layer reveals distinct stages of processing. The blue box (A) shows where the model prepares an argument for transformation, the red box (B) shows the function application phase during which the argument is transformed (here with the capital_of fu

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.