Document segmentation divides a string into a sequence of smaller text pieces called tokens. In a language-model pipeline, it follows normalization and precedes mapping each token to a numeric identifier. A token may be a whole word, part of a word, or another discrete substring. section 2.2.1 section 2.6
The simplest approach splits wherever a space appears: “hello world” becomes “hello” and “world.” Punctuation exposes the weakness of this rule: “hello, world” can produce “hello,” and “world,” treating punctuation-attached text as a separate token from “hello.” section 2.2.3
From characters to subwords
Byte-pair encoding, or BPE, starts with individual characters, finds frequent adjacent pairs, replaces them with combined tokens, and repeats. A simplified run might find “ng,” replace its occurrences with a placeholder, add “ng” to the vocabulary, and continue until no useful common pairs remain. This reduces dependence on hand-written splitting rules and can represent words as reusable subword pieces. section 2.2.3
Segmentation is not a neutral cleanup step. Its choices help determine vocabulary size, while vocabulary size affects how well text can be represented and how much computation, memory, and storage are needed. Languages without spaces also challenge whitespace-based rules, and poorly chosen tokens can hinder arithmetic or word-game behavior. section 2.2.3 section 2.6
