Large language models process lists with a general filter headLLMs Process Lists With General Filter Heads
Llama-70B's filter heads encode transferable predicates: object class Causality is 0.863, rhyme is 0.041 (Table 1).
- The authors aim to explain whether language models performing list filtering encode predicates as internal representations transferable across lists and languages, rather than relearning a separate approach for each task.
- On six self-constructed filter-reduce tasks, use activation patching and sparse binary masks to localize mid-layer attention heads. Swap the source prompt's last-token query into the target prompt and see whether the model instead selects the item satisfying the source predicate.
- Llama-70B object-class Causality is 0.863, rhyme is 0.041 (Table 1). Question-first cross-transfer is 0.020. After ablation, SelectOne accuracy is 22.5%, CheckExistence is 98.61% (Table 3).
- The authors state in Appendix O that only six tasks and four models were used, templates may bias toward specific strategies, and most causality scores come from a single run of 512 cases. The main cross-language table is on Llama-70B; Gemma-27B replicates the core experiments.
- Evaluated models
- Llama-70B (meta-llama/Llama-3.3-70B-Instruct)Gemma-27B (google/gemma-2-27b-it)Gemma-9B (google/gemma-2-9b-it)Llama-8B (meta-llama/Llama-3.1-8B-Instruct)
- Benchmarks
- SelectOneSelectOne-MCQSelectFirstSelectLastCountingCheckPresenceCheckExistenceSelectOne-Object
- Metrics
- Causality∆logitLM AccuracyProbe Accuracy
The paper uses causal mediation analysis to study the mechanisms by which large language models handle list tasks, finding that a small number of attention heads encode a compact representation of the filtering predicate in the query state of specific tokens; the authors call these attention heads filter heads. The authors claim that this predicate representation is general and portable, and can be extracted and used to perform the same filtering operation on different sets, which may be in different formats, languages, or even different tasks. The paper also finds that Transformer LMs sometimes switch to an alternative strategy, namely judging in advance whether an item satisfies the predicate and storing this intermediate result as a flag directly in the item's representation. The authors argue that this shows Transformer LMs can develop human-interpretable abstract computational implementations, generalizing in ways quite similar to strategies in traditional functional programming.
Paper analysis
What problem does this paper attempt to solve?
The authors claim a small set of mid-layer attention heads encode filtering predicates into transferable query representations.
How language models implement predicate-based list filtering as a context-swappable internal operation, rather than learning a separate heuristic for each task.
- Scenario: The authors use Marr's three-level analysis to look at list processing: computational goal is to select elements satisfying the predicate; algorithmically corresponds to map, filter, reduce. The authors state map (writing semantics into entries) is already in literature; this paper focuses on the subsequent filter.
- Gap in existing work: The authors state existing selection mechanism studies mostly look at labels or option letters in MCQA; attention patterns themselves may not reflect causal effects.
- Core observation: The authors state that a few middle-layer attention heads in Llama-70B encode the predicate in the query at the answer token, and interact with keys carrying entry semantics, thereby attending to items satisfying the predicate.
- Proposed analysis: The authors call these heads filter heads, test whether the representation transfers across lists, formats, languages, and reduce tasks; and describe another eager path that writes an is_match flag into entry hidden states. The authors also use this query as a training-free concept probe.
What related research exists?
Related work covers specialized attention heads, MCQA selection mechanisms, and symbolic reasoning; the authors claim filter heads were not previously identified.
- Specialized attention heads: Induction heads (Olsson et al., 2022) do pattern matching and copying. Feucht et al. (2025) identify heads that copy concepts rather than single tokens. Todd et al. (2024)'s function vector heads encode task representations transferable across contexts. The authors state filter heads belong to this class of functionally specialized heads, and compare causal effects with these head types in experiments.
- LM selection mechanisms: Tulchinskii et al. (2024) identify select-and-copy heads in question-first MCQ that attend to the correct item then newline, based on attention patterns. Lieberum et al. (2023) identify heads that attend to correct MCQ letters, and write that these heads encode option order IDs. Wiegreffe et al. (2025) report middle-layer attention boosts answer symbols in MCQA. The authors state these works focus on MCQA; this paper looks at general list processing.
- Symbolic reasoning: Yang et al. (2025) discuss early layers turning tokens into abstract variables, middle layers doing sequence operations, later layers retrieving values. Meng et al. (2022) and Geva et al. (2023) see similar stages in fact recall; this paper maps map to entry representation writing. Mathematical mechanisms in Nanda et al. (2023), Hanna et al. (2023), Kantamneni and Tegmark (2025); variable binding in Feng and Steinhardt (2024), Prakash et al. (2025). The authors cite Smolensky (1991), stating distributed representations can exhibit symbolic structure in unit interactions.
- Baseline heads and data: Experimental baselines are Function Vector, Concept Induction, Token Induction, and random heads. The authors clarify they are not traditional baselines for filtering tasks, only to confirm functional difference. Task data are six self-constructed filter-reduce sets D_τ. For localizing FV and CI heads, they use public data and code from Todd et al. (2024) and Feucht et al. (2025).
The authors position this paper as "middle-layer specialized heads implement transferable predicate evaluation," and state lazy filter heads and eager flag correspond to two evaluation strategies in functional programming (Henderson and Morris Jr, 1976; Friedman et al., 1976).
How does the paper address this problem?
Use sparse-mask causal mediation to localize filter heads, then test predicate transferability via query swapping.
The authors formalize filtering as selection over a set and a predicate, then use query patching of filter heads to test whether the model actually performs this operation. The main analysis targets Llama-70B (figure captions say 80 layers); Gemma and smaller Llama replications are in the appendix.
Task formalization
- Filtering definition: The authors adopt filter(C,ψ)={c∈ C∣ ψ(c) is True}, i.e., keeping items for which the predicate is true. Prompts state (C, ψ) in natural language, then perform a reduce.
- Six tasks: SelectOne, SelectOne-MCQ, SelectFirst, SelectLast, Counting, CheckPresence (also written CheckExistence in Table 3). Predicate types include object categories, occupations, nationalities, landmark countries, and rhymes.
- Head computation: Head [ℓ, j] projects the previous layer's hidden state into a query and attends to keys of previous tokens. The authors cache queries before rotary position encoding and claim these heads are insensitive to position information, classifying them as semantic heads.
Localizing filter heads
- Single heads are insufficient: Patching source queries into target runs head-by-head, heads are selected by logit difference of ctarg. The authors claim other filter heads and backup mechanisms counteract single-head interventions.
- Sparse mask: Queries of the last token are swapped across all heads with a binary mask, aiming to increase ctarg's logit, suppress other items in the target set, and add an L1 sparsity term. Appendix H states 79 heads are selected on Llama-70B at λ=0.02.
- Scale: 1024 cases are used per task for localization, with swapping only at the last token. Figure 3 gives head counts of 79 for SelectOne, 45 for SelectOne-MCQ, 81 for SelectFirst, 145 for SelectLast, 64 for Counting, and 21 for CheckPresence. Localization does not require the attention pattern of Figure 1 to appear first.
Causality scores
- Pairing: Source and target predicates differ, sets are disjoint, and the target set contains at least one item satisfying the source predicate. Source answer, target answer, and the answer to be selected after patching are mutually distinct. The question-first flag experiment uses the same set instead; see Section 5.
- Judgment: Only the selected heads' queries are patched, checking whether the highest-probability item in the target set is ctarg; this is Causality. ∆logit is the logit difference of ctarg before and after patching.
- Evaluation convention: Reported scores come from 512 cases the model originally answered correctly. Evaluation patches the last two tokens, namely "\nAnswer" and ":". q_src is the average over several runs of the same source prompt with the correct item's position changed; the paper does not give the number n. The authors claim averaging removes order information.
Two paths and probing
- Lazy: When the question follows the items, filter heads match predicate in the query against item semantics in keys. Section 4 then swaps keys of two items to see whether attention follows semantics.
- Eager: When the question precedes the items, the authors hypothesize the model can write an is_match flag as it reads each item, and the final position selects by flag. The test is: patch the residual of the last two tokens in a single layer and implant the flag under another predicate into a third item.
- Probing: For each category, collect filter-head queries, take inner products with the head's key-projected representations, and take the maximum as the category. The authors use head [35, 19] without training an additional probe.
What experiments did the paper conduct?
Llama-70B object category Causality is 0.863; rhyme, question-first, and CheckPresence causality are weak.
Experimental Setup
- Models: Main results on Llama-70B (meta-llama/Llama-3.3-70B-Instruct). Appendix L reproduces Gemma-27B (google/gemma-2-27b-it). Table 5 and Appendix M also include Gemma-9B (google/gemma-2-9b-it) and Llama-8B (meta-llama/Llama-3.1-8B-Instruct).
- Data: Six self-constructed tasks. Baseline accuracy in Table 5 uses 1024 examples from the same draw per task; causal scores mostly use 512 examples the model answered correctly. Localization uses 1024 examples.
- Accuracy without ablation: Llama-70B on Table 5: SelectOne 99.32%, SelectOne-MCQ 98.63%, SelectFirst 78.42%, SelectLast 87.01%, Counting 67.38%, CheckPresence 91.02%.
- Baselines: Function Vector, Concept Induction, Token Induction, and random heads; Table 4 fixes head count to 79 for each type. Ablation baseline is random heads.
- Metrics and criteria: Causality checks whether ctarg becomes the highest-probability item in the target set; also reports ∆logit. Ablation accuracy uses samples that were correct without ablation as 100% baseline. The paper does not use LLM judges; correctness is determined by next token, and requires entries not sharing first token.
- Replication: Appendix O states most causal scores are single trials on random 512 examples. The paper does not report statistical significance tests.
Main Results
The table below is for Llama-70B, SelectOne, filter heads localized with object category, per Table 1. Section 3 states reported scores come from samples the model answered correctly; Table 9 gives /512 for two of those rows.
Semantic Type Causality ∆logit Object Category 0.863 +9.03 Person Profession 0.836 +7.33 Person Nationality 0.504 +5.04 Landmark in Country 0.576 +7.02 Word rhymes with 0.041 +0.65 - The authors state these heads transfer to profession, nationality, and landmark, but rhyme causality is very low, so they participate in semantic filtering, not phonological properties.
- The authors state that after first prompting the model to recall nationality or country, causality improves by about 10 points. Table 9 with prefix results: nationality 0.625 (320/512), landmark 0.670 (343/512).
- The authors state that with 7 distractors in the target list, causality remains near 0.8 (Figure 2); text does not give exact values for each point. In Appendix P, the authors also state that on letter counting and alphabetical order tasks, the aggregated attention of the same 79 heads does not align with items satisfying the condition; this is an attention visualization, not Causality.
Cross-Language, Format, and Tasks
- Table 2: Causality for English predicates transferring to Thai is 0.951, to French is 0.779. Single-line format to bullet points is 0.842. Question-last to question-first is 0.580, question-first mutual transfer is 0.020, question-first to question-last is 0.398. The authors state representations remain abstract under surface form changes, but question-first more often uses another implementation.
- Figure 3(a): SelectOne heads on own task 0.86, transfer to SelectLast 0.78, to Counting 0.04, to CheckPresence 0.02. Counting heads on own task 0.36, transfer to SelectOne 0.61. CheckPresence heads on own task 0.09. The authors state causality among the four Select tasks is not below 70%, excluding SelectOne-MCQ; in the figure, SelectOne to SelectFirst is 0.69, SelectOne-MCQ to SelectOne, SelectFirst, SelectLast are 0.59, 0.27, 0.44.
- Figure 3(b): SelectOne query to Counting is 0.06, to SelectFirst is 0.60. SelectFirst to SelectLast is 0.28, SelectLast to SelectFirst is 0.17. The authors believe that in the query of these two tasks, the predicate may be entangled with task information.
Ablation, Key, and Question-First
- Table 3: On 512 originally correct samples, ablating filter heads gives SelectOne 22.5%, SelectOne-MCQ 0.4%, SelectFirst 13.1%, SelectLast 9.22%; random ablation gives 99.6%, 100%, 97.3%, 99.4%. Counting is 89.80% (random 99.19%), CheckExistence is 98.61% (random 99.2%). The authors state Select* tasks depend on these heads, which are less than 2% of all heads; the latter two tasks do not fully depend on them.
- Table 4 and Appendix K: With the same 79 heads, Function Vector Causality is 0.002, Concept Induction is 0.080, Token Induction is 0.00, random is 0.00. Ablating FV gives accuracy 88.3%, ablating CI gives 98.2% (Table 12). The authors state these heads are functionally different from filter heads; FV and filter heads are both more common in middle layers, but only 7 of the 79 heads overlap.
- Key and flag: On single-token entries, patching query and swapping keys of two entries gives Causality 0.783 (432/552), ∆logit 8.2591±3.352. The authors state the key carries the semantics being checked. In question-first, the authors state early-to-middle layers select the entry with the implanted flag (Figures 5, 11). After erasing the flag, question-first accuracy is 46.09%, question-last is 96.06% (Table 8, 512 examples).
Other Ablations and Analyses
- When source list has no valid answer, Causality remains 0.80 (410/512, ∆ctarg=8.08±3.1, Appendix E).
- Summing queries of two predicates: Appendix D gives 0.6523 (334/512), logit increase 6.75±3.94; main text says 0.65.
- Patching only the last token gives object category Causality 0.819 (839/1024), lower than the two-token setting's 0.863 (Appendix H).
- After position-averaging the query, SelectOne goes from 0.79 to 0.86 (Figure 15, 512 examples); the authors state improvement of 7 to 10 points. The 79 heads selected by FilterScore, per-head patching, and masked patching have collective causality 0.67, 0.59, 0.86 (Figure 12).
- Head [35, 19] has probe accuracy 0.81±0.02 on 238 objects, 16 categories (Figure 6). The figure has Logit Lens Baseline; text does not give that baseline value.
- Gemma-27B object category Causality is 0.824, rhyme is 0.018 (Table 13). Llama-8B object category is 0.826 (423/512); Appendix M title says 47 heads, table header says 39, paper does not reconcile. The authors state smaller models generalize slightly worse across tasks, hypothesizing head reuse under parameter constraints; Figure 24 cell values not given in text.
What are some points that can be further explored?
The authors state they only examine six tasks and four models, and most causality scores come from a single run of 512 cases.
Limitations and future directions noted by the authors
- Task scope (Appendix O): Only six filter-reduce tasks are examined. The authors state that filter heads show low causality on CheckPresence, indicating some filtering uses alternative mechanisms; fixed prompt templates may bias experiments toward specific computational strategies.
- Model scope (Appendix O): Filter heads are localized in Llama-70B, Llama-8B, Gemma-27B, and Gemma-9B. The authors claim other model families may not use such heads; in smaller models, predicate representations may be entangled with other information, obscuring this head-level causal role.
- Next-token constraint (Appendix O): Correctness is judged by the next token, requiring items not to share a first token, and source answer, target answer, and transferred answer to be mutually distinct. The authors claim this limits exploration of other filter-reduce tasks.
- Single sampling (Appendix O): Most causality scores come from a single trial of 512 random cases. The authors claim scores may vary slightly with a different sample.
Experimental coverage
- Models analyzed are Llama-70B, Gemma-27B, Gemma-9B, and Llama-8B. Main-text causality tables focus on Llama-70B; language, format, and question-position replication tables are in Appendix L, targeting Gemma-27B.
- Tasks are SelectOne, SelectOne-MCQ, SelectFirst, SelectLast, Counting, and CheckPresence/CheckExistence. Semantic types include objects, occupations, nationalities, landmark countries, and rhymes.
- Languages are English, Spanish, French, Hindi, and Thai. Formats include single-line, bulleted, question-first, and question-last.
- Interventions include filter-head ablation, random-head ablation, Function Vector, Concept Induction, Token Induction, as well as key swapping, flag implantation, and probing of head [35, 19].
- Localization uses 1024 cases; main causality scores are mostly on the 512 correctly answered cases. The paper does not report replication counts for these causality scores; Appendix O states most are single-run; the paper reports no statistical tests. Llama-8B head counts are inconsistent between the Appendix M title and table header.
Summarize the main content of the paper
The authors state that middle-layer filter heads implement transferable semantic filtering, alongside an eager flag path.
The authors localize a set of mid-layer filter heads in list filtering of autoregressive transformers and test whether their predicate representations transfer across contexts.
- Problem: List tasks first select items by a predicate, then reduce. The authors ask whether this is a reusable filtering operation or a per-task heuristic.
- Method: They patch the query of the last token between source/target prompts with different predicates and disjoint lists, using a sparse mask to find heads that jointly matter. Causality is defined as whether the highest-probability item in the target list becomes the one satisfying the source predicate.
- Semantics and language: On Llama-70B SelectOne, object-class Causality is 0.863, occupation is 0.836, rhyme is 0.041 (Table 1). English predicates transfer to Thai at 0.951; question-first cross-transfer is 0.020 (Table 2).
- Tasks and ablation: SelectOne heads transfer to Counting with Causality 0.04, CheckPresence heads in their own task give 0.09 (Figure 3a). After ablation, among the 512 originally correct cases, SelectOne accuracy is 22.5%, CheckExistence remains 98.61% (Table 3).
- Authors' conclusion: The authors claim these heads encode predicates as directions in the query, transferable across lists, formats, and languages, and shared across some reduce tasks. When information allows, the model also writes an is_match flag into item hidden states. The authors map the two paths to lazy and eager evaluation and claim some computational patterns arise from task demands rather than being purely architecture-determined.