· 10 min read
NLP #1: What Is a Word?
On this page
I'm taking an introductory natural language processing (NLP) course this semester. This series is me learning it in public. My course follows Speech and Language Processing by Jurafsky & Martin: the 3rd edition draft (January 2026 version), which is free online. The authors update the draft occasionally, so a newer version may number its sections differently. Any version works if you want to follow along.
This first post covers sections 2.1–2.2. Before a model can read text, someone has to decide what a "word" is. That decision is the first step of every NLP system, from a spam filter to ChatGPT.
Each post has three parts: Intuition (no math needed), The math (definitions and key equations), and Exercises (to check yourself).

Intuition
Counting words is a choice
Take one sentence, our running example for the whole post:
The bakery's cinnamon rolls were so good, I bought more rolls for the road.
How many words? Split on spaces and you get 14. But "rolls" appears twice, so there are only 13 different words. NLP needs both counts. Every word as it appears in the text is an instance. Every distinct word is a type. The set of types is the vocabulary.
Then the questions start. Are "The" and "the" the same type? Is the comma a word? There's no single right answer. A search engine may ignore capitals. A model that writes text keeps capitals and punctuation, because it has to produce both. Try it:
N = 14, |V| = 13
- The
- bakery's
- cinnamon
- rolls ×2
- were
- so
- good
- I
- bought
- more
- for
- the
- road
Spoken language adds more puzzles. In "I want, uh, the cinnamon one", is uh a word? A transcript for reading would drop it. A speech recognizer keeps it, because a pause like that is a hint about what comes next.
New words never stop coming
On the first page of a novel, almost every word is new to your list. By page 100 you have seen "the", "and" and "she" hundreds of times, and new words come slowly. But they never stop: there's always another name, place, technical term, typo or bit of slang.
So a vocabulary has no final size. The more text you collect, the bigger it gets. For a model this is a real problem: however large its word list, it will meet words that aren't on it.
Words have parts
"Rolls" is roll plus -s, which means "more than one". "Bakery's" is bake, plus -ery (a place where it's done), plus 's (belongs to). These smallest pieces that carry meaning are called morphemes. Some don't split cleanly: "bought" means buy + past tense, but you can't point to the letters that mean "past".

Languages differ a lot here. In Spanish, dámelo ("give it to me") is one written word: da (give) + me (to me) + lo (it). Chinese has no spaces between words, so finding the words is its own task.
Put together, these facts make whole words a shaky unit for a model. They're hard to define across languages, and new ones keep appearing. That's why modern models split text into subwords, pieces between a letter and a word. Reusing pieces like bake, -er and -s, they can build words they've never seen, like baker and bakes. How they choose those pieces is the topic of the next posts.
The math
Instances and types
Definition 1 (Corpus, word instance). A corpus is a collection of text. After deciding what counts as a word, the corpus is a sequence of word instances . is the number of instances, the length of the corpus in words.
Definition 2 (Vocabulary, word type). The vocabulary is the set of distinct words in the corpus: , with repeats removed. Its elements are types, and is the number of types.
Since every type appears at least once, . In the running example, splitting on spaces and keeping capitals, and . Lowercasing merges "The" and "the" into one type, so . Counting the comma and the period as words gives .
In code, with one possible definition of "word":
import re
text = "The bakery's cinnamon rolls were so good, I bought more rolls for the road."
words = re.findall(r"[\w']+", text) # letters, digits and apostrophes
print(len(words), len(set(words))) # N = 14, |V| = 13Heaps' law
Key equation (Heaps' law, also called Herdan's law). For a text of words, the number of different words is about
It has two numbers, both measured from real text:
- (beta) is the growth rate: how fast new words keep coming. At every word is new; at no word is. For English is between 0.4 and 0.6. At the usual 0.5, 100 times more text gives only about 10 times more different words.
- is the scale: it moves the whole curve up or down. A varied text (technical, full of names) has a bigger .
For example, with and , a text of 10,000 words has about different words, and a text of 1,000,000 words about 20,000.
Taking logs gives : on log-log axes the law is a straight line, and is its slope. Here is real text: ten classic novels read one after another. Drag the slider to see the slope at each point:
5,623 words → 1,579 different · β ≈ 0.60 · Pride and Prejudice
The slope starts near 1 (at first almost every word is new), settles around 0.5, and rises again when a new author brings new names. So isn't one fixed number: it describes a stretch of text.
Two more ways to read the law. The derivative of is always positive, but it shrinks as grows:
New words keep coming, but more slowly. Scaling shows the same thing: multiply the text by , and the vocabulary grows only by , which is less than :
Morphemes
Definition 3 (Morpheme, root, affix). A morpheme is the smallest unit of a language that carries meaning. A word is a sequence of morphemes . The root carries the main meaning (bake in bakery). Affixes add to it (-ery, -s).
Definition 4 (Inflectional, derivational, clitic). An inflectional affix adds grammar and keeps the word's class: roll → rolls (plural), bake → baked (past). A derivational affix makes a new word, often of a different class, with a less predictable meaning: bake (verb) → bakery (noun). A clitic acts like a separate word but can't stand alone, so it attaches to its neighbor: the 's in bakery's, the 'll in I'll.
Key equation (morphemes per word). If word of a text has morphemes, the text averages
morphemes per word. Languages with close to 1 (like Vietnamese) are called isolating. Languages that pack many morphemes into one word (like Turkish) are synthetic. A high means many possible word forms, so grows faster. That is one more reason to split text into subwords.
Exercises
Try each one before opening the answer. Questions 6–10 use the definitions and equations above.
1. (Intuition) Is um a word? Give one application that should keep it and one that should remove it.
Answer
It depends on the task. A speech recognizer should keep it, since a filler signals a pause or a restart and helps predict what comes next. Subtitles or a meeting summary for reading should remove it, because it adds nothing for the reader.
2. (Intuition) In the counter above, paste a paragraph from any news site and switch "ignore capitals" on. Why does go down? Give an example where ignoring capitals loses information.
Answer
Words at the start of a sentence ("The") merge with the same word inside a sentence ("the"), so there are fewer types. But capitals sometimes carry meaning. Ignoring them merges "Apple" (the company) with "apple" (the fruit), and "US" (the country) with "us" (the pronoun).
3. (Intuition) You double the amount of text in your collection. Does the vocabulary double too?
Answer
No. Most of the new text reuses words you've already seen, so the vocabulary grows by much less than double. It does still grow, because the new text brings new names, terms and typos.
4. (Intuition) Give three reasons why a model can't simply use a list of all the words in a language.
Answer
- The list never ends: there are always new names, terms and slang.
- Some languages (Chinese, Japanese, Thai) don't put spaces between words, so even deciding where words are is hard.
- In languages with many morphemes per word, one root has a huge number of forms, each a separate entry.
5. (Intuition) The Spanish word dámelo means "give it to me". Split it into its parts. Then explain why it's a problem for a model that treats every whole word as one unit.
Answer
da (give) + me (to me) + lo (it). A whole-word model sees one rare word. It must learn that word from scratch, even if it has seen da, me and lo in other words. A subword model can reuse those parts.
6. (Math · Definitions 1–2) For the corpus "the dog saw the other dog near the gate", find and .
Answer
The instances are: the, dog, saw, the, other, dog, near, the, gate, so . The types are the, dog, saw, other, near, gate, so . "the" appears 3 times and "dog" 2 times, which accounts for the difference: .
7. (Math · Definition 2) Show that for any corpus. When are they equal?
Answer
Each type in is one of the instances . Different types come from different instances, so can't have more elements than there are instances: . They're equal exactly when no word repeats, meaning every instance is a different type.
8. (Math · Heaps' law) A corpus follows Heaps' law with and . (a) What is for ? (b) How many instances do you need for a vocabulary of 12,000 types?
Answer
(a) .
(b) Solve : , so .
Doubling the vocabulary takes four times as much text, because with , grows like .
9. (Math · Heaps' law, log form) You measure two points on a corpus: gives , and gives . Find and .
Answer
Divide the two equations: , so and .
Then .
10. (Math · Definitions 3–4, morphemes per word) Split each word of "The teachers repainted the unbreakable doors" into morphemes, label every affix as inflectional or derivational, and compute .
Answer
| Word | Morphemes | |
|---|---|---|
| The | the | 1 |
| teachers | teach + -er (derivational) + -s (inflectional) | 3 |
| repainted | re- (derivational) + paint + -ed (inflectional) | 3 |
| the | the | 1 |
| unbreakable | un- (derivational) + break + -able (derivational) | 3 |
| doors | door + -s (inflectional) | 2 |
morphemes per word.
Next: how computers store text as bytes: Unicode, code points and UTF-8 (section 2.3).