Tokenization

Tokenization chooses the basic units that a model receives. It is not only a text preprocessing step: residues, atoms, image patches, graph nodes, retrieved chunks, and tool calls can all be treated as tokens.

A sequence model usually starts from discrete tokens:

and maps them to vectors:

where is the embedding for token , and is a positional or structural encoding.

Common Choices

  • Text: character, byte, subword, wordpiece, or sentence chunk.
  • Image: patch, region, pixel, feature-map cell, or visual token.
  • Video and audio: frame, clip, spectrogram patch, waveform chunk, or learned acoustic token.
  • Protein sequence: amino acid residue, motif, span, or multiple-sequence-alignment token.
  • Molecule: SMILES token, atom, bond-centered token, substructure, or conformer token.
  • Grid or structure: voxel, contact-map cell, spatial window, or local coordinate token.
  • Agent context: message, retrieved document chunk, tool call, observation, or memory item.

Tokenization Contract

FieldQuestionExample
UnitWhat object becomes one token?byte, subword, residue, atom, patch, node
VocabularyIs the token space fixed, learned, open, or continuous?BPE vocab, amino acids, atom types
BoundaryHow are sequence breaks, chains, documents, or components marked?BOS/EOS, chain id, segment id
LengthWhat controls token count?sequence length, image resolution, atom count
Lost informationWhat is discarded before modeling?stereochemistry, whitespace, coordinates, metadata
ReversibilityCan outputs be decoded back to valid objects?valid text, molecule, graph, action

Tokenization is part of the model claim because it determines what the model can possibly learn.

Scaling

For Transformer-style attention, token count directly affects cost:

where is token length and is hidden width. A paper claiming better architecture or training can actually be benefiting from shorter or more informative tokens.

Domain-Specific Risks

DomainToken Risk
texttokenizer changes can alter benchmark prompts and likelihoods
imagepatch size trades spatial detail for sequence length
proteinresidue tokens may miss MSA, domain, or structure context
molecule SMILESdifferent valid strings can represent the same molecule
molecular graphatom/bond features depend on standardization and chemical state
structurecoordinate tokens need frames, units, and equivariance policy
agentstool-call tokens need schema validity and execution feedback

Output Decoding

If the model generates tokens, validity depends on a decoder:

For structured objects, detokenization can fail. Report invalid strings, invalid graphs, schema violations, or failed tool calls instead of silently dropping them.

Checks

  • What information is lost before the model sees the input?
  • Does token length scale with sequence length, atom count, image resolution, or retrieved context size?
  • Are positional, chain, segment, or structural encodings needed?
  • Does tokenization leak labels, future information, or evaluation-set-specific preprocessing?
  • Is the tokenizer trained on test or future data?
  • Are invalid detokenized outputs counted in evaluation?