Predict the embedding table parameter count for a 32k vocab at d_model 512
A teammate is sizing a small decoder-only model: vocab_size = 32,000 and d_model = 512, with the output head tied to the input embedding. Predict how many trainable parameters the embedding table contributes.
The embedding table is a matrix of shape vocab times d_model, here 32000 times 512 equals 16,384,000 parameters. Tying the output head reuses the same matrix at zero extra cost.
Imagine a giant dictionary with 32,000 entries, where each entry stores a list of 512 numbers describing that word. The total number of numbers in the dictionary is just the number of rows times the numbers per row, like counting cells in a spreadsheet with 32,000 rows and 512 columns. The model also needs to translate its internal thoughts back into one of those 32,000 words at the end. Instead of building a second dictionary, it reuses the same one in reverse, which is called weight tying. Two jobs, one table, zero extra parameters.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
The embedding table is the entry point of a transformer. Every input token is a lookup into a fixed matrix of shape [vocab_size, d_model], returning one row per token. The output side mirrors this: the final residual stream is multiplied by the transpose of the same matrix (under weight tying) to produce logits over the vocabulary. The parameter count is exactly the product of the two dimensions: 32,000 by 512 in this question, or 16,384,000 parameters.
This is a basic computation, but it surfaces three deeper questions worth understanding: how the embedding fits into the overall parameter budget, why weight tying matters, and when modern large models choose to untie the head despite the cost. The deep dive walks through each.
The takeaway will be that embedding sizing is one of the earliest and most consequential design choices in any decoder architecture. Get it wrong and your model spends most of its budget on a lookup table; get it right and the table becomes a small, fixed cost that scales gracefully as the model grows.
The arithmetic and what it means
The shape. An embedding table is a single 2D parameter matrix E of shape [V, d] where V is the vocabulary size and d is d_model. Each row is the learned representation of one token id. The forward pass for a token at position t is just embedding[t] = E[token_id_t], a row lookup; no matrix multiplication, no activation.
The count. Parameters in E equal V * d. For the question: 32,000 times 512 equals 16,384,000. About 16.4M parameters live in the embedding table.
In context. A small decoder with this vocabulary and d_model might have around 100M parameters total, depending on layer count and FFN expansion. The embedding alone is about 16% of that budget. If you doubled vocabulary to 64k for better tokenization, the embedding would consume 32% of the budget, which is too much. If you instead doubled d_model to 1024, the embedding grows to 32M but the rest of the model grows much faster (FFN goes as d_model squared) so the embedding fraction shrinks.
The right scaling. Vocabulary should be proportional to model size. Small models (under 1B params) use 32k vocabularies. Mid-size models (7B-30B) use 32k-128k. Large models (70B+) use 128k or larger. The cost of a bigger vocabulary in embedding parameters is real but justified at scale because the rest of the model can afford it.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- GPT-2 (vocab 50257, d_model 768) ties embeddings and spends roughly 38.6M of its 124M parameters on the table, about 31% of the budget
- Llama 3 8B (vocab 128k, d_model 4096) does NOT tie embeddings; the embedding plus head together cost roughly 1.05B parameters, about 13% of the 8B total
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does the embedding fraction change if you scale d_model from 512 to 4096 while keeping vocab at 32k?
Embedding scales linearly with d_model, but FFN scales with d_model squared and attention with d_model squared. The embedding fraction shrinks from order 16% at small d_model to single digits or less at d_model in the thousands.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Adding a separate parameter count for the unembedding head, forgetting that weight tying makes input and output share the same matrix.
60 second bullets to scan on the way to the call.
Why the embedding table shape is exactly vocab times d_model
What weight tying does to the head parameter count
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.