wikillm

Paper · 2023-01-31 · cs.CL, cs.AI

Large Language Models Can Be Easily Distracted by Irrelevant Context

Adds one irrelevant sentence to 100 GSM8K base problems (58,052 variants, GSM-IC) and measures prompting methods. Chain-of-thought, least-to-most and program prompts fall from 83-95% on the base problems to 62-81% micro accuracy. Self-consistency (20 samples) lifts least-to-most to 93.4% micro but only 45.0% macro. An instruction to ignore irrelevant information also helps. Author-reported.

Chain-of-thought promptingSelf-consistencyPrompt engineeringbenchmarkrobustnessreasoningpromptingself-consistency

arXivPDFMarkdown11 min read

AI-compiled by claude-haiku-5-5 on 2026-10-18, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.

In plain words

Maths word problems are often solved by a language model that writes out its steps. This paper asks what happens when the problem also contains a sentence that has nothing to do with the answer, such as an unrelated detail about a person in the story. The authors built a test set by adding one such sentence to easy school maths problems and found that the models' answers often change, even when they solved the original problem correctly.

Three things helped. Showing the model an example that already ignores such a sentence helped. Adding a plain instruction to ignore irrelevant information also helped. The largest gain came from asking the model many times and taking the most common answer, which is also known as voting. Even with these fixes, most of the original problems were not solved reliably once different distractors were added.

The point for an engineer is that a prompt that scores well on clean benchmarks can still be fragile when the input carries extra, unrelated text.

TL;DR

The paper introduces GSM-IC, which adds one irrelevant sentence to each of 100 easy GSM8K base problems and yields 58,052 variants §3.1 app. A. It measures micro, macro and normalised accuracy §3.2. On code-davinci-002, every tested prompting method loses accuracy, and macro accuracy never exceeds 45% tab. 3. Self-consistency (20 samples, majority vote) gives the largest gain, and an instruction to ignore irrelevant information also helps §5.1 §5.3. Relevant if you deploy prompts on inputs that may contain unrelated context.

Problem

Benchmarks usually contain only information that bears on the answer, but real inputs often carry related and unrelated details §1. The paper assumes that a sentence which does not change the standard solution should not change a correct model's answer §1 §3.1. It measures this distractibility with accuracy on the variants and on the base problems §3.2.

Method

The paper has two parts: a dataset construction procedure §3.1, and an evaluation of prompting techniques and mitigations on that dataset §4 §5.

  1. Choose base problems. Sample a 1,000-problem development pool from GSM8K's training split. Keep 100 that at least one prompting technique solves correctly. Each base problem needs two to seven reasoning steps, and 60 need two steps §3.1; the step distribution is in app. A.
  2. Create variants. Add one irrelevant sentence before the question. Each sentence is produced from a template and is either in-topic (close to the problem) or off-topic §3.1 tab. 1 app. A. Three factors are varied orthogonally §3.1 fig. 1:
    • topic: in-topic or off-topic;
    • role-name overlap: the filled name either reuses a role from the problem (for example "X's father") or uses a name not in the problem;
    • number range: the inserted number is in range or out of range.
  3. Verify. The authors manually checked that each sentence reads as correct English and does not change the standard solution §3.1. Where a sentence made a pronoun ambiguous, the question was reworded app. A.
  4. Evaluate. Score each method with micro, macro and normalised accuracy §3.2 (see Pseudocode below). Methods: chain-of-thought (CoT), zero-shot CoT, least-to-most (LtM) and program prompts §4.1. Self-consistency (SC) is applied on top of these §4.1.
  5. Mitigate. Put irrelevant information in the exemplar §4.2. Add an instruction before the exemplars §4.3. Use SC §4.1 §5.1.

Dataset construction, as pseudocode:

Pseudocode
# Build one GSM-IC variant from a base problem  [§3.1] [app. A]
# Inputs: base problem text, standard solution, factor settings
# Output: problem text with one irrelevant sentence inserted

