NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Analyzing Chain-of-Thought Prompting in Large Language Models via Gradient-based Feature Attributions

Skyler Wu, Eric Meng Shen, Charumathi Badrinath, Jiaqi Ma, Himabindu Lakkaraju

TL;DR

While Chain-of-Thought (CoT) prompting empirically boosts the accuracy of Large Language Models (LLMs), understanding why it works has remained an open question. This paper peers under the hood using gradient-based feature attribution, revealing that CoT does not make models focus "harder" on key tokens. Instead, it significantly increases the stability and robustness of the model's internal focus against question rewordings and stochastic generation variations.

What Problem Does This Paper Address?

Chain-of-Thought (CoT) prompting—asking an LLM to "think step-by-step" before providing a final answer—is a highly effective technique for improving performance on complex reasoning tasks. However, why this simple trick works is poorly understood. Some prior behavioral studies suggest that CoT simply forces the model to output a specific structure, showing that even incorrect intermediate reasoning steps can still yield accurate final answers.

To establish a more faithful, mechanistic understanding, the authors look past the text generated on the surface and examine the model's internal gradients. They address a fundamental question: How does CoT prompting alter the relative importance an LLM assigns to different input tokens when computing its final answer?

Methods

The authors employ gradient-based feature attribution methods to compute "saliency scores" for input tokens. Saliency scores measure the influence of each input token on the model's final predicted token by calculating the gradient of the output logit with respect to the input token embeddings.

To ensure robust observations, they use four distinct saliency formulations adapted from prior literature:

  1. Gradient × Input: Multiplies the gradient by the token embedding vector.
  2. L1 Norm: Computes the absolute sum of the gradient vector components.
  3. Contrastive Gradient × Input: Measures why the model chose the predicted token over an alternative "foil" token.
  4. Contrastive L1 Norm: The contrastive version of the L1 Norm method.

The framework was evaluated across three open-source autoregressive transformers: GPT-J (6B), GPT-Neo (2.7B), and GPT-2 XL (1.5B). While these models are smaller than the scale at which CoT accuracy gains typically emerge (>100B parameters), they still exhibit measurable shifts in internal processing behavior.

Datasets

The authors evaluated the framework on four question-answering datasets (50 questions each), spanning different reasoning types:

  • SST (Stanford Sentiment Treebank v2): Movie reviews for binary sentiment classification.
  • CoinFlip: A tracking task determining if a coin remains heads/tails up after a series of flips.
  • GSM8K (Grade School Math 8K): Multi-step math word problems.
  • CSQA (CommonsenseQA): Multiple-choice commonsense reasoning questions.

To test robustness, the authors also manually created reworded versions of the CoinFlip and GSM8K datasets, altering the sentence structures while strictly preserving the vocabulary and semantic meaning.

Key Insights and Ideas

  • The "Dilution Effect": Counterintuitively, CoT prompting uniformly decreases the absolute magnitude of saliency scores for semantically relevant tokens compared to standard prompting. Because CoT prompts are longer and contain intermediate explanations, the model's "attention" and gradient weights are spread across a larger pool of tokens.
  • Stability Over Intensity: CoT’s true benefit lies in stabilization rather than amplification. Under standard prompting, minor changes in a question's phrasing cause wild shifts in which tokens the model deems important. CoT prompting anchors the model, ensuring it consistently prioritizes the same core semantic tokens regardless of syntax.
  • Gradients are Agnostic to Semantic Errors: Saliency scores remain tightly clustered during CoT generation even when the model outputs a variety of different unique answers across random runs. This implies that CoT primes the model's internal mechanics into a stable state, even if the model scale isn't large enough to always synthesize the correct text.

Key Results

  • Saliency Reduction: Across all datasets and feature attribution methods, CoT prompting consistently lowered the mean absolute saliency scores of human-annotated "relevant" tokens (as shown in Figure 1).
Figure 1. Mean absolute saliency scores of relevant tokens on all four original datasets using GPT-J, with and without CoT prompting.
  • Robustness to Rewording: In Experiment 2, standard prompting showed massive variance in token saliency between original and reworded questions. With CoT prompting, the variance dropped dramatically, demonstrating that the model's internal focus remains steady despite syntactic perturbations (see Figure 2).
Figure 2. GPT-J mean absolute saliency scores of relevant tokens on GSM8K (Original) and (Reworded), with / without CoT.
  • Output Stochasticity: When introducing randomness into text generation (Experiment 3), running the same question 20 times under standard prompting yielded highly scattered saliency distributions. CoT prompting produced significantly tighter clusters of saliency scores across repeated runs.

Limitations and Future Work

The primary limitation of this study is model scale. Due to computational constraints, the authors could only evaluate models up to 6B parameters. Since the dramatic accuracy improvements of CoT prompting typically manifest in models with more than 100B parameters, a critical next step is validating these gradient behaviors on much larger open-source models (like LLaMA or Falcon variants).

Additionally, the datasets were limited to 50 questions each, and identifying "semantically relevant tokens" relied on manual human annotation. Future work could scale this analysis up by utilizing automated NLP toolkits (such as spaCy) for token labeling and crowdsourcing platforms for generating larger volumes of reworded questions.

Summary updated

BibTeX
@inproceedings{wu2023analyzing,
  author = {Skyler Wu and Eric Meng Shen and Charumathi Badrinath and Jiaqi Ma and Himabindu Lakkaraju},
  title = {{Analyzing Chain-of-Thought Prompting in Large Language Models via Gradient-based Feature Attributions}},
  booktitle = {DeployableGenerativeAI @ ICML},
  year = {2023},
  url = {https://openreview.net/forum?id=xnXln7c0no},
}
Figure