Introduction
DNA has only four ordinary bases, but useful signals occur at several scales: individual positions, short local motifs, repeated sequence, and longer context. A tokenizer therefore has to trade sequence length against positional fidelity while producing representations that transfer to both sequence-level and position-level tasks. Single-nucleotide tokenizers preserve the finest resolution [1, 2]. Fixed k-mers shorten the sequence by binding neighboring bases into predefined words [3, 4], while BPE-style vocabularies learn merges [5]. Learned and dynamic chunkers make the boundaries data-dependent [6, 7, 8, 9]. Work on tokenizer choice and transfer makes clear that this representation decision can dominate downstream behavior [10, 11].
We ask whether a tokenizer can obtain some of the efficiency of chunks without giving up a state at every nucleotide. Our answer is HRC: a character vocabulary feeds a deep bidirectional encoder; a learned convolution summarizes non-overlapping groups before the fixed backbone; interpolation and a learned encoder residual return information to the original positions; and a decoder refines those states. The pretraining target remains masked reconstruction, but repeated regions receive less weight.
Method
Character inputs and bidirectional encoder
We use the fixed character vocabulary already exposed by the interface. Nucleotide code is mapped to token id , with vocabulary size , mask id , and padding id . There is no corpus fitting step and no CPU-side segmentation: every nucleotide enters the embedding table. The tokenizer then applies six bidirectional Mamba blocks. Each block runs a forward and a reversed state-space scan, sharing the input and output projections, and adds the two directions.
def _rev_index(lengths, T):
t = torch.arange(T, device=lengths.device)[None, :]
L = lengths[:, None]
return torch.where(t < L, L - 1 - t, t)
class BiMamba(nn.Module):
def __init__(self, d_model, layer_idx=None, **kw):
super().__init__()
self.mamba_fwd = Mamba(d_model=d_model, layer_idx=layer_idx, **kw)
self.mamba_rev = Mamba(d_model=d_model, layer_idx=layer_idx, **kw)
self.mamba_rev.in_proj.weight = self.mamba_fwd.in_proj.weight
self.mamba_rev.in_proj.bias = self.mamba_fwd.in_proj.bias
self.mamba_rev.out_proj.weight = self.mamba_fwd.out_proj.weight
self.mamba_rev.out_proj.bias = self.mamba_fwd.out_proj.bias
self.rev_idx = None
def forward(self, x, inference_params=None):
out = self.mamba_fwd(x)
if self.rev_idx is None:
return out + self.mamba_rev(x.flip(1)).flip(1)
g = self.rev_idx[:, :, None].expand_as(x)
return out + torch.gather(self.mamba_rev(torch.gather(x, 1, g)), 1, g)The encoder output is . Keeping this full-resolution path is deliberate: the compressed branch can supply broad context, while the residual path retains local information for the nucleotide-level head.
Learned compression and nucleotide reconstruction
For a sequence of length , we set and . With the selected convolutional option, a bias-free -by- Conv1d with kernel and stride maps the first encoder states to . The fixed backbone sees , so its token sequence is shorter while its input and output width stay unchanged. We then linearly interpolate the backbone output to positions, pad the right edge if , and add a learned projection of the original encoder states before six decoder blocks.
If is the backbone output, the reconstruction input is
followed by the decoder stack and RMS normalization. The resulting tensor has one state per input nucleotide and is returned unchanged by nucleotide_states; downstream heads therefore receive nucleotide-resolution states even though the backbone operated on compressed tokens.
class Tokenizer(nn.Module):
VOCAB, MASK, PAD, OFFSET = 12, 3, 4, 7
N_ENC, N_DEC = 6, 6
C = 4
COMPRESS = "conv" # avg | conv
UPSAMPLE = "interp" # repeat | interp
RC_WEIGHT = 0.0
repeat_penalty = 0.1
mlm_probability = 0.15
def __init__(self, d_model: int):
super().__init__()
d = d_model
self.embed = nn.Embedding(16, d)
self.enc = nn.ModuleList([make_block(d, i) for i in range(self.N_ENC)])
self.dec = nn.ModuleList([make_block(d, 100 + i) for i in range(self.N_DEC)])
self.residual_proj = nn.Linear(d, d)
if self.COMPRESS == "conv":
self.compress = nn.Conv1d(d, d, self.C, stride=self.C, bias=False)
nn.init.normal_(self.compress.weight, std=0.02) def _forward(self, ids, backbone):
B, L = ids.shape
x = self.embed(ids)
h_enc, _ = run_blocks(self.enc, x)
C = self.C
Lc = L // C
if self.COMPRESS == "avg":
hc = h_enc[:, :Lc * C].reshape(B, Lc, C, -1).mean(2)
else:
hc = self.compress(h_enc.transpose(1, 2)).transpose(1, 2)
z = backbone(hc)
if self.UPSAMPLE == "repeat":
zu = z.repeat_interleave(C, dim=1)
else:
# linear interpolation between token centers
zu = F.interpolate(z.transpose(1, 2), size=Lc * C, mode="linear", align_corners=False).transpose(1, 2)
if zu.shape[1] < L:
zu = F.pad(zu, (0, 0, 0, L - zu.shape[1]))
hidden, residual = run_blocks(self.dec, zu + self.residual_proj(h_enc))
out = rms_norm_fn(hidden, self.norm_f.weight, self.norm_f.bias, eps=self.norm_f.eps,
residual=residual, prenorm=False, residual_in_fp32=False)
return outMasked objective and repeat weighting
We retain the character masked-language-model objective. Each position is selected with probability . A selected input is replaced by the mask id with probability ; among the remaining selected inputs, half receive a random vocabulary id and half remain unchanged. Unselected targets are set to the padding id and ignored by cross-entropy. The logits use the embedding table as the output matrix:
where is the sum of the active weights. If no repeat track is supplied, all active positions have unit weight. This weighting changes the pretraining emphasis without entering the representation path used at transfer.
The reverse-complement auxiliary loss is disabled with RC_WEIGHT = 0.0; the final method consequently relies on the bidirectional stacks and the residual path rather than adding a second objective.
def pretrain_loss(self, nuc, extra, backbone):
ids = nuc + self.OFFSET
target = ids.clone()
masked = torch.rand(ids.shape, device=ids.device) < self.mlm_probability
target[~masked] = self.PAD
inp = ids.clone()
replaced = (torch.rand(ids.shape, device=ids.device) < 0.8) & masked
inp[replaced] = self.MASK
rand = (torch.rand(ids.shape, device=ids.device) < 0.5) & masked & ~replaced
inp[rand] = torch.randint(self.VOCAB, ids.shape, device=ids.device)[rand]
h = self._forward(inp, backbone)
logits = F.linear(h, self.embed.weight).float()
rep = extra.get("repeat") if isinstance(extra, dict) else None
y = target.view(-1)
if rep is None:
mlm = F.cross_entropy(logits.view(-1, logits.shape[-1]), y, ignore_index=self.PAD)
else:
ce = F.cross_entropy(logits.view(-1, logits.shape[-1]), y, ignore_index=self.PAD, reduction="none")
w = torch.where(rep.reshape(-1) > 0, self.repeat_penalty, 1.0).float()
w = torch.where(y == self.PAD, torch.zeros_like(w), w)
mlm = (ce * (w / w.sum().clamp_min(1e-12))).sum()
loss = mlm
stats = {"mlm": mlm.detach()}
if self.RC_WEIGHT > 0:
rc_inp = self.comp[inp].flip(1)
with torch.no_grad():
h_rc = self._forward(rc_inp, backbone).flip(1)
rc = F.mse_loss(h.float(), h_rc.float())
loss = loss + self.RC_WEIGHT * rc
stats["rc"] = rc.detach()
return loss, statsResults
| Method | ① | ② | ③ | ④ |
|---|---|---|---|---|
| Benchmark mean score ↑ | Benchmark mean score ↑ | Benchmark mean score ↑ | Benchmark mean score ↑ | |
| Qwen4-Max | 0.634 | 0.471 | 0.622 | 0.430 |
| Single-nucleotide tokens | 0.621 | 0.457 | 0.626 | 0.454 |
| Non-overlapping 6-mers | 0.594 | 0.445 | 0.611 | 0.434 |
| Overlapping 6-mers | 0.598 | 0.474 | 0.635 | 0.468 |
| Byte-pair encoding | 0.564 | 0.437 | 0.567 | 0.429 |
| DNAChunker | 0.629 | 0.466 | 0.624 | 0.457 |
| DNAChunker, camera-ready decoder | 0.628 | 0.465 | 0.629 | 0.462 |
| dnaHNet | 0.606 | 0.443 | 0.599 | 0.412 |
| MxDNA | 0.650 | 0.468 | 0.639 | 0.438 |
| No pretraining | 0.623 | 0.399 | 0.409 | 0.292 |
- ① NT benchmark (revised) · Mamba backbone
- ② BEND · Mamba backbone
- ③ NT benchmark (revised) · Transformer backbone
- ④ BEND · Transformer backbone
On NT-Mamba, HRC reaches 0.634, compared with 0.621 for the single-nucleotide baseline. The strongest published baseline there is MxDNA [7] at 0.650. On BEND-Mamba, HRC reaches 0.471 versus 0.457, while Overlapping 6-mers [3] is strongest at 0.474. Thus the method improves the simple character baseline on these two settings but does not lead the field.
The picture reverses on NT-Transf and BEND-Transf. HRC obtains 0.622 on NT-Transf against 0.626, with MxDNA [7] at 0.639. On BEND-Transf it obtains 0.430 against 0.454, while Overlapping 6-mers [3] reaches 0.468. The residual branch appears compatible with fine positional transfer, but the aggregate results show that compression and extra depth do not uniformly improve transfer.
How we got here
We began with the starter's character tokenizer because it gives every position a direct state and keeps the vocabulary independent of a corpus fit. The trace then explored where that representation paid for its long sequence. A deeper full-resolution encoder/decoder was the first structural attempt; development checks suggested that it was undertrained under the available budget and could lose fine-resolution transfer. We therefore kept depth only together with compression and an explicit residual route.
We also tried changing the objective. A replaced-token detection variant provided a denser discriminative signal but did not improve the downstream screen, so we returned to masked reconstruction. A reverse-complement consistency term was tested as an auxiliary loss and was removed after it hurt the aggregate development behavior; that outcome is reflected directly in the final zero weight. Repeat-aware weighting was retained because it changes emphasis without changing the token sequence.
The final sweep compared average and convolutional compression, repeated and interpolated upsampling, several compression widths, and shallower or deeper encoder/decoder stacks. The selected configuration is the convolutional, interpolated path with and six blocks on each side. Attention pooling was competitive in the trace, but the convolutional residual path was kept because its positional behavior was more balanced across the downstream checks. These are development observations from the trace, not additional benchmark measurements.
Limitations
HRC still uses a fixed character vocabulary and a fixed compression factor. It does not learn boundaries from the sequence, so it cannot adapt its token length to a motif or a repeated region in the way learned chunkers can. Because , the compressed branch omits any trailing remainder before the reconstruction padding; the encoder residual still carries those positions, but the fixed backbone does not contextualize that remainder through a compressed token.
The method adds twelve tokenizer-side bidirectional blocks around the fixed backbone. That gives the residual route substantial capacity and may make optimization harder when the pretraining budget is short; the trace's failed deeper full-resolution attempt is evidence of that risk. The selected convolution and interpolation choices are also fixed design decisions rather than learned alternatives.
The repeat weighting depends on the optional training-time repeat track. It is safe when the track is absent because the code falls back to ordinary masked loss, but it cannot exploit repeat annotations at transfer time. Conversely, the disabled reverse-complement term provides no explicit strand-consistency objective.
Finally, the reported results are mixed. HRC is above the single-nucleotide baseline on NT-Mamba and BEND-Mamba, below it on NT-Transf and BEND-Transf, and below the strongest baseline on every setting. The method therefore offers a useful compression-and-residual design, not a universal replacement for learned or fixed alternative tokenizers.
References
- Yair Schiff, Chia-Hsiang Kao, Aaron Gokaslan et al. (2024). Caduceus: Bi-Directional Equivariant Long-Range DNA Sequence Modeling. ICML.
- Eric Nguyen, Michael Poli, Marjan Faizi et al. (2023). HyenaDNA: Long-Range Genomic Sequence Modeling at Single Nucleotide Resolution. NeurIPS.
- Yanrong Ji, Zhihan Zhou, Han Liu et al. (2021). DNABERT: pre-trained Bidirectional Encoder Representations from Transformers model for DNA-language in genome. Bioinformatics.
- Hugo Dalla-Torre, Liam Gonzalez, Javier Mendoza-Revilla et al. (2025). Nucleotide Transformer: building and evaluating robust foundation models for human genomics. Nature Methods.
- Zhihan Zhou, Yanrong Ji, Weijian Li et al. (2024). DNABERT-2: Efficient Foundation Model and Benchmark For Multi-Species Genome. ICLR.
- Taewon Kim, Jihwan Shin, Hyomin Kim et al. (2026). DNACHUNKER: Learnable Tokenization for DNA Language Models. ICML.
- Lifeng Qiao, Peng Ye, Yuchen Ren et al. (2024). Model Decides How to Tokenize: Adaptive DNA Sequence Tokenization with MxDNA. NeurIPS.
- Sukjun Hwang, Brandon Wang, Albert Gu (2026). Dynamic Chunking for End-to-End Hierarchical Sequence Modeling. ICLR.
- Arnav Shah, Junzhe Li, Parsa Idehpour et al. (2026). dnaHNet: A Scalable and Hierarchical Foundation Model for Genomic Sequence Learning. ICML.
- LeAnn M Lindsey, Nicole L Pershing, Anisa Habib et al. (2025). The impact of tokenizer selection in genomic language models. Bioinformatics.
- Kirill Vishniakov, Karthik Viswanathan, Aleksandr Medvedev et al. (2026). Tokenization to Transfer: Do Genomic Foundation Models Learn Good Representations?. ICLR.