Subword tokenization and embedding tables
What it is
A tokenizer maps text to integer token IDs, commonly with BPE or WordPiece subwords rather than whole words. Subwords make a finite vocabulary capable of representing rare names, inflections, code, and new compounds by breaking them into reusable pieces. An embedding table maps each ID to a learned vector; adding position information yields the ordered sequence of vectors presented to a Transformer. The embedding table is trained like any other parameter matrix: only rows for tokens appearing in a batch receive direct gradient updates.
Why it matters
Tokenization fixes the vocabulary, sequence length, cost, and even what text a model can express. Embeddings give tokens with similar training contexts an opportunity to become nearby vectors, but proximity is a learned association, not a guaranteed human semantic truth. A tokenizer mismatch at inference is therefore catastrophic: the same text becomes different IDs, and the model is asked to interpret a language it was not trained to read.
In the real world: How a chatbot turns a customer's message into numbers it can work with.
Visual example
Deep learningText becomes token IDs, then learned vectors with position information.
import torch
import torch.nn as nn
ids = torch.tensor([[1045, 2293, 2204, 4157]]) # (batch=1, seq=4)
embed = nn.Embedding(num_embeddings=30_522, embedding_dim=768)
vectors = embed(ids)
vectors.shape # torch.Size([1, 4, 768])
embed.weight.shape # torch.Size([30522, 768]) - one row per vocabulary entryCounting words to estimate context length. Models consume tokenizer-specific tokens, not words or characters; always use the tokenizer for the model you will run.