K-mer
A k-mer is a length- substring of a biological sequence. It is a common tokenization unit for DNA, RNA, and protein-like sequence inputs.
For a sequence , the -th k-mer is:
The number of overlapping k-mers is:
For an alphabet of size , the possible vocabulary size is:
This grows exponentially with , so large k-mers quickly become sparse.
Why It Matters
- K-mers convert long sequences into discrete tokens or counts.
- Larger captures more context but increases vocabulary size.
- Small can miss long-range dependencies.
- Overlapping k-mers can create near-duplicate leakage if windows are split carelessly.
Design Choices
| Choice | Effect |
|---|---|
| k | controls local context and vocabulary size |
| stride | overlapping stride 1 gives dense tokens; larger stride reduces redundancy |
| reverse complement handling | merge or separate strand-equivalent tokens |
| ambiguous bases | keep, mask, discard, or map to unknown token |
| count vs sequence | bag-of-k-mers loses order; token sequence preserves local order |
| vocabulary cutoff | rare k-mers may be pruned or mapped to unknown |
Checks
- What value of is used?
- Are ambiguous bases handled explicitly?
- Are reverse complements merged or kept separate?
- Is tokenization deterministic across train and inference?
- Does the split prevent overlapping windows from crossing train and test?
- Is the model using k-mer counts, ordered k-mer tokens, or learned embeddings?
- Is vocabulary construction fit only on training data when it depends on frequency?