Supporting Information
Supporting Results
Lattice protein corpus and data splits
We use lattice proteins [26] to test whether models can recover fitness effects and predict evolutionary substitutions in a system with known fitness landscapes and evolutionary histories. Each protein consists of 18 amino acids encoded by a 54-nucleotide DNA sequence and folds as a self-avoiding walk on a two-dimensional square lattice (Figure S1). Non-bonded residues at adjacent lattice positions interact through amino-acid-specific contact energies [68]. These energies determine the Boltzmann distribution over conformations, with the lowest-energy conformation defining the native fold. We define fitness as the frequency of the protein in its native fold multiplied by the negative binding energy of that fold to the ligand [27]. High fitness thus requires both stable folding and favorable binding.

Figure S1. Lattice proteins as a synthetic system with a known fitness landscape. Each sequence folds as a self-avoiding walk on a two-dimensional square lattice. Residues are colored by class (hydrophobic, polar, charged) and interact through contacts between lattice-adjacent, non-bonded positions. Panels show representative conformations drawn from the Boltzmann ensemble at temperature , with the target ligand (purple) held fixed. Fitness combines fold stability and ligand binding as , where is the equilibrium fraction of the ensemble in the native (lowest-energy) fold and is the negative binding energy of that native fold to the ligand.
We evolve these proteins at the DNA level under origin-fixation dynamics, where mutations arise rarely enough that each fixes or is lost before the next appears [9]. At each step, we evaluate the fitness effects of all single-nucleotide mutations and sample the next substitution in proportion to its mutation rate and Kimura fixation probability [8], which depends on its fitness effect and the effective population size. Synonymous mutations are neutral and mutations introducing stop codons are lethal. We generate distinct fitness landscapes for 1000 ligands, divided equally between simple four-residue ligands and more complex bent shapes. We vary mutation spectra and effective population sizes among ligands and generate both independent evolutionary trajectories and branching phylogenies on each landscape.
We evaluate models by predicting the next substitution, scoring information gain relative to a uniform baseline and top-10% recall as the fraction of realized substitutions in the model's top 10% of candidates. Because lattice protein fitness is exactly computable, we also measure the Spearman correlation between the model's fitness ranking and the true fitness ranking of nonsynonymous mutations. We evaluate each metric on the training sequences themselves, unseen clades from the training trees, independent trajectories on training landscapes and entirely new ligands, a progression of increasing distribution shift (Figure S2).

Figure S2. Lattice protein evaluation uses increasing levels of held-out data. Within a training landscape (defined by one ligand), train is the parent sequences and substitutions the model saw, held-out clade is unseen branches of the same phylogenetic tree, held-out trajectory is independent evolutionary walks on the same landscape, and held-out ligand uses branches and trajectories for an entirely new landscape.
Sequence frequencies at equilibrium
Protein language models are commonly trained by masked language modeling (MLM), predicting masked amino acid residues from the surrounding sequence [13]. Models trained with this objective predict mutational effects measured by deep mutational scanning, with Spearman rank correlations of approximately 0.4 in the ProteinGym benchmark [14]. Here, we describe the population genetic basis for this objective, which holds for sequences sampled at equilibrium on a fixed fitness landscape, and test it on synthetic lattice proteins.
We consider a haploid population evolving on a constant fitness landscape in the weak mutation regime, where substitutions occur one at a time. The success of each mutation depends on its selective effect scaled by effective population size to yield . This gives the Kimura fixation probability relative to the neutral rate [8],
To isolate selection, we assume a reversible mutation process with a uniform reference distribution over amino acid sequences.
At stationarity, the probability of finding the population fixed for sequence at a randomly sampled time is
where is its fitness, is the haploid effective population size and under the haploid Kimura convention used here [22]. For large populations, and we write in the following. This is a statistical energy function with inverse temperature , where large populations concentrate on fitness peaks and small populations are more dispersed by drift.
At a site , we compare variant and reference with fitness difference while holding the remaining sequence fixed (Figure S3). Detailed balance of the fixation chain, with , gives the equilibrium log-odds
Thus equilibrium log-odds measures the scaled selection coefficient [21]. Because the comparison holds the rest of the sequence fixed, it includes the effects of epistasis.

