Tokenization and embeddings

Draft

Draft

This page is a skeleton for review: a short opening, planned headings, diagrams and references. The article is not written yet. It is listed here so the chapter can be checked as a whole. (Quarto’s draft: true would hide the page from the preview, so we mark the draft in this callout instead.)

From bytes to vectors

A language model does not read letters the way we do. It first cuts the text into a finite list of pieces, called tokens, and then looks up a vector for each piece, called an embedding. The rest of the network only ever sees those vectors. This page will be the short, plain-language walk through that first step: why we do not feed raw characters or whole words, how a vocabulary is chosen, and what an embedding actually stores.

Why we tokenise

  • A model needs a fixed vocabulary. Letters are too small (long sequences, weak meaning); whole words explode the list and leave new spellings unseen.
  • The usual compromise is subwords: common words stay one token, rarer words split into familiar pieces. Planned: a short analogy (a child’s reading book that already knows “play” and “ing”).
  • One sentence, tokenised two ways, is enough to show that “the same text” is not “the same number of tokens”.

A vocabulary, and then a vector

  • Each token id is just an index in a table. The embedding is the row of that table: a learned vector.
  • Nearby vectors tend to play similar roles, but this is not a magic map of meaning; it is a useful starting point the later layers can move.
  • Planned: one paragraph on positional information (the model also needs to know order), with a pointer to The Transformer and Language model architecture rather than a second architecture lesson.

What this page will not do

  • It will not become a survey of every tokenizer (BPE, WordPiece, SentencePiece) or a recipe for training one. A sketch of the idea, and pointers, is enough.
  • Context windows, packing, and serving belong with Language model inference and, for production, with System Design / MLOps, not here.

Planned diagrams

  • Light and dark: a short sentence split into subword tokens, then each token looked up in a small embedding table.
  • Optional: the same word, split differently by two vocabularies, to show that “token count” is a choice.

Planned references

See also

Back to top