Source-linked AI summary

Attention Satisfies: A Constraint-Satisfaction Lens on Factual Errors of Language Models

Mert Yuksekgonul, Varun Chandrasekaran, Erik Jones, Suriya Gunasekar, Ranjita Naik, Hamid Palangi, Ece Kamar, Besmira Nushi

arXiv:2309.15098v2cs.CLcs.AIcs.LG

TL;DR

Language models can generate factually incorrect text, while how they process factual queries and produce errors remains insufficiently understood. The paper models factual queries as constraint-satisfaction problems and probes attention to constraints. It finds that attention-based SAT Probe predicts factual correctness comparably to model confidence and can identify errors before the forward pass is complete.

  • Problem

    How LLMs internally process factual queries and produce errors remains nascently understood, despite their tendency to generate factually incorrect text.

    Source: §1 · p. 1
  • Method

    The paper models factual queries as constraint-satisfaction problems and uses attention to constraint tokens to predict whether constraints are satisfied.

    Source: §1 · pp. 1–2
  • Results

    SAT Probe predicts factual correctness comparably to model confidence and can provide fine-grained constraint feedback and identify errors partway through the forward pass.

    Source: §1 · p. 2, §5.1 · p. 8
  • Takeaways & Limitations

    The findings demonstrate the potential of model internals for understanding and mitigating factual errors.

    Source: §1 · p. 2, §5.1 · p. 8

    The study covers conjunctive factual queries and assumes access to constraint tokens; broader query types and extracting those tokens remain open scope boundaries.

    Source: §7 · p. 9

Abstract

from arXiv · show

We investigate the internal behavior of Transformer-based Large Language Models (LLMs) when they generate factually incorrect text. We propose modeling factual queries as constraint satisfaction problems and use this framework to investigate how the LLM interacts internally with factual constraints. We find a strong positive relationship between the LLM's attention to constraint tokens and the factual accuracy of generations. We curate a suite of 10 datasets containing over 40,000 prompts to study the task of predicting factual errors with the Llama-2 family across all scales (7B, 13B, 70B). We propose SAT Probe, a method probing attention patterns, that can predict factual errors and fine-grained constraint satisfaction, and allow early error identification. The approach and findings take another step towards using the mechanistic understanding of LLMs to enhance their reliability.

1 INTRODUCTION

Understanding how language models process factual queries and produce errors remains an open challenge. The paper studies attention to factual constraints and uses it to predict constraint satisfaction and factual errors.

1 INTRODUCTION

  • The authors frame factual queries as constraint-satisfaction problems whose constraints completions must satisfy to be correct.The introduction illustrates constraints such as a movie’s director or award name.Source: §1 · pp. 1–2
  • SAT Probe uses attention to constraint tokens to predict constraint satisfaction and factual correctness.The paper reports that it performs comparably to model confidence and can identify errors partway through the forward pass.Source: §1 · p. 2
  • Attention to constraint tokens correlates with factual correctness, with less attention associated with inaccurate responses.Source: §1 · p. 2
  • The study uses 10 datasets with more than 40,000 prompts to evaluate factual-error prediction.The datasets include single- and multi-constraint queries.Source: §1 · p. 2

2 BACKGROUND: LANGUAGE MODELS AND FACTUAL RECALL

The section introduces Transformer representations and attention, then situates the paper’s focus against prior work on factual recall. Prior studies mainly examine correct completions, while this work focuses on incorrect ones.

2 BACKGROUND: LANGUAGE MODELS AND FACTUAL RECALL

  • Transformer layers transform input embeddings into hidden states, and the final-layer representation at the last token is used to predict the next token.Source: §2 · p. 2
  • Attention updates a token’s state using earlier token states, making it the operation of interest for studying token interactions.The section says standard Transformer MLP layers do not capture token interactions.Source: §2 · p. 2
  • In autoregressive LLMs, attention weights are lower triangular because each token can attend only to previous tokens.Source: §2 · p. 3
  • Prior work suggests that MLP layers store factual associations and attention transfers factual information from subject tokens to where it is used.For example, the section describes attention transferring information about LeBron James from the subject tokens to the final token used to generate “basketball.”Source: §2 · p. 3
  • Unlike most cited factual-recall studies, this work investigates mechanisms involved when LLMs produce factually incorrect text.Source: §2 · p. 3

