Skip to main content
QUICK REVIEW

[Paper Review] How does GPT-2 compute greater-than?: Interpreting mathematical abilities in a pre-trained language model

Michael Hanna, Ollie Liu|arXiv (Cornell University)|Apr 30, 2023
Topic ModelingComputer Science14 citations
TL;DR

The paper analyzes GPT-2 small’s ability to perform a greater-than operation on year spans by identifying a minimal causal circuit within the model and explaining how MLPs and attention heads contribute to the behavior.

ABSTRACT

Pre-trained language models can be surprisingly adept at tasks they were not explicitly trained on, but how they implement these capabilities is poorly understood. In this paper, we investigate the basic mathematical abilities often acquired by pre-trained language models. Concretely, we use mechanistic interpretability techniques to explain the (limited) mathematical abilities of GPT-2 small. As a case study, we examine its ability to take in sentences such as "The war lasted from the year 1732 to the year 17", and predict valid two-digit end years (years > 32). We first identify a circuit, a small subset of GPT-2 small's computational graph that computes this task's output. Then, we explain the role of each circuit component, showing that GPT-2 small's final multi-layer perceptrons boost the probability of end years greater than the start year. Finally, we find related tasks that activate our circuit. Our results suggest that GPT-2 small computes greater-than using a complex but general mechanism that activates across diverse contexts.

Motivation & Objective

  • Investigate how pre-trained language models exhibit mathematical abilities without explicit training.
  • Apply mechanistic interpretability to GPT-2 small to uncover internal circuits for a simple math task.
  • Identify the minimal set of components necessary to compute the greater-than operation.
  • Characterize the roles of attention heads and MLPs in transmitting and processing numeric information.

Proposed method

  • Define the year-span prediction task where GPT-2 assigns higher probability to end years greater than the start year YY.
  • Use path patching to create a dataset (01-dataset) and measure how patching components affects logits and probability differences.
  • Iteratively identify circuit components by patching direct contributions to the logits from attention heads and MLPs (MLPs 8–11) to isolate the circuit.
  • Explain the circuit by analyzing attention patterns (logit lens) and neuron-level contributions within MLPs.
  • Evaluate circuit sufficiency via a targeted dataset patching experiment and assess necessity by cross-patching outside-circuit components.
Figure 1: Year-span prediction example ( XX =17 and YY =32) with sample (in)valid output years.
Figure 1: Year-span prediction example ( XX =17 and YY =32) with sample (in)valid output years.

Experimental results

Research questions

  • RQ1Can a minimal, causal circuit within GPT-2 small explain the greater-than operation on year-span prompts?
  • RQ2Which components (attention heads, MLPs, and neurons) are necessary and sufficient for computing greater-than in this task?
  • RQ3How do the identified circuit components interact to transmit the start year YY and compute the comparison?
  • RQ4Does the discovered circuit generalize to related prompts with similar format and output space?
  • RQ5Do the results differentiate memorization versus generalization as the source of GPT-2’s mathematical abilities?

Key findings

  • A circuit consisting of MLPs 8–11 and a9.h1 (attention head) largely accounts for the greater-than computation in the logits.
  • Attention heads appear to transmit the start year YY to downstream MLPs, which directly compute which output years are greater than YY.
  • MLP 10 (and to a lesser extent MLP 9 and MLP 11) contribute most directly to the greater-than decision, with neuron-level analysis showing the operation is distributed across multiple neurons within the MLPs.
  • Path-patching experiments show the circuit is largely sufficient (probability difference ~72.7% of original) and necessary when edges outside the circuit are disrupted (-36.6% in a control).
  • The logit lens analysis reveals that MLPs 9–11 upweight years greater than YY, forming an upper-triangular pattern that implements the comparison across the end-of-sentence position.
Figure 3: A : The computational graph of GPT-2, run on our normal dataset. B : GPT-2, where the (MLP 10, logits) path is patched to receive 01 -input. C : GPT-2, where the (Attn 10, MLP 10, logits) path receives 01 -input. Nodes receiving normal input have blue output; nodes receiving 01 -input have
Figure 3: A : The computational graph of GPT-2, run on our normal dataset. B : GPT-2, where the (MLP 10, logits) path is patched to receive 01 -input. C : GPT-2, where the (Attn 10, MLP 10, logits) path receives 01 -input. Nodes receiving normal input have blue output; nodes receiving 01 -input have

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.