4.2.4 · D3Tokenization & Language Modeling

Worked examples — Vocabulary size tradeoffs

3,494 words16 min readBack to topic

This page is a drill hall. The parent note built the two cost formulas — embedding table size and attention cost. Here we throw every kind of case at those formulas until none can surprise you.

Before we start, let us re-anchor the two tools so no symbol is used unearned.

The single most important sign-of-life fact: embedding cost grows with (a fixed one-time price), attention cost grows with (a per-batch, per-use price). Every example below is really asking "which side of this seesaw tips?"


The scenario matrix

Every problem this topic can ask lands in one of these cells. The worked examples afterward each carry a tag [Cell X] telling you which one it fills.

Cell Case class What makes it tricky
A Plain embedding-table sizing Just — but watch units (M vs B params)
B Plain attention memory sizing The scalar-vs-vector trap (do NOT multiply by )
C Breakeven: small vs large vocab Compare permanent params against accumulated batch savings
D Degenerate low end: byte-level, Tiny table, huge — attention blows up
E Degenerate high end: whole words Short , giant table, rare-token starvation
F Zero / limiting input Empty text (), one-token text,
G Real-world word problem Multilingual / domain, must choose a number
H Exam twist A hidden wrong assumption you must catch

We cover A through H across 9 examples: A (Ex 1), B (Ex 2), C (Ex 3), D (Ex 4), E (Ex 5), F (Ex 6), G (Ex 7 — with its geometric figure), the U-shaped seesaw synthesis (Ex 8), and H (Ex 9).


The examples


Recall Self-test

Attention score memory carries the dimension. True or false? ::: False — scores are scalars; only projections carry . Doubling sequence length changes attention cost by what factor? ::: (it scales as ). Embedding table size depends on the text being processed. ::: No — it is , fixed by vocab and width, independent of any input. Why does a bigger vocab not proportionally shorten sequences? ::: Average token length grows only sublinearly with . In the U-shaped total-cost curve, what lives on the two arms? ::: Rising arm = embedding cost (); falling arm = attention cost (). When you compare a fixed param cost to a per-batch activation cost, what must you do first? ::: Convert both to the same unit (bytes), since params and activation scalars are only comparable once counted in bytes.

See also: Vocabulary size tradeoffs · 4.3.01-Transformer-attention-complexity · 4.5.02-Embedding-layer-design · 5.1.03-Memory-optimization-techniques · 4.2.04 Vocabulary size tradeoffs (Hinglish)