3 FACTUAL QUERIES AS CONSTRAINT SATISFACTION PROBLEMS

The section models factual queries as constraint-satisfaction problems to represent both correctness and query difficulty. It relates query popularity and constrainedness to LLM performance and argues that this lens helps analyze factual errors.

3 FACTUAL QUERIES AS CONSTRAINT SATISFACTION PROBLEMS

  • Binary correctness labels cannot distinguish easy queries from barely-correct ones or reveal which query parts drive failure.Source: §3 · p. 3
  • A factual query is represented by constraints and verifiers, and a completion is an error if any constraint’s verifier returns zero.Source: §3 · p. 3
  • The framework focuses on conjunctions of constraints and assumes access to the tokens that identify the constraints in its evaluations.The text notes that the framework could be generalized to other operations.Source: §3 · p. 3
  • LLM performance is better for more popular entities, and larger models perform better for less popular entities.Popularity is approximated using the number of site links on a WikiData page.Source: §3 · p. 4
  • More constrained problems, with fewer potential solutions, have lower LLM performance, while larger models perform better across constrainedness levels.Source: §3 · p. 4, Figure 2 · p. 4
  • The CSP lens is proposed as a useful way to capture factual-query difficulty and discuss how LLMs process queries and generate errors.Source: §3 · p. 4

4 UNDERSTANDING FACTUAL ERRORS VIA ATTENTION TO CONSTRAINTS

The section examines attention to factual constraints as a signal of correctness, finding that stronger constraint attention accompanies accurate answers across confidence cases and model scales.

  • The analysis tracks attention contributions from constraint tokens to the final token used for generation, including constraints composed of multiple tokens.Source: §4 · pp. 4–5
  • Across Llama-2 7B, 13B, and 70B, attention predicts constraining-entity popularity with held-out Spearman’s Correlation ρ ≥0.65 and p-value p ≈0.The authors note that popularity may not be available as a clean measure, motivating a more direct indicator of factual correctness.Source: §4 · p. 5
  • Correct generations show stronger constraint-token attention than failures, and total attention to constraints correlates with accuracy.The analysis compares attention across confident and less-confident predictions and relates total constraint attention to accuracy across query groups.Source: §4 · p. 5
  • Across model scales, greater relative attention in both models generally accompanies shared success, while larger-model-only success occurs when the larger model attends more.The authors report that performance improvements in larger models correlate with increased attention to constraint tokens.Source: §4 · p. 6

5 PREDICTING FACTUAL ERRORS USING ATTENTION TO CONSTRAINTS

This section frames factual-error prediction as estimating whether a query’s constraints are satisfied, using attention to those constraints as a predictor. It evaluates SAT PROBE against confidence and other baselines, then explores early stopping, constraint-level predictions, and predictors generalized across constraint types.

5 PREDICTING FACTUAL ERRORS USING ATTENTION TO CONSTRAINTS

  • The benchmark contains 10 datasets with over 40,000 queries, evaluated using Llama-2 7B, 13B, and 70B variants.Single-constraint queries use exact match when there is one solution and WikiData verification when multiple solutions are possible.Source: §5 · p. 7

5.1 PREDICTING FACTUAL CORRECTNESS

  • SAT PROBE estimates constraint satisfaction from self-attention, using a linear probe over attention weights across layers and heads.For multi-constraint queries, it combines predictions for individual constraints.Source: §5.1 · p. 7
  • Exact-match verification is a strict criterion that can introduce noise into evaluations where it is used.The authors identify this as a limitation of their verification approach.Source: §5.1 · p. 7
  • SAT PROBE is often comparable to CONFIDENCE and better than POPULARITY, while COMBINED performs best in most scenarios.Across single- and multi-constraint settings, SAT PROBE also provides fine-grained feedback; the figure reports standard errors over 10 random train/test splits.Source: Figure 6 · p. 8, §5.1 · p. 8
  • Attention alone significantly outperforms the CONSTANT baseline and sometimes exceeds CONFIDENCE, but it does not explain every failure.The authors report cases where attention to constraints is present even though the model still fails.Source: §5.1 · p. 8