def make_variant(problem, solution, in_topic, overlap, in_range):
    # Numbers the sentence may be compared against  [§3.1]
    known_numbers = numbers_in(problem) + numbers_in(solution)
    # Pick a template for the chosen topic kind  [app. A] [tab. 1]
    template = pick_template(problem, in_topic)
    # Fill the role blank: reuse a role in the problem, or a fixed name  [app. A]
    role = pick_role(problem, overlap)
    # Fill the number blank in range or out of range  [§3.1] [app. A]
    number = pick_number(known_numbers, in_range)
    sentence = template.format(role=role, number=number)
    # Insert the sentence immediately before the question  [tab. 1]
    return insert_before_question(problem, sentence)

Number rule, as pseudocode:

Pseudocode
# A number a is in range if some known number b has 1/10 <= a/b <= 10  [§3.1]
def is_in_range(number, known_numbers):
    return any(
        0.1 <= number / other <= 10
        for other in known_numbers
    )

Hyperparameters

NameValueWhereNotes
Modelscode-davinci-002 (main); text-davinci-003 (second)§5OpenAI API models named by the paper; availability today not checked
Greedy decodingtemperature 0§5used for all non-SC runs
SC samples20§5 §5.1
SC temperature0.7§5
SC aggregationmajority vote; random choice among top-tier answers on a tie§5.1 footnote
Evaluation setGSM-IC-4K: 4,000 examples sampled uniformly from GSM-IC; covers all 100 base problems§5
Base problems100, chosen from a 1,000-problem GSM8K training-set subset§3.1the base set is an "easy" subset
Exemplars1 exemplar (a 2-step problem); with or without the irrelevant sentence§4.2 app. CLtM uses the same single exemplar
Instruction"Solve grade school math problems. Feel free to ignore irrelevant information given in the questions."§4.3 app. Cprepended before exemplars
Zero-shot trigger"Let's think step by step:" after "A:"§4.1 app. C
Max tokens, top-p, stop sequencesnot stated
Program executionPython run by an external interpreter; timeout not stated§4.1
Dataset size58,052 variants§3.1counts checked against the authors' data files, see Paper vs code

Program prompts use a Python program as the solution, executed to obtain the answer §4.1 app. C.

Results

Author-reported. Setup: GSM-IC-4K; code-davinci-002 unless noted §5.

Base problem accuracy on the 100 base problems, code-davinci-002 tab. 2:

MethodCoTLtMProgram0-CoT
Accuracy95.094.083.044.0
+ SC96.099.091.076.0

For text-davinci-003 the base accuracy is 80.0 for CoT and 81.0 for LtM tab. 3 caption.

Main results on GSM-IC-4K tab. 3. Columns: micro accuracy and macro accuracy, each split into 2-step and more-than-2-step problems, overall, and normalised ("Norm") by base accuracy.

MethodMicro 2Micro >2Micro allMicro NormMacro 2Macro >2Macro allMacro Norm
Exemplar without irrelevant context, code-davinci-002
CoT73.570.872.476.28.32.56.06.3
CoT + Inst.79.076.077.881.820.07.015.015.8
0-CoT29.029.129.065.91.70.01.02.3
0-CoT + Inst.31.628.830.569.31.70.01.02.3
LtM74.981.577.582.416.720.018.019.1
LtM + Inst.80.181.380.685.718.335.025.026.6
Program59.147.454.465.56.72.55.06.0
Program + Inst.60.650.956.768.36.75.06.07.2
CoT + SC87.690.188.191.829.028.330.031.3
0-CoT + SC61.668.464.384.60.02.51.01.3
LtM + SC92.494.893.494.351.635.045.045.5
Program + SC73.576.174.682.016.77.513.014.3
Exemplar without irrelevant context, text-davinci-003
CoT69.366.968.485.410.07.59.011.3
CoT + Inst.72.070.371.389.111.712.512.015.0
LtM78.073.676.394.25.00.05.06.2
LtM + Inst.80.570.976.794.75.00.05.06.2
Exemplar with irrelevant context, code-davinci-002
CoT79.872.476.880.816.710.014.014.7
CoT + Inst.80.574.478.182.220.012.017.017.9
LtM78.184.680.785.923.335.028.029.8
LtM + Inst.81.085.482.888.123.335.028.029.8
Program67.055.062.274.911.75.09.010.8
Program + Inst.68.854.863.276.115.07.512.014.5

