Vocabulary Embeddings Take Up Too Much of a Small Model's Parameters: Practical Ways to Freeze and Prune Vocabulary
Small language models under one billion parameters often spend much of their budget on vocabulary embeddings instead of the backbone network. This article explains how to estimate the vocabulary's parameter cost and why it matters most for small models. It covers vocabulary pruning, embedding freezing, weight tying, low-rank factorization, and quantization, and it suggests an order for applying them and checking the results.
Small language models under one billion parameters are becoming capable enough for many everyday tasks. They can handle text classification, summarization, simple question answering, and instruction following. When you deploy these models to on-device hardware, edge nodes, or low-cost inference environments, a structural problem appears quickly: the model’s parameters are not going where you expect.
1. The Root Cause: How Much Weight the Vocabulary Carries
A Transformer-based language model has two main groups of parameters. The first is the backbone network, which includes the attention and feed-forward layers. The second is the vocabulary-related parameters, which consist of the input embedding matrix and the output projection matrix.
The vocabulary parameter count can be estimated with a simple formula:
vocab_params ≈ vocab_size × hidden_dim × 2
Take a common configuration with a vocabulary size of 32,000 and a hidden dimension of 2,048. The embedding and output layers alone need about 32,000 × 2,048 × 2 ≈ 130 million parameters. In a model with 1 billion parameters, the vocabulary accounts for about 13%. In a model with 200 million parameters, the backbone shrinks to about 80 million parameters, and the vocabulary grows to more than 60% of the total.
Multilingual models often use vocabularies of 100,000 or even more than 250,000 tokens to cover more languages. For a small model, most of the parameters then sit in the vocabulary, and the backbone responsible for understanding and reasoning receives too few parameters.
2. Why Large Models Are Unaffected but Small Models Are Not
In models with tens or hundreds of billions of parameters, the same vocabulary cost is only a few percent of the total, so it can be ignored. A small model has a fixed parameter budget, however. Memory on on-device hardware, inference latency, and power consumption all scale directly with parameter count. This creates an asymmetric optimization opportunity:
- For large models, the main optimization target is compute efficiency, such as attention complexity and parallelism strategy.
- For small models, the first priority is a sensible allocation of parameters. The vocabulary is the largest source of waste.
Also, many tokens in a vocabulary are rare words, uncommon character sets, or long-tail subwords. In a specific vertical scenario, such as a Chinese-language customer support bot, around 80% of the vocabulary entries may almost never activate, yet they still occupy memory in full.
3. Technique 1: Vocabulary Pruning
The most direct approach is to prune the vocabulary for a target scenario. The basic process is as follows:
- Corpus statistics: Collect text from the target use case and count how often each token appears.
- Keep the core vocabulary: Keep the high-frequency tokens and the required special tokens, such as the start, end, and padding tokens. A vocabulary of around 30,000 entries can often be reduced to a few thousand.
- Remap indices: Build a mapping between the old and new token IDs, and update the tokenizer’s vocabulary files.
- Rebuild the embedding matrix: Extract the rows for the retained tokens from the original embedding matrix to form a smaller matrix.
Example code:
import torch# old_embed: [V_old, D], keep_ids: list of token indices to keepnew_embed = old_embed.weight[keep_ids].clone()model.get_input_embeddings().weight = torch.nn.Parameter(new_embed)# If the output layer shares weights with the input embedding, it updates automatically.# Otherwise, prune it the same way.
After pruning, the parameter count falls linearly with vocabulary size, and memory use and first-token latency both improve noticeably. You need a fallback strategy for tokens that are missing from the pruned vocabulary, such as mapping them to an unknown token or falling back to byte-level tokens. Without one, the model can produce unpredictable output.
4. Technique 2: Freezing the Vocabulary Embeddings
Another approach is to freeze the embedding layer during downstream fine-tuning and train only the backbone. The reasons are as follows:
- During pretraining, the embedding vectors learn a stable semantic space. Downstream tasks usually do not require large changes to it.
- Small models are often fine-tuned on limited data. Updating hundreds of millions of embedding parameters can lead to overfitting. It can also cause catastrophic forgetting, where gradient noise shifts the vectors of rare tokens.
- When the embedding layer is frozen, the optimizer does not need to store state, such as momentum terms, for it. This can reduce GPU memory use by more than half, which matters for fine-tuning on consumer graphics cards.
The implementation takes one line of code:
for p in model.get_input_embeddings().parameters():p.requires_grad = False
A common combination is to freeze the embeddings and add low-rank adaptation modules to the attention layers. This reduces the trainable parameters to less than 1% of the total, and fine-tuning quality usually drops only slightly.
5. Technique 3: Structural Compression
Besides pruning and freezing, several structural methods are worth knowing:
- Weight tying: The output projection reuses the transpose of the input embedding matrix, which cuts the vocabulary parameters in half. Many small models already do this by default.
- Low-rank factorization: Split the V×D embedding matrix into two smaller matrices, V×r and r×D, where r is much smaller than D. This trades capacity for parameters and suits multilingual scenarios where the vocabulary cannot be pruned.
- Factorized embeddings: Store the vocabulary in a low-dimensional embedding, such as 128 dimensions, then project it up to the hidden dimension. Several well-known lightweight model architectures use this design.
- Quantization: Apply 8-bit or even 4-bit integer quantization to the embedding layer. Embedding lookups are simple table reads, so quantization usually affects accuracy less than quantizing the backbone does.
6. Trade-offs and Recommendations
None of these methods is a silver bullet. Consider the following trade-offs before adopting them:
- Task coverage: Vocabulary pruning suits closed-domain scenarios. Use it with caution for open-domain conversation.
- Reversibility: Freezing and weight tying are reversible. Pruning the vocabulary changes the model structure, so the tokenizer and the inference framework must stay compatible.
- Validation: After any compression, compare perplexity and downstream metrics on an evaluation set for the target task. Do not judge the result only by how much the parameter count fell.
A practical order is to start with weight tying and freezing for lossless compression, then evaluate the gains from vocabulary pruning. Finally, depending on your tolerance for accuracy loss, decide whether to add low-rank factorization or quantization.
Conclusion
Building small models is a matter of careful budgeting under a fixed parameter limit. The vocabulary is the largest hidden share of that budget, and it is both a cost and an opportunity. Combining pruning, freezing, weight sharing, and factorization can free up parameters for the backbone and help models under one billion parameters deliver value on edge devices. Teams building inference services on limited compute can also pair these techniques with general-purpose container platforms, object storage, and monitoring and alerting tools. Together, these form a full pipeline from model compression to production deployment.
