Introduction
The advent of BERT and similar Transformer-based models has revolutionized Natural Language Processing (NLP). However, these models are notoriously resource-intensive, posing significant challenges for deployment on edge devices like smartphones. A major contributor to this "memory tax" is the embedding matrix, which accounts for over 21% of the parameters in BERT-base. While knowledge distillation is a standard technique for model compression, it typically requires the student and teacher models to share the same vocabulary. This constraint limits the potential for extreme compression, as the vocabulary size remains fixed at around 30,000 tokens.
Methodology: Mixed-Vocabulary Training
To overcome the vocabulary bottleneck, we introduce Mixed-Vocabulary Training, a novel distillation framework that allows for a significant reduction in vocabulary size (e.g., from 30,000 to 5,000 words). This approach consists of two primary stages:
Stage I: Student Embedding Initialization
In this stage, the large teacher BERT model is retrained using a "mixed" input. Sequences are tokenized using both the teacher’s large vocabulary and the student’s proposed small vocabulary. By forcing the teacher to predict student tokens within its existing high-level context, the student's smaller embedding matrix effectively "absorbs" the teacher's linguistic knowledge. To bridge the gap between different vector dimensions (e.g., 768 for the teacher vs. 256 for the student), a trainable linear projection layer is employed.
Stage II: Student Model Training
Once the small embeddings are initialized and aligned with the teacher's latent space, the actual student model—featuring fewer layers and smaller hidden dimensions—is trained using only the student vocabulary.
Experimental Results
The proposed method was evaluated on standard NLP benchmarks (GLUE) and real-world edge applications (SNIPS).
Performance on GLUE Benchmarks
Our 6-layer distilled model, with only 6.2M parameters, demonstrates competitive performance against much larger models. As shown in the comparison table below, the mixed-vocab distilled models significantly outperform "NoKD" (No Knowledge Distillation) baselines of the same size and achieve results comparable to models with many more parameters.
Edge Efficiency and Accuracy
On the SNIPS intent detection task, the 6.2M parameter model retained over 95% of the performance of the original BERT-base model. Crucially, the model achieved a latency of just 6ms on a Pixel 4 smartphone, representing a 56x speedup over the 340ms latency of BERT-base.
Key Insights
- Vocabulary Compression: Shrinking the vocabulary from 30,000 to 5,000 is the most effective lever for compressing models to under 10MB.
- Information Density: A well-trained 5,000-word vocabulary is sufficiently dense for most common language tasks; increasing the size to 7,000 or 10,000 yielded diminishing returns.
- Data Efficiency: The tiny models performed exceptionally well on smaller datasets like MRPC, suggesting they may be less prone to overfitting than their larger counterparts.
Conclusion
Mixed-vocabulary training provides a powerful path toward extreme model compression. By decoupling the student vocabulary from the teacher, we can produce tiny, edge-ready models that maintain high accuracy while drastically reducing memory footprint and latency. This approach is orthogonal to other compression techniques and can likely be combined with them for even greater efficiency gains.
Summary updated