liveBook · Manning

Vocabulary

As explained in Grokking AI Algorithms, Second Edition

A vocabulary is a collection of distinct tokens recognized by a language-processing system, often associated with numerical identifiers.

A vocabulary is the collection of distinct tokens a language model recognizes. Think of it as a numbered catalog: each token has an ID, so text can be converted into a sequence of numbers for the model to process. Tokens can be words, parts of words, characters, or punctuation. section 11.4 section 11.9

From characters to tokens

One way to build a vocabulary is byte-pair encoding (BPE). Start by splitting training text into characters and adding an end-of-word marker. Count adjacent token pairs, then merge the most frequent pair into a new token. For example, i followed by n occurs eight times, so it can be merged into in. Repeat the counting and merging to create longer tokens. section 11.9

Table 11.6 The vocabulary based on the training data

ID

Token

 

ID

Token

 

ID

Token

0

a

 

12

o

 

24

th

1

l

 

13

v

 

25

k

2

ic

 

14

er

 

26

,

3

e

 

15

y

 

27

:

4

w

 

16

ti

 

28

c

5

s

 

17

re

 

29

r

6

b

 

18

d

 

30

p

7

g

 

19

f

 

31

u

8

in

 

20

i

 

32

"

9

n

 

21

h

 

33

?

10

ing

 

22

ers

 

 

 

11

t

 

23

on

 

 

 

This example vocabulary pairs IDs with tokens ranging from single characters to pieces such as in, ing, and th. section 11.9

Vocabulary size is the number of distinct tokens in the catalog, not the number of tokens in a particular input. A small training example has 34 tokens in its vocabulary; usable LLMs may have 50,000 to more than 250,000. section 11.11 section 11.9

The vocabulary also shapes the model’s calculations. An embedding matrix maps token IDs to vectors. When predicting the next token, a final layer produces one raw score, or logit, per vocabulary token; softmax converts those scores into probabilities. section 11.14 section 11.29

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Walks through character-based byte-pair merges, token IDs, embedding dimensions, and vocabulary-wide prediction scores.
Examples
Traces merging i and n in training text and lists a 34-token vocabulary with numerical IDs.
What you can do after
Evaluate and understand how token choices and vocabulary size affect text encoding and next-token prediction.
How it connects
Connects tokenization and byte-pair encoding to embeddings, Transformer outputs, logits, and softmax.

Also explained in

Compare how 13 books explain vocabulary →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.