5.2 EXTENSIONS

  • For Llama-2 7B and 13B, early stopping preserves average performance while saving 50% of failure-case wall-clock time on most datasets; 70B shows a slight performance drop.The predictor uses attention only up to an intermediate layer.Source: §5.2 · p. 9
  • SAT PROBE predicts satisfaction for individual constraints with results comparable to single-constraint prediction, unlike raw CONFIDENCE, which gives one value for all constraints.The authors suggest partial constraint-satisfaction reports may help debug issues such as failure to follow specific instructions.Source: §5.2 · p. 9
  • A single predictor trained across mixed single-constraint datasets performs competitively with predictors trained separately and better than POPULARITY.The authors present this as potential for developing general factual-error detectors.Source: §5.2 · p. 9

6 RELATED WORK

Related work examines factual recall, attention mechanisms, truthfulness interventions, and black-box hallucination checks; this paper distinguishes its focus on predicting factually incorrect text and fine-grained constraint satisfaction.

6 RELATED WORK

7 CONCLUSION AND FUTURE WORK

The study offers initial mechanistic insights into factual errors but covers only conjunctive factual queries and assumes access to constraint tokens. It identifies broader constraints, opaque attention signals, and error correction as future-work directions.

7 CONCLUSION AND FUTURE WORK

  • The analysis covers conjunctive factual queries, while possible constraints also include instructions and disjunctive queries, so the framework does not cover all factual queries.The approach also assumes access to constraint tokens; extracting them is left for future work.Source: §7 · p. 9
  • The information carried by attention patterns remains opaque and warrants further investigation.Source: §7 · p. 9
  • Future work could investigate actions to fix errors, including steering model behavior by manipulating attention to constraints.The authors hope these methods and analyses contribute to the pursuit of reliable and safe LLM generations.Source: §7 · p. 9

A MODEL DETAILS

The experiments use Llama-2 models with greedy decoding; 70B is quantized to fit a single A100 GPU. The analysis focuses on attention contributions, while MLP contributions remain unexplored.

A MODEL DETAILS

  • Llama-2 70B uses 8-bit quantization to fit on one A100 GPU with 80GB of memory, and all models use greedy decoding at temperature 0.The models are accessed through HuggingFace Transformers.Source: A MODEL DETAILS · p. 14
  • Grouped-Query Attention reduces the KV cache loaded at each inference step, but does not change analyses of attention weights or attention contributions.The passage describes Llama-2 70B as using an 8 key-value projection variant of GQA.Source: A MODEL DETAILS · p. 14
  • The study examines attention contributions rather than MLP contributions, which may also contain relevant signals.The authors leave exploration of MLP contributions to future work.Source: A MODEL DETAILS · p. 14

B.1 SINGLE-CONSTRAINT EXPERIMENTS

In the single-constraint experiments, SAT PROBE with attention weights performs better than the attention-contribution variant. Evaluation uses train/test splits, feature normalization, and repeated seeded runs.

B.1 SINGLE-CONSTRAINT EXPERIMENTS

  • Each dataset is split into train and test sets, and features are normalized to zero mean and unit variance using the training split.Source: §B.1 · p. 14
  • A logistic regressor with C = 0.05 L1 regularization is trained on one subset and evaluated on the other across 10 random seeds.The reported performance is the mean with standard error for each dataset and method.Source: §B.1 · p. 14
  • SAT PROBE(A), which uses attention weights, performs better than SAT PROBE(a), which uses attention contribution.Source: §B.1 · p. 14

B.2 MULTI-CONSTRAINT EXPERIMENTS