Figure S3. Equilibrium residue frequencies encode fitness differences. For a fixed sequence context, log-frequency odds gives the scaled selection coefficient.
Masked language modeling
The stationary relationship described above motivates masked language modeling as a training objective [13]. We mask residue positions in a protein sequence and train a model with parameters to reconstruct them from a corrupted input . The masked cross-entropy loss is
averaged over sequences and choices of . With the residue at site masked, the model gives the probability of each amino acid at that site given the rest of the sequence (Figure S4). Because evolved sequences are draws from , this estimates and the masked log-odds
is proportional to the scaled selection coefficient of the residue change that induces. The standard MLM / pLM log-odds is a selection coefficient. A perfectly calibrated model would give exactly. In practice, neural classifiers are often miscalibrated [69], so tracks only up to an unknown overall scale.

Figure S4. A masked model reconstructs a masked residue from its context, estimating the site-conditional frequency . Its log-odds against the reference residue is .
Masked log-odds require a separate forward pass for each site. We score every candidate from a single forward pass over the unmasked sequence, using the wildtype-marginal log-odds of the main text,
which performs nearly as well on deep mutational scanning [13]. We use this readout for every model here, including pure masked language modeling.
Converting log-odds to substitution probability
We convert model log-odds into fixation probabilities and normalize across candidate mutations (Figure S5). We introduce a single positive scalar to calibrate the overall scale of these estimates . Each candidate is then weighted by its fixation probability and these weights are normalized over the potential mutations,
Beneficial mutations receive weights greater than 1, deleterious mutations receive weights less than 1, and synonymous changes have and . Under weak selection (), and enter only through their product , so calibrates the model's estimate of this combined quantity.

Figure S5. The readout maps the language model's log-odds with arbitrary scale to , applies the Kimura tilt and normalizes to a distribution over candidate substitutions.
When the training corpus represents the stationary distribution on a fixed landscape, the masked conditionals provide estimates of scaled selection. To test this approach on lattice proteins, we train a small transformer with 4.9 million parameters from scratch by masked language modeling alone (see Supporting Methods). This objective never sees , so after training we fit it as the single value that maximizes the probability assigns to the training substitutions.
Thinning the training corpus
Closely related sequences share inherited residue patterns, and densely sampled lineages give these patterns greater weight in the training loss. To reduce redundancy, protein language model training commonly clusters sequences by protein identity and samples representatives from the clusters [13]. Without thinning, phylogenetic happenstance in covariance across sites can masquerade as epistatic relationships. We find that this thinning improves generalization of fitness prediction in the lattice system when training solely with the MLM objective (Figure S6). Notably, performance for held-out clades declines with thinning, while performance for held-out trajectories improves with modest thinning. We select thinning at 94% identity for our MLM model, the threshold with the highest nonsynonymous Spearman correlation on held-out trajectories.

Figure S6. Thinning the training corpus improves generalization of fitness prediction from masked language modeling. Performance of models trained solely by masked language modeling as a function of the protein-identity threshold used to thin the training corpus. The x-axis ranges from the unthinned corpus to representatives clustered at 50% identity. Panels show information gain over a uniform baseline, top-10% recall and Spearman correlation between model log-odds and true selective effects. Points show means over training seeds, with error bars giving s.d. Controls switch between showing combined, simple or complex ligands, and between showing nonsynonymous or all substitutions.
Next-substitution prediction
Thinning reduces redundancy, but does not ensure that the remaining sequences represent equilibrium. Lineages sampled during adaptation or following a change in environment need not have reached their stationary distribution. We instead train the model to predict the observed transitions between sequences (Figure S7). In the lattice trajectories and trees, each training transition consists of a parent DNA sequence and the single-nucleotide substitution producing its child. The entire parent protein remains visible, and a single unmasked forward pass supplies the wildtype-marginal log-odds for every candidate amino acid change. Under this objective, is trained directly against observed substitutions rather than standing in for masked log-odds. We gather the scores for the single-nucleotide neighbors of , apply the same fixation weights and normalize jointly over candidate positions and replacements.

