Natural Language Processing · free preview

Words, Corpora, and Word Frequency

Tokens and types, type-token ratio, Zipf's law, hapaxes, and Heaps' law, counted with NumPy on a small corpus.

1. Words, Corpora, and Word Frequency

Words, Corpora, and Word Frequency

2. Word frequencies follow two empirical laws

Word frequencies follow two empirical laws

3. Counting a corpus in a dozen lines

Counting a corpus in a dozen lines

4. Tokens and types in a sentence

Count word tokens and word types in this sentence (split on spaces, ignore punctuation): "the ferry waits, the mast waits, and the ferry waits again."

5. Type-token ratio

A toy corpus contains these 23 tokens:

"pilot mast harbour dusk wake wake mast pilot dusk sail harbour pilot mast pilot wake wake sail pilot harbour wake sail dusk mast"

Compute the type-token ratio, rounded to three decimal places.

6. Zipf's law interpolation

In a large corpus the most frequent type occurs 22,000 times. Zipf's law predicts the frequency of the type at rank 4 as f(r)=k/rf(r) = k/r. How many occurrences does it predict for rank 4?

7. Share of the most frequent type

The three most frequent types in a corpus occur 3,120, 1,560, and 520 times, and the long tail of remaining types accounts for 3,000 tokens. What fraction of all tokens does the single most frequent type account for? Round to three decimal places.

8. Heaps' law extrapolation

A corpus of 600,000 tokens has a vocabulary of 50,000 types. Assume Heaps' law ∣V∣=k nβ|V| = k\,n^{\beta} with β=0.56\beta = 0.56. Predict the vocabulary size at 1,200,000 tokens.

Practice this interactively

Free account · instant grading · spaced review that schedules itself.

Start this course for free