Breakdown by the factors of the inserted sentence tab. 4. Micro then macro; columns are Topic (In / Off), Role overlap (Yes / No), Number range (In / Out).

MethodMicro Topic InMicro Topic OffMicro Role YesMicro Role NoMicro Num InMicro Num OutMacro Topic InMacro Topic OffMacro Role YesMacro Role NoMacro Num InMacro Num Out
code-davinci-002, without irrelevant context
CoT63.180.768.376.670.274.610.233.010.322.211.019.0
LtM70.883.477.078.277.277.823.545.025.835.427.029.0
Program44.163.550.758.454.354.54.124.09.316.27.011.0
text-davinci-003, without irrelevant context
CoT63.372.968.768.167.269.616.336.017.520.219.022.0
LtM75.476.975.676.875.377.26.17.06.29.16.06.0
code-davinci-002, with irrelevant context
CoT70.282.773.680.276.177.718.443.021.632.322.026.0
LtM73.087.581.480.280.081.428.658.037.142.441.035.0
Program52.970.560.264.561.562.810.237.014.423.215.017.0

Instruction and exemplar effects on GSM8K dev and SVAMP test tab. 5. The table as printed is ambiguous, see Pitfalls.

MethodInstructionExemplar with irrelevant contextGSM8K devSVAMP test
CoTnoyes59.379.1
CoTnono (baseline)60.377.6
CoT + Inst. (printed label "CoT")yesyes59.379.1
CoT + Inst. (printed label "+Inst.")yesno58.878.7
LtMnoyes61.976.9
LtMnono (baseline)59.876.6
LtM + Inst.yesyes60.976.2
LtM + Inst.yesno60.376.3
Programnoyes58.680.0
Programnono (baseline)59.877.3
Program + Inst.yesyes59.277.9
Program + Inst.yesno61.177.8

Complicated prompts, micro accuracy tab. 6: a 4-exemplar CoT prompt scores 66.3 on GSM8K dev (1 exemplar: 60.3) but 69.4 on the more-than-2-step split (1 exemplar: 70.8). With the instruction, the 1-exemplar CoT scores 58.8 on dev, 79.0 on 2-step and 76.0 on more-than-2-step; the 4-exemplar version scores 66.5, 79.2 and 70.6 §5.4.

DROP football split, accuracy tab. 7 (code-davinci-002 / text-davinci-003): CoT 67.4 / 68.2; CoT + Inst. 68.9 / 69.9; LtM 73.4 / 70.2; LtM + Inst. 74.4 / 72.8 §5.5.

Headline numbers, quoted from the text §5.1: the recall of the correct answer within 20 samples is 99.7% for CoT and LtM; the best macro accuracy with any prompting technique is 45%.

Paper vs code

No official method code. The paper's abstract footnote links google-research-datasets/GSM-IC. That repository holds the dataset files and a README, and has no LICENSE file. It contains no prompts, sampling or scoring code. So no code, code_commit or code_license is recorded, and nothing is quoted or cited from it. A GitHub search for "GSM-IC" found no other repository by the authors. The authors' data files were used only to check the dataset size: the 2-step file has 34,220 examples, and the more-than-2-step file has 8,864 (3 steps), 7,392 (4), 5,160 (5), 1,776 (6) and 640 (7), for 58,052 in total, which matches §3.1.