These appendix experiments extend attention-based failure prediction to multi-constraint queries, early inference, and shared predictors, while also specifying how attention to constraints is measured.

B.2 MULTI-CONSTRAINT EXPERIMENTS

  • Multi-constraint splits keep identical constraint pairs out of both training and test sets, and correctness requires satisfying both query constraints.Constraint pairs are treated as sets, so prompts with reversed constraint order stay in the same split.Source: §B.2 · p. 14

B.3 PREDICTING PARTIAL CONSTRAINT SATISFACTION

  • Partial-satisfaction experiments predict each constraint separately; confidence is not a baseline because it cannot make per-constraint predictions.The authors point to future work on individual instructions and queries with logical operators such as OR.Source: §B.3 · p. 15

B.4 EARLY STOPPING EXPERIMENTS

  • Up to 50% less computation time causes little or no failure-prediction performance drop for most datasets, while Llama-2 70B benefits more from later layers.The authors suggest attention patterns could support early abstention or escalation.Source: §B.4 · p. 15

B.5 GENERALIZING THE FAILURE PREDICTOR

  • A single predictor trained on mixed single-constraint datasets remains better than POPULARITY and competitive with individual predictors, with only minor performance fluctuations.The mixture uses 50% of each dataset for training and 50% for testing.Source: §B.5 · p. 15, Figure 8 · p. 16

C.1 PREDICTING POPULARITY

  • Basketball-player popularity is predicted from attention using Lasso regression on entities with at least 15 site links, split equally into training and test sets.The regression uses a 0.005 regularization strength.Source: §C.1 · p. 16

C.2 COMPUTING ATTENTION TO A CONSTRAINT

  • Constraint attention is measured as the maximum across all constraint tokens, since tokenization and ambiguity can make earlier tokens more informative than the last token.For Kelly Oubre Jr., the passage reports little attention to “Jr.” and the most attention on “Oubre.”Source: §C.2 · p. 17

D.1 DATA CURATION FOR SINGLE-CONSTRAINT QUERIES

The appendix describes how single- and multi-constraint query datasets were assembled and how their completions were checked, using exact match, knowledge-base lookup, or character checks as appropriate.

D.1 DATA CURATION FOR SINGLE-CONSTRAINT QUERIES

  • Four non-CounterFact query groups use WikiData entities with at least five site links and fields selected to support exact-match evaluation.The site-link threshold is intended to avoid extremely tail knowledge and low-quality entity samples.Source: §D.1 · p. 17
  • CounterFact queries use mother tongue, citizenship, and headquarters-location relations selected for less variation in valid exact-match answers.The authors report nontrivial model performance on these relations despite using exact match.Source: §D.1 · p. 18

D.2 DATA CURATION FOR MULTI-CONSTRAINT QUERIES

  • The multi-constraint datasets contain 1,352 word prompts, 1,290 Nobel-winner prompts from 645 cities, and 1,492 book prompts from 746 books.Each of the three datasets has at least one correct completion per query.Source: §D.2 · p. 19

D.3 VERIFICATION

  • For single-constraint queries, exact match checks whether the first |Y| generated tokens equal the reference, and prompts are shaped to elicit the desired format.For example, a question can include “the year founded in” and the response can begin “The team was founded in.”Source: §D.3 · p. 19
  • Multi-constraint book verification looks up the generated entity in WikiData, retrieves relevant fields, then uses GPT-3.5 to check whether each constraint appears in those fields.The GPT-3.5 step is limited to multi-constraint queries because it is not cheap.Source: §D.3 · p. 19
  • Word-query constraints are checked by testing the first or last character of the completion’s first word.Source: §D.3 · p. 19

E COMPARING CONFIDENCE AND ATTENTION

The paper compares attention- and confidence-based failure predictions on basketball-player and football-team test sets. The predictors do not always agree, and their disagreements become more pronounced for larger models.

E COMPARING CONFIDENCE AND ATTENTION

Loading 2309.15098v2…