UUtah CS 6340 NLP | Fall 2026 | BPE Tokenizer (Part 1)
Overview
Subword tokenization breaks text into reusable units between characters and whole words, giving language models a finite vocabulary while retaining a way to represent unfamiliar words. The lecture explains how Byte Pair Encoding (BPE), adapted for NLP by Sennrich and colleagues in 2016, builds that vocabulary by repeatedly merging the most frequent adjacent token pairs, then applies the ordered merges to new text; it also covers character fallback, vocabulary-size tradeoffs, and practical tokenization quirks.
Key takeaways
- BPE constructs its vocabulary by repeatedly merging the most frequent adjacent token pair, recording each merge in order, and applying those ordered rules to tokenize new text.
- Starting with every character in the training corpus gives BPE character fallback, allowing rare or unseen words to be represented without collapsing them into a single unknown token.
- Vocabulary size trades coverage and shorter token sequences against the memory cost of the V-by-d embedding matrix; modern vocabularies can reach about 200,000 tokens.
- Subword tokenization helps with morphologically rich languages because rare inflected forms can be assembled from more common pieces instead of requiring a separate vocabulary entry for every form.
- BPE learns statistical units rather than linguistic or mathematical structure, so it can split numbers such as 17,328 into awkward pieces that may hinder numerical reasoning.
- A tokenizer's quality is ultimately assessed through downstream model performance, since the lecture identifies no universal intrinsic measure for judging a vocabulary on its own.
Chapters
- Students are directed to the Canvas syllabus, course website, and Piazza for schedules, readings, recordings, announcements, and team assignments.
- An availability poll will help schedule office hours; students are asked to join Piazza themselves while enrollment is changing.
- A question about whether a language's structure affects NLP performance remains open; the instructor notes that English has relatively little inflection compared with languages such as Croatian.
- An LLM receives a prompt as text, but a tokenizer first splits it into units such as the pieces of “superconductors.”
- A tokenizer includes both a vocabulary of possible tokens and rules for splitting input text into those tokens.
- Tokenization is an established NLP problem, discussed by researchers since at least the early 1990s, as well as a practical concern in modern LLM APIs.
- There are effectively infinitely many possible text sequences, so assigning a learned representation to every complete sequence would leave most examples too rare.
- Language is compositional: recurring words and phrases appear across many contexts and can acquire useful numerical representations.
- A model can combine representations of smaller units to represent a whole sequence instead of learning a separate vector for every sentence.
- Whitespace splitting leaves punctuation attached to words and fails to divide contractions such as “isn't” into reusable parts like “is” and “not.”
- Linguistically motivated units include roots and morphemes, but they do not offer one universally agreed tokenization scheme.
- Chinese NLP often uses character-level segmentation, while character-level tokenization performs poorly for English because it forces models to infer word structure from individual characters.
- Subword tokenization permits units ranging from individual characters to complete words, including pieces that have no independent linguistic meaning.
- A model's corpus frequencies determine which subwords become tokens rather than requiring linguists to define every unit manually.
- Pre-tokenization first divides text into words or word-like units, after which the subword algorithm builds token boundaries within them.
- Byte Pair Encoding originated as a data-compression algorithm in 1994 and was adapted for NLP tokenization by Sennrich and colleagues in 2016.
- BPE remains influential in modern LLM tokenizers; the lecture cites an ACL Test of Time Award as evidence of the 2016 work's lasting impact.
- The first programming practicum will evaluate BPE, and students are urged to complete the ungraded GradeScope practice assignment before the in-person assessment.
- BPE training takes an unlabeled text corpus and constructs both a vocabulary and merge rules; despite terms such as “trainer,” it is a classic algorithm, not machine learning.
- The example corpus contains “hello world,” “world peace,” and “peace please”; words are pre-tokenized and a special marker such as Ġ can represent a word boundary.
- The initial vocabulary contains every character observed in the corpus, including boundary markers where applicable, so unseen words can at least be represented character by character.
- At each training iteration, BPE counts adjacent token pairs and selects the pair with the highest frequency, randomly resolving ties.
- The selected pair is concatenated into a new vocabulary token, then occurrences are replaced within each word so merges do not cross word boundaries.
- Each merge is recorded in order for later use when tokenizing new text; the number of iterations, and thus vocabulary size, is a hyperparameter.
- Vocabulary sizes have ranged from roughly 30,000 to 100,000 tokens, with some modern vocabularies approaching 200,000.
- A vocabulary of size V paired with embedding dimension d requires an embedding matrix of shape V by d; a 200,000-token vocabulary and thousands of dimensions create substantial memory costs.
- Repeated merges grow character units into subwords and sometimes complete words; a token may also be a substring of a larger token.
- Implementations can store word frequencies and multiply pair counts by those frequencies, so a pair repeated in “hugging face” contributes multiple observations.
- The exact BPE corpus for commercial LLMs is rarely disclosed; it is generally related to the model's pretraining data, making efficient implementations important at internet scale.
- There is no single intrinsic score for vocabulary quality; different tokenizers can be compared by their downstream effects on language-model performance.
- To tokenize new input, split each pre-tokenized word into characters and apply the saved merge rules greedily in their learned order.
- The result is a sequence drawn from the learned vocabulary; word-boundary markers such as Ġ can preserve spaces through processing.
- Decoding joins the token pieces and converts the special boundary marker back into whitespace, keeping Ġ as an implementation detail rather than visible text.
- Because BPE begins with the corpus's characters, it can fall back to character sequences when a complete word or subword was not seen during training.
- Earlier fixed word vocabularies, such as a 30,000-word vocabulary, had to map rare test-time words to an unknown token with no word-specific semantic representation.
- Character fallback supports both comprehension and generation of rare forms, an especially important benefit for morphologically rich languages where many valid word forms are uncommon.
- Modern tokenizer-training data is broadly related to LLM pretraining data, which is largely internet text and may include code and multilingual content.
- Code-heavy data, including large collections from GitHub, introduces tokenization patterns that general-purpose BPE may handle imperfectly.
- For experimentation, smaller corpora such as WikiText are more practical than large datasets such as C4 or The Pile on a personal computer.
- Hugging Face provides a model and dataset hub, the Transformers library, and a tokenizers library for training and using tokenizers.
- The demonstration creates a BPE tokenizer and shows that the pre-tokenizer choice matters: a whitespace pre-tokenizer has limitations, while more capable alternatives can separate punctuation more effectively.
- Tokenization output can include character offsets that map each token back to its start and end positions in the original text, useful for applications that need source alignment.
- The demonstration shows that BPE can split a number such as 17,328 into unintuitive pieces, which may make numerical patterns harder for a language model to process.
- A repeated sequence such as “34” can produce two separate tokens when the learned merge rules contain a merge for “3” plus “4” but not a larger digit sequence.
- These results illustrate that token boundaries reflect corpus frequency and merge order, not human notions of number structure or linguistic meaning; the lecture closes by previewing a follow-up BPE session and an ungraded quiz.
Transcript excerpt
0:00 Okay, I think we can get started. Uh, welcome and welcome back. Um, I will get right into it. I will repeat the things I've said last time in case you weren't here. I know we had this room change. Maybe you haven't seen the announcement so you missed it. Um, long story short, you should check syllabus which is on the canvas. Uh, you should join Patza where we will communicate and there is a website associated with the course. Um and here you can see now the schedule is populating. This is where I'm going to share slides, recordings, readings. So all the materials you need for from lectures are going to be over there. Um just a few things uh please do join uh Piaza because we are going to start
0:49 sending teams over there. So I don't want you to miss anything. So you need to join to not miss anything since uh you know roster is changing in the first two weeks before the drop deadline. I don't want to add all of you because I don't know who's going to stick around. Uh so please do it uh on your own following this link. Um also please fill out this when to meet because I want to schedule office hours around when most of you are available. Uh so please please do me a favor and do that and then yeah read the read the syllabus. All the information that you need to know is um over over there. Any questions before we uh move on with the new lecture? Okay. I don't see anyone. Oh, yes,
1:37 please. Um this was just something I was thinking about um based on Monday's >> uh where like you talked about other languages and syntactic rules and using
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, UofU Data Science.