What is tokenization, and why can't LLMs just process raw text directly?
Tokenization is the process of breaking text into smaller units (tokens) — like words, sub-words, or characters — and converting each into a numerical ID the model can process, since neural networks operate on numbers, not raw text characters directly. It's like converting a sentence into a sequence of numbered entries from a lookup dictionary before a machine that only understands numbers can do anything with it — the machine can't directly 'read' letters, so everything first needs to be translated into its numerical vocabulary.
Neural networks, including Transformers, are fundamentally mathematical systems that operate on numerical vectors — matrix multiplications, additions, and non-linear transformations — and have no native way to process raw text characters or strings directly. Before any text can be fed into a model, it needs to be converted into a sequence of numbers the model's architecture can actually operate on.
Tokenization is this conversion process: text is first split into discrete units called tokens (which could be whole words, parts of words/sub-words, individual characters, or even raw bytes, depending on the specific tokenization scheme used), and each unique token in the model's vocabulary is assigned a specific integer ID. The input text is then represented as a sequence of these integer IDs, which is what actually gets fed into the model — the first step inside the model is typically an embedding layer that converts each integer token ID into a dense vector representation (an embedding), which is the actual numerical form the rest of the Transformer architecture operates on.
The specific way text gets split into tokens matters significantly for both efficiency and model behavior. Splitting purely by individual characters would keep the vocabulary very small (only needing entries for each possible character), but would result in very long token sequences for any given piece of text, since even short words become multiple tokens — this significantly increases the computational cost of processing a given amount of text, since Transformer computation scales with sequence length. Splitting purely by whole words keeps sequences shorter, but requires an enormous vocabulary to cover all possible words in a language (and would still fail entirely on any word not in that fixed vocabulary, a problem sometimes called the out-of-vocabulary problem). Modern LLMs use a middle-ground approach — sub-word tokenization — which balances these concerns by breaking text into a vocabulary of common whole words plus common sub-word pieces, allowing reasonably compact sequences for common text while still being able to represent any possible input text (including rare or unseen words) by breaking it down into smaller known sub-word pieces, rather than having a fixed, closed vocabulary that fails entirely on truly novel words.
Framing the character/word/sub-word comparison as a genuine trade-off (not just 'sub-word is simply better') shows you understand *why* the middle-ground approach was chosen, rather than just knowing it's the current standard.