Pitfalls

  • Macro accuracy is strict. A base problem counts only if every one of its variants is answered correctly §3.2. The 45% ceiling is for macro accuracy; micro accuracy is much higher tab. 3.
  • Normalisation uses base accuracy. Divide by the base accuracy from tab. 2 for code-davinci-002, and by 80.0 (CoT) or 81.0 (LtM) for text-davinci-003 tab. 3 caption.
  • Text and table disagree in places.
    • The text says LtM "achieves about double macro accuracy of CoT" on code-davinci-002 §5.1. The table gives 18.0 vs 6.0, which is three times tab. 3.
    • The text says SC improves micro accuracy "by more than 11 percentage points" §5.1. From the table, the gains are 15.7 (CoT, 72.4 to 88.1), 15.9 (LtM, 77.5 to 93.4), 20.2 (Program, 54.4 to 74.6) and 35.3 (0-CoT, 29.0 to 64.3). The paper says 35.5 for 0-CoT. The "more than 11" figure cannot be reproduced from the table, and the paper gives no other basis.
  • Dev set naming. §3.1 says the 1,000-problem development set was drawn from the GSM8K training set, while later tables report "GSM8K Dev." tab. 5 tab. 6. Which split the dev numbers come from is not stated.
  • Table 5 labels. Two rows are labelled "CoT" and "CoT + Inst." in a way that makes the instruction-without-exemplar and exemplar-without-instruction cases unclear. The values above follow the printed order. Check against a fresh run before relying on them.
  • Single exemplar. The main prompts use one exemplar §4.2. The paper compares against a 4-exemplar prompt taken from another work §5.4; the paper's appendix does not list that prompt, so its exemplars are not given here.
  • Irrelevant sentence can change the answer by use, not just presence. The paper reports that a model can use the irrelevant number in a calculation, or give a wrong answer even without using it §5.1 fig. 3.
  • Cost of SC. The SC results use 20 sampled responses per problem §5. The paper does not report token or time costs. Program prompts also need an external Python execution step §4.1.
  • Model availability. The models are OpenAI API models named by the paper. Their current availability was not checked, and the results are not guaranteed to transfer to other models. The paper does not claim transfer §6.
  • Ambiguous pronouns are fixed by hand. Some inserted sentences made pronouns ambiguous, so the question was reworded app. A. Reproducing the dataset needs the same kind of manual check.
  • Metrics are unnumbered. The micro, macro and normalised formulas are unnumbered in the paper §3.2. Cite them by section.

Pseudocode

Metrics, as pseudocode:

Pseudocode
# Micro accuracy: every test problem weighs the same  [§3.2]
def micro_accuracy(method, test_problems):
    # standard(p) is the standard solution of problem p
    correct = [
        method(problem) == standard(problem)
        for problem in test_problems
    ]
    return sum(correct) / len(test_problems)

# Macro accuracy: a base problem counts only if all its variants are right  [§3.2]
def macro_accuracy(method, variants_by_base):
    # variants_by_base maps each base problem to its derived variants
    solved = [
        all(method(v) == standard(v) for v in variants)
        for variants in variants_by_base.values()
    ]
    return sum(solved) / len(variants_by_base)

# Normalised accuracy divides by the base-problem accuracy  [§3.2] [tab. 2]
def normalised(accuracy, base_accuracy):
    return accuracy / base_accuracy

Self-consistency, as pseudocode:

Pseudocode
# Self-consistency: sample 20 chains at temperature 0.7, then vote  [§5] [§5.1]
def self_consistent_answer(prompt, problem):
    # Sample 20 independent solutions  [§5]
    answers = [
        parse_answer(sample(prompt, problem, temperature=0.7))
        for _ in range(20)
    ]
    # Majority vote; a tie is broken at random among the top answers  [§5.1]
    return vote_with_random_tiebreak(answers)

Prompt assembly, as pseudocode:

Pseudocode
# Few-shot prompt: optional instruction, one exemplar, then the problem  [§4.2] [§4.3]
def build_prompt(exemplar, problem, instructed):
    # The instruction is prepended only in the instructed variant  [§4.3] [app. C]
    header = INSTRUCTION if instructed else ""
    # Exemplar may include the irrelevant sentence or not  [§4.2]
    return header + exemplar + "Q: " + problem + "\nA:"

Lineage

  • Builds on: chain-of-thought prompting §4.1; zero-shot CoT, which uses the trigger phrase §4.1; least-to-most prompting §4.1; program-based prompting, which the paper takes from prior work §4.1; and self-consistency §4.1.
  • Compared against: the same base methods, with and without the instruction and the irrelevant-context exemplar tab. 3.
  • Related prior work on distraction and on DROP is cited in the paper but has no card here §2 §5.5.
  • Superseded by: not stated.

Source and license

Adapted from “Large Language Models Can Be Easily Distracted by Irrelevant Context” by Freda Shi, Xinyun Chen, Kanishka Misra, Nathan Scales, David Dohan, Ed Chi, Nathanael Schärli, Denny Zhou (arXiv:2302.00093), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors.