Induction Meets Biology: Mechanisms of Repeat Detection in Protein Language Models
Organizations: Technion - Israel Institute of Technology · The Hebrew University of Jerusalem, Israel · Kempner Institute, Harvard University
Abstract
Protein sequences are abundant in repeating segments, both as exact copies and as approximate segments with mutations. These repeats are important for protein structure and function, motivating decades of algorithmic work on repeat identification. Recent work has shown that protein language models (PLMs) identify repeats, by examining their behavior in masked-token prediction. To elucidate their internal mechanisms, we investigate how PLMs detect both exact and approximate repeats. We find that the mechanism for approximate repeats functionally subsumes that of exact repeats. We then characterize this mechanism, revealing two main stages: PLMs first build feature representations using both general positional attention heads and biologically specialized components, such as neurons that encode amino-acid similarity. Then, induction heads attend to aligned tokens across repeated segments, promoting the correct answer. Our results reveal how PLMs solve this biological task by combining language-based pattern matching with specialized biological knowledge, thereby establishing a basis for studying more complex evolutionary processes in PLMs.
Figures & tables
| Model | Synthetic | Identical | Approximate |
| ESM-3 | 99.8% | 99.0% | 79.0% |
| ESM-C | 99.9% | 99.4% | 79.7% |
| Feature | Description |
| Induction score | Pattern-matching and copying across aligned repeats. |
| Relative position | Consistent attention at fixed offsets. |
| Amino acid bias | Selectivity for specific amino acids. |
| Repeat focus score | Sharper attention to repeat regions. |
| Attention sharpness | Attention distribution concentration. |
| Boundary attention | Attention to boundary tokens. |
Appendix figures & tables35 assets
Supplementary material from the paper’s appendix.
Appendix
| Task | Masked Input | Repeat Alignment | Eligible mask positions |
| Synthetic | ...NFDIQREHYKTEWYN... ...NFDI_REHYKTEWYN... | NFDIQREHYKTEWHRYN ||||||||||||||||| NFDIQREHYKTEWHRYN | All positions |
| Identical | ...MKTAYIAKQRQISFVHFS... ...MKTA_IAKQRQISFVHFS... | MKTAYIAKQRQISFVKSHFS |||||||||||||||||||| MKTAYIAKQRQISFVKSHFS | All positions |
| Approximate (Substitution-Adjacent) | ...PYTSAVTQTR... ...PYRA_VTQTR... | PYTSAVTQTR ||..|||||| PYRAAVTQTR | Identical positions adjacent to substitutions (Y, A in example) |
| Approximate (Indel-Adjacent) | ...GNAASATKLQTSR... ...GNAASAT_ATQDSR... | GNAASATK-LQTSR |||||||| | .|.|| GNAASATKATQDSR | Identical positions adjacent to gaps (K in example) |
| Model | Subst. rate | Repeat length | ||||
| 1–10 | 11–15 | 16–20 | 21–25 | 26+ | ||
| ESM-3 | – | |||||
| – | ||||||
| ESM-C | – | |||||
| – | ||||||
| Counterfactual Type | Input Example |
| Original Input | ...RLRHQLSFYG _ PFALG...KLRHQLSFYGVAFALG... |
| 100% BLOSUM (Chosen Strategy) | ...RLRHQLSFYG _ PFALG... RIKYEIAYFAISYSIA ... |
| Permutation | ...RLRHQLSFYG _ PFALG... QLFHYGARFLKLSAVG ... |
| 100% BLOSUM Opposite | ...RLRHQLSFYG _ PFALG... CDCCCDWPDIRWPWDI ... |
| 100% Mask | ...RLRHQLSFYG _ PFALG... ______________ ... |
| 50% BLOSUM | ...RLRHQLSFYG _ PFALG...KLRHQ IAYF G ISY AL A ... |
| Feature | Formal Definition | Description |
|---|---|---|
| Induction Score | Measures induction-like behavior following prior work on decoder-only models ( Olsson et al., 2022 ; Ren et al., 2024 ; Bansal et al., 2023 ) , which defines induction behavior as the combination of pattern-matching and copying. The Copying score quantifies whether the head promotes the token it attends to most strongly at the masked position, while the Pattern Matching component measures attention between aligned tokens across the two repeat instances. Both scores are first computed at the per-sequence level and averaged across all sequences. The Induction Score is then defined as the mean of these two aggregated quantities, yielding a single score per head. This score is motivated by manual inspection of attention patterns that closely resemble induction behavior previously identified in large language models. | |
| Relative Position Score | For each sequence and query position , denotes the normalized relative offset between the query and the key position receiving maximal attention from head . The per-sequence score is computed as the standard deviation of across query tokens, with denoting the mean offset. Offsets are normalized by the sequence length to allow comparison across sequences of different lengths, and BOS/EOS positions are excluded as queries. The final score is obtained by averaging over the dataset and inverting it ( ), so that higher values indicate heads that attend to a more consistent relative position. This metric is motivated by qualitative observations of heads attending to fixed relative offsets (e.g., tokens). | |
| Attn. Amino-Acid Bias | For each amino acid , we compute the average attention mass that head assigns from sequence-token queries to all key positions containing , and average this quantity across the dataset, yielding one feature per amino acid. These features are normalized to form an amino-acid attention distribution for each head, which is compared to the dataset amino-acid frequency distribution using Jensen–Shannon divergence. This score is motivated by qualitative observations of attention patterns, including global amino-acid biases, where a head broadly attends to all occurrences of a subset of amino acids, as well as more localized, motif-like patterns, where attention is concentrated on specific amino acids at particular positions. | |
| Repeat Focus | Measures how differently head behaves when the query comes from a repeat segment compared to non-repeat regions, by partitioning query positions into repeat queries and non-repeat queries . For each query, the maximum attention peak across keys is computed and averaged separately over the two sets. The logarithm of their ratio centers the measure at zero: positive values indicate sharper focus on repeat queries, negative values indicate sharper focus on non-repeat queries, and values near zero indicate similar behavior across regions. The score is computed per sequence and averaged across all sequences in the dataset. This score is motivated by manual observations that, beyond induction heads, additional heads tend to exhibit stronger activation for repeat queries. | |
| Attention to BOS/EOS | Measures the average attention weight that head assigns from sequence-token query positions to the sequence-boundary positions corresponding to the beginning of the sequence (BOS) and the end of the sequence (EOS). Throughout, positions and denote the BOS and EOS boundary positions, respectively. Both scores are computed at the per-example level and averaged across all sequences. This metric is motivated by manual inspection of attention patterns, where we observed several heads that attend to boundary positions in a subset of proteins examined qualitatively. Prior work suggests that attention to sequence-boundary positions can be associated with “no-op” behavior or approximate if–else mechanisms, in which heads default to boundary positions when no salient pattern is detected ( Clark et al., 2019 ; Vig and Belinkov, 2019 ; Barbero et al., 2025 ) . | |
| Attention Entropy | Computes the average normalized Shannon entropy of the attention distribution of head over sequence-token queries, excluding BOS/EOS as queries but including them as keys. For each query, entropy is normalized by , corresponding to the tokenized sequence length, yielding values in and enabling comparison across sequences of different lengths. The score is averaged across all sequences in the dataset. High entropy indicates that the head spreads attention broadly across many tokens, while low entropy indicates that the head focuses attention sharply on a few tokens. This metric is motivated by empirical observations that relative-position and induction heads typically exhibit lower entropy than other heads, making attention entropy useful for separating distinct head behaviors. |
| Cluster | Heads |
| a0.h7, a0.h17, a3.h9, a3.h12, a3.h14, a5.h1, a5.h14, a5.h21, a7.h19, a7.h21, a8.h9, a9.h15, a9.h17, a15.h10, a22.h2, a22.h9, a22.h10, a22.h13, a24.h9, a25.h13, a25.h14, a25.h16, a26.h0, a26.h2, a27.h7, a27.h11, a27.h12, a27.h13, a28.h10, a28.h11, a30.h2, a30.h22, a30.h23, a31.h9, a32.h4, a32.h14, a32.h21, a34.h23, a35.h1, a35.h3, a35.h20, a36.h2, a36.h3, a36.h4, a36.h9, a36.h10, a36.h15, a36.h20, a37.h0, a37.h2, a37.h4, a37.h9, a37.h19, a39.h7, a39.h8, a39.h13, a39.h15, a39.h17, a39.h22, a40.h1, a40.h8, a40.h13, a40.h19, a40.h21, a41.h2, a41.h3, a41.h7, a41.h8, a41.h14, a41.h20, a43.h2, a43.h3, a43.h4, a44.h1, a44.h2, a44.h9, a44.h11, a44.h16, a44.h18, a45.h0, a45.h3, a45.h4, a45.h17, a45.h23, a46.h1, a46.h2, a46.h3, a46.h4, a46.h8, a46.h16, a47.h5, a47.h8, a47.h10, a47.h12, a47.h14, a47.h15, a47.h17, a47.h21, a47.h22 | |
| a23.h5, a23.h23, a28.h13, a29.h1, a38.h10, a38.h22, a42.h5 | |
| a0.h4, a24.h16, a24.h19, a25.h23, a26.h19, a27.h5, a31.h8, a31.h17, a33.h23, a34.h9, a35.h10, a35.h21, a37.h8, a37.h10, a37.h15, a38.h0, a38.h18, a39.h3, a39.h6, a39.h10, a40.h7, a40.h11, a40.h16, a40.h17, a40.h22, a41.h13, a41.h17, a42.h10, a45.h2, a45.h6, a45.h9, a45.h10, a45.h16, a46.h10, a46.h17, a46.h22, a47.h2, a47.h3, a47.h6, a47.h7, a47.h18, a47.h19, a47.h20 |
| Cluster | Heads |
| a0.h7, a0.h15, a0.h16, a0.h17, a1.h3, a1.h10, a7.h1, a7.h7, a8.h6, a8.h16, a9.h3, a9.h9, a10.h7, a10.h8, a11.h8, a14.h5, a15.h0, a15.h2, a15.h9, a15.h10, a15.h15, a15.h17, a16.h2, a16.h5, a16.h12, a16.h13, a17.h0, a18.h2, a18.h6, a18.h8, a18.h9, a18.h13, a18.h14, a18.h17, a19.h7, a20.h1, a20.h6, a20.h13, a21.h6, a22.h8, a22.h10, a22.h12, a23.h13, a23.h15, a24.h0, a24.h1, a24.h2, a24.h3, a24.h10, a25.h16, a26.h1, a27.h1, a27.h16, a29.h12, a29.h15, a34.h0, a34.h9, a35.h0, a35.h3, a35.h10, a35.h11, a35.h12 | |
| a12.h2, a13.h5, a17.h4, a17.h12, a19.h8, a19.h14, a19.h16, a21.h0, a28.h3, a29.h13, a30.h12, a35.h16 | |
| a4.h14, a13.h12, a14.h17, a16.h3, a16.h11, a17.h2, a17.h8, a18.h16, a20.h7, a21.h14, a25.h12, a26.h2, a26.h16, a27.h0, a28.h17, a29.h5, a29.h10, a30.h15, a33.h10, a34.h8, a34.h11, a34.h15, a35.h1, a35.h2, a35.h5, a35.h13, a35.h15, a35.h17 |
| Cluster | Size | Induction | Rel. Pos. | AA Bias | Attn. BOS/EOS | Entropy | Residual Contr. | Vocab. Entropy | Context Sens. | Repeat Focus |
| 99 | ||||||||||
| 7 | ||||||||||
| 43 |
| Cluster | Size | Induction | Rel. Pos. | AA Bias | Attn. BOS/EOS | Entropy | Residual Contr. | Vocab. Entropy | Context Sens. | Repeat Focus |
| 62 | ||||||||||
| 12 | ||||||||||
| 28 |
| Model | Head | Repeat Focus | Cluster |
| ESM-3 | a26.h19 | 0.701 | |
| ESM-3 | a24.h16 | 0.628 | |
| ESM-3 | a27.h5 | 0.618 | |
| ESM-3 | a46.h22 | 0.565 | |
| ESM-3 | a31.h8 | 0.562 | |
| ESM-3 | a38.h0 | 0.541 |
| Concept / Concept Group | Description |
|---|---|
| Repeat Tokens | We define a repeat-based concept. A token belongs to this concept if it appears within a repeated segment in one of the repeats present in the dataset. |
| Aligned Repeat Token to Mask Position | We define an alignment-based concept. A token belongs to this concept if it is aligned to the masked position, i.e., the token from which the model is expected to retrieve information to predict the masked token. This concept is motivated by manual inspection, which revealed consistent neuron patterns targeting this aligned position across multiple proteins. |
| Amino Acid Identity | We define amino-acid–based concepts by assigning a distinct concept to each of the 20 standard amino acids. A token is assigned to a concept if it represents that specific amino acid. This corresponds to a total of 20 concepts. |
| BLOSUM62-Based Concepts | We construct groups of substitutable amino acids using the BLOSUM62 substitution matrix ( Henikoff and Henikoff, 1992 ) . We view the matrix as a weighted graph over amino acids and identify cliques in which all pairwise substitution scores are greater than or equal to zero, corresponding to substitutions that are neutral or favorable. Each such clique is treated as a distinct concept. This procedure yields a total of 110 BLOSUM-based concepts. Although many of these cliques overlap, this does not pose an issue for our analysis, since each neuron is assigned to the best-matching concept according to its AUROC score. |
| Polarity (IMGT) | We define two polarity-based concepts according to the IMGT classification: polar and non-polar . A token is assigned to one of these concepts based on the polarity of the amino acid it represents. |
| Hydropathy (IMGT) | We define three hydropathy-based concepts according to the IMGT classification: hydrophobic , neutral , and hydrophilic . A token is assigned to one of these concepts based on the hydropathy class of the amino acid it represents. |
Protein Language Models
Protein language models learn patterns in amino-acid sequences to predict protein properties, interpret mutations, and design new proteins.
See all 69 papers