Notes

Tokenization

Before anything can be counted, embedded or fed to a model, a stretch of text has to be cut into pieces. Tokenization is that cut — and deciding where one token ends and the next begins is less obvious than it looks.

Where the boundaries go
Splitting on whitespace handles English prose for about one sentence. Then don't arrives: one token, or do plus n't? New York is two words and one thing, and the full stop after Dr. has to be told apart from the one ending a sentence. Rule-based tokenizers settle all of this as explicit conventions — the Penn Treebank rules are the best-known set, implemented in NLTK and mirrored in spaCy's per-language rules. Writing systems without spaces, such as Chinese, need segmentation that is a model in its own right.

Why the choice propagates
Tokens define the vocabulary, and the vocabulary fixes what every later stage can see:

  • counts, TF-IDF weights and n-gram features are computed over tokens, so a different split means different features;
  • part-of-speech tags, entity spans and parse trees attach to tokens, so annotation and prediction have to agree on them;
  • scores are computed over token spans, so mismatching the tokenizer between training and test measures the wrong thing.

The limit of whole words
A fixed word-level vocabulary cannot cover an open vocabulary: a surname, a typo or a new product name is simply unseen, and everything the model knows about it collapses into one out-of-vocabulary token. That ceiling is why subword schemes took over in neural pipelines — though the rule-based step rarely disappears, it just runs first and hands whitespace- and punctuation-separated chunks to the subword model.

Tokenization splits raw text into the discrete units — typically words, punctuation marks and sentences — that later processing operates on. Rule-based tokenizers apply explicit conventions for contractions, hyphens and abbreviations, so that a full stop ending a sentence is treated differently from one inside U.S.A. The chosen split defines the vocabulary, and therefore the features, annotations and evaluation spans of everything downstream; changing it mid-pipeline invalidates all three.

Read a sentence out loud and you break it up without thinking — into words, then into the pauses between them. Software has no such instinct. Handed a line of text, all it really has is a long string of characters.

Tokenization is the step that chops that string into sensible pieces, usually words and punctuation, before anything else happens. It sounds trivial until you look closely: should don't count as one word or two? Is New York one name or two words? Does the dot after Dr. end the sentence? Every later step — counting words, tagging names, translating — works on the pieces this step produced, so getting the cuts right matters more than it first appears.