Figure S7. Learning scaled selection coefficients from realized substitutions. Wildtype-marginal scores of potential single-nucleotide mutations produce estimates of scaled selection coefficient . These estimates are then converted into fixation probabilities and normalized to score realized substitutions.
The substitution cross-entropy loss is
averaged over observed transitions. Synonymous events remain in the loss, with their selective effects fixed at zero. Gradients pass through the fixation weights and their normalization into the protein language model and the global calibration parameter . This objective fits the conditional probability of a substitution given its parent, so it does not require parent sequences to be sampled at equilibrium. The supervision comes from observed sequence changes, without requiring fitness measurements as training labels.
Nucleotide mutation rates are unequal and can vary across sequence backgrounds. DASM [16] accounts for mutation bias using a fixed nucleotide mutation model fitted to out-of-frame antibody sequences, alongside a learned amino acid selection model. Similarly, we use a separate nucleotide encoder with parameters to predict a parent-specific spectrum of relative rates for the 12 directed nucleotide changes. These mutation weights multiply the fixation weights, so that the probability of the next substitution is proportional to . We train both components jointly, using synonymous changes to anchor the mutation spectrum and nonsynonymous changes to learn selective effects through the protein model.
Co-training masked language and next-substitution objectives
We next test whether combining residue reconstruction and substitution prediction improves performance. Both objectives train the same protein model, with their relative weights controlled by so that
Here, gives pure masked language modeling and gives pure substitution training.
With the MLM corpus thinned at 94%, we find clear evidence that training on substitution signal improves task performance over pure masked language modeling for both held-out clades and held-out trajectories (Figure S8). However, we find that intermediate weights give higher information gain, higher top-10% recall and higher Spearman correlation than pure substitution training as well. Information gain plateaus between and , while Spearman correlation peaks at and declines as the substitution weight increases further. We use in subsequent experiments to balance information gain against Spearman correlation.

Figure S8. Co-training improves next-substitution prediction. Performance as a function of the substitution weight in the combined objective , where is pure masked language modeling and is pure substitution training. The training corpus is thinned at 94%. Panels show information gain over a uniform baseline, top-10% recall and nonsynonymous fitness Spearman. Points show means over training seeds, with error bars giving s.d. Controls switch between showing combined, simple or complex ligands, and between showing nonsynonymous or all substitutions.
We then repeat the thinning experiment under co-training at (Figure S9). Here we thin the sequences used for MLM while retaining the full set of substitution training examples. Performance is less sensitive to thinning than under pure MLM, and co-training on the unthinned corpus outperforms the best-thinned MLM on the held-out evaluations. For held-out clades, nonsynonymous information gain is 1.88 under co-training on the unthinned corpus, compared with 1.18 for the best MLM. Similarly for held-out trajectories, nonsynonymous information gain is 1.11 under co-training and 0.72 under MLM.

Figure S9. Co-training reduces the dependence on corpus thinning. Performance across the protein-identity thresholds in Figure S6, comparing pure masked language modeling () with co-training at . The MLM sequence corpus is thinned, while the substitution training examples are retained in full. Panels show information gain over a uniform baseline, top-10% recall and nonsynonymous fitness Spearman. Points show means over training seeds, with error bars giving s.d. Controls switch between showing combined, simple or complex ligands, and between showing nonsynonymous or all substitutions.
Scaling with data and model size
We repeat model training and evaluation on nested subsets of 50 to 950 training ligands and with smaller (0.85M) and larger (26M parameter) transformer models (Figure S10). The 4.9M parameter model is largely sufficient for the full 17.1M substitution / 950 ligand corpus. At 950 ligands, the 26M model adds 0.06 nats of nonsynonymous information gain on held-out trajectories and ligands, while the 0.85M model falls 0.11–0.13 nats short. Performance scales log-linearly with corpus size, with each doubling of training ligands adding 0.11–0.16 nats of nonsynonymous information gain on held-out trajectories and ligands, more for larger models. The 26M model shows no sign of saturating by 950 ligands, while the 0.85M and 4.9M models begin to level off over the last doubling. Held-out clades are the exception, rewarding capacity to retain each training landscape in detail. With a fixed number of training steps, the 0.85M model loses ground beyond 200 ligands and the 4.9M model peaks at 476 ligands, while the 26M model continues to improve.

Figure S10. Scaling of model performance with training data and model size at fixed compute. Held-out performance of the co-training runs as a function of the number of training ligands and model size measured as parameter count. Training ligands are nested subsets scaling from 50 to 950, where 950 ligands represents 4.9M distinct amino acid sequences and 17.1M realized DNA substitutions. Every training stage runs for the same number of steps at each ligand count, and each run is scored at its best-validation checkpoint. Held-out clades and trajectories are evaluated on the 50 ligands shared by every subset. Held-out ligands are evaluated on 50 ligands never seen during training. Panels show information gain over a uniform baseline and Spearman correlation to true fitness of nonsynonymous mutations. Points show means over training seeds, with error bars giving s.d. Controls switch between evaluation groups and between showing nonsynonymous or all substitutions.
Modeling adaptive trajectories
The lattice protein simulations start from a random initial sequence and then climb towards a high fitness conformation over the course of 100 steps, with most of the climb completed within the first 30 to 50 steps (Figure S11). We compare selective effects, dN/dS and the ranking of mutations between an oracle that knows the true landscape and the trained model. Initial substitutions are strongly beneficial and level off to slightly beneficial with median of 1.3 by step 70. Expected dN/dS starts well above 1, falls below 1 at step 24 as evolution shifts from adaptation to purifying selection, and declines below 0.1 by step 70. The model shows the same dynamics, placing the dN/dS crossing at step 16, but its early estimates of and dN/dS are attenuated toward neutrality. Early in the climb the model lacks information about the target ligand and this only emerges organically as evolution refines the sequence towards its target as demonstrated by the rising Spearman correlation.

Figure S11. Selection along lineages climbing to a fitness peak. Each lattice protein lineage starts from a random sequence and evolves to bind to a fixed ligand. At each step, we summarize substitutions that occurred, including scaled selection coefficient of nonsynonymous substitutions (left), expected dN/dS based on distribution of selective effects (middle) and the mean Spearman correlation between the model's and the true fitness effects across each sequence's nonsynonymous mutations (right). Black lines show an oracle that knows the exact folded fitness landscape, the mutation spectrum and the fixation law. Blue lines show the co-trained model from above (4.9M parameters, MLM corpus thinned at 94% identity), with bands giving s.d. over three training seeds. Each step pools 8 lineages per ligand over 50 ligands per evaluation group. Controls switch between evaluation groups.
Supporting Methods
Lattice protein folding
The folding and evolutionary models follow the lattice protein literature [26, 27]. Each protein folds in the presence of a fixed ligand, a short chain of amino acids occupying sites of the same lattice [70, 71]. The protein's first residue is fixed at the origin, directly above the ligand, so binding depends on the shape of the fold rather than on diffusion. A conformation's energy sums Miyazawa-Jernigan contact energies [68] over pairs of non-bonded protein residues on adjacent lattice sites, and over protein residues adjacent to ligand residues.
We enumerated every self-avoiding walk of the 18-residue chain that avoids the ligand's sites, from 22.6 to 28.5 million conformations depending on the ligand's shape. The native fold is the lowest-energy conformation, and is its share of the Boltzmann ensemble, where sums over all conformations. Conformations with fewer than four contacts within the protein, about 77% of the total, enter through a mean-field approximation [72]. Fitness is , where the binding energy sums the contact energies between the native fold and the ligand.
Each of the 1000 ligands defines its own fitness landscape, and each has an amino acid sequence drawn uniformly at random. The 500 simple ligands are straight chains of four residues in the row beneath the protein's first residue. The 500 complex ligands, 125 of four residues and 375 of six, take shapes drawn at random from all lattice walks of their length, placed with their widest row directly beneath the protein's first residue.
Lattice protein evolution
Proteins evolve at the DNA level under origin-fixation dynamics [9]. At each step, we evaluate all 162 single-nucleotide mutations of the 54-nucleotide sequence, each with selection coefficient . Mutations to stop codons are lethal. A mutation fixes with the haploid Kimura probability [8]
which tends to as , so synonymous mutations fix at the neutral rate and neutral dN/dS is 1. For small , with . The next substitution is drawn in proportion to , where is the relative rate of the mutation's type of nucleotide change.
Each ligand has its own effective population size and mutation spectrum, drawn independently of its landscape. is drawn uniformly from . The spectrum gives relative rates for the 12 directed nucleotide changes, built to resemble bacterial mutation spectra. Transitions exceed transversions by a factor drawn log-uniformly between 2 and 9, changes from G or C to A or T are elevated by a factor between 1 and 4, changes from C and from G differ by a strand asymmetry, and each rate carries a small lognormal jitter. Rates are normalized to a geometric mean of 1, since only their ratios matter. Each trajectory and each tree starts from its own sequence of random sense codons, redrawn if its fitness is negative.
On each landscape, we generated 1000 independent trajectories of 100 substitutions each. We also grew one tree per landscape for 100 steps under the same dynamics, using a branching process similar to a Yule process. At each step, each lineage stops with probability 0.05 and becomes a sampled tip. Each remaining lineage either splits into two daughter lineages, with probability 0.8, or continues as a single lineage. Each resulting lineage then takes one new substitution, drawn independently as above. To keep trees to a manageable size, whenever more than 70 lineages remain after a step, randomly chosen lineages stop as tips until 70 remain. After 100 steps, all remaining lineages become tips. Every branch thus carries exactly one substitution, and the training trees average about 11,000 branches and 5000 tips.
For each of the 950 training ligands, we held out about 10% of the tree's branches as whole clades and 50 of its trajectories. The training corpus combines the tree's remaining branches with 100 of its remaining trajectories, kept whole. For validation, we further set aside disjoint sub-clades of at least 20 nodes, covering about 10% of the remaining branches, and 10 of those 100 trajectories whole. We dropped training branches that share a parent with a held-out branch, so that no parent sequence appears both in training and in a held-out clade. This gave 17,087,194 training substitutions, about 9000 per ligand from its tree and 9000 from its trajectories, along with 1,955,321 validation substitutions and 1,042,713 substitutions in held-out clades. Each of the 50 held-out ligands contributes its 1000 trajectories, all held out.
Bespoke transformer architecture
For the lattice experiments, we train a small encoder-only transformer from scratch. It reads the 18-residue protein through a vocabulary of the 20 amino acids and a mask token, with learned positional embeddings and returns a distribution over the 20 amino acids at each position. The model has six layers of width 256, four attention heads and a feed-forward width of 1024, with pre-layer normalization, GELU activations and no dropout, giving 4.9M parameters. Each attention layer applies layer normalization to its queries and keys before the dot product (QK-LayerNorm [73]), which bounds the attention logits. Both objectives read this output head: masked language modeling at masked positions and the wildtype-marginal log-odds at every position of the unmasked parent. A single global scale gives . The model receives only the parent sequence and never sees the ligand, so any information about the fitness landscape comes from the sequence itself. The mutation spectrum comes from the same nucleotide mutation head used with empirical data, a two-layer transformer of width 128 that reads the 54-nucleotide parent and adds 0.6M parameters beyond the 4.9M of the protein model, here also with QK-LayerNorm. For the scaling experiments, the smaller and larger models have four layers of width 128 (0.85M parameters) and eight layers of width 512 (26M parameters), keeping 64 dimensions per attention head.
Bespoke transformer training
We trained each model in two stages. The first stage trained a base model from scratch by masked language modeling alone (). The second stage fine-tuned the base under , with a newly initialized mutation head, and optimizer state. Each stage ran 8343 steps, one pass over the 17.1M training substitutions at a batch size of 2048, and each step drew a separate batch of 2048 sequences for masked language modeling. The masked language modeling corpus consists of the training parent sequences, thinned within each ligand at a given protein-identity threshold, giving 2.06M amino acid sequences at 94%. In each sequence we selected each position for masking independently with probability 0.15, plus one position chosen at random so that at least one was always selected, or 3.55 of the 18 positions on average, about 20%. Unlike empirical training, we followed BERT in replacing 80% of selected positions with the mask token and 10% with a random amino acid, leaving 10% unchanged.
We used AdamW at a constant learning rate of , chosen by a one-epoch pilot over multiples of , with no warmup, weight decay of and gradients clipped at norm 1. had its own learning rate of , with no weight decay. Training used fp32 weights with TF32 matrix multiplication and no dropout. The thinning experiment (Figure S6) reports base models after the first stage. Elsewhere, is a second stage of continued masked language modeling at matched compute. Models trained without substitutions have no signal to fit a mutation head, so we scored them with the fixed mutation head of a single substitution-only () model fine-tuned from a 94% base. We trained three replicates of each setting, with each fine-tune sharing its base's seed and starting from the base's final checkpoint. We saved checkpoints every 1000 steps and report each model at the checkpoint with the highest nonsynonymous information gain on validation substitutions. Each stage took about 45 minutes with two runs sharing an A100 40 GB GPU.
For the scaling experiments (Figure S10), each stage ran 25,029 steps, three passes over the 950-ligand corpus, and each fine-tune started from its base's best-validation checkpoint. Learning rates for each model size came from the same pilot: for the 4.9M and 26M models and for the 0.85M model, whose fine-tunes ran at half that rate for stability.
Supporting References
- Miyazawa S, Jernigan RL (1985) Estimation of effective interresidue contact energies from protein crystal structures: quasi-chemical approximation. Macromolecules 18: 534–552.
- Guo C, Pleiss G, Sun Y, Weinberger KQ (2017) On calibration of modern neural networks. In: ICML. pp. 1321–1330.
- Miller DW, Dill KA (1997) Ligand binding to proteins: the binding landscape model. Protein Sci 6: 2166–2179.
- Williams PD, Pollock DD, Goldstein RA (2001) Evolution of functionality in lattice proteins. J Mol Graph Model 19: 150–156.
- Bloom JD, Silberg JJ, Wilke CO, Drummond DA, Adami C, et al. (2005) Thermodynamic prediction of protein neutrality. Proc Natl Acad Sci USA 102: 606–611.
- Dehghani M, Djolonga J, Mustafa B, Padlewski P, Heek J, et al. (2023) Scaling vision transformers to 22 billion parameters. In: ICML. pp. 7480–7512.