Learning Dynamic BERT via Trainable Gate Variables and a Bi-modal Regularizer

Seohyeong Jeong, Nojun KwakarXiv 2021

Large-scale language models like BERT have revolutionized Natural Language Processing but remain computationally expensive. Their massive size and high FLOP requirements often make them impractical for deployment on resource-constrained edge devices like smartphones or IoT hardware. While techniques like pruning and knowledge distillation exist, they typically involve complex, multi-stage pipelines. This paper presents a novel "one-stage" method to prune BERT dynamically by learning token redundancy during the fine-tuning process.

The One-Stage Framework

Traditional model compression often requires a separate architecture search followed by a dedicated round of fine-tuning or distillation. The researchers from Seoul National University propose a more streamlined approach where the model learns to be efficient while it is being fine-tuned for a specific task. This dynamic inference model identifies and "turns off" redundant input tokens at each layer, significantly reducing the workload for subsequent attention and feed-forward layers.

Core Methodology: Mask Matching Module

The primary architectural innovation is the Mask Matching Module (MMM), which is placed before each BERT encoder block. The MMM calculates an importance score for each token based on its vector magnitude. These tokens are then sorted and matched against learned "gate" variables (masks). By sorting tokens by importance first, the model learns a robust strategy to keep the "top N" tokens rather than learning masks for specific positions in a sentence.

Figure 3: Comparison between the standard BERT encoder block and the proposed Dynamic BERT block featuring the Mask Matching Module (MMM).

The Power of Polarization

A common pitfall with trainable gates is that they often settle into intermediate "gray areas" (e.g., values around 0.5), which does not result in actual pruning. To solve this, the authors introduced a Bi-modal Regularizer. This customized loss function forces gate variables toward binary states: either 0 (off) or 1 (on). This polarization is essential; ablation studies showed that without it, performance on tasks like SST-2 drops significantly (from 92.1 to 76.0).

Figure 6: Distribution of mask values across layers on the SST-2 dataset. The right column demonstrates how the bi-modal regularizer successfully polarizes values toward 0 and 1.

Key Results and Insights

The model was rigorously evaluated on the GLUE (General Language Understanding Evaluation) benchmark. Key findings include:

  • Efficiency: The model achieved an average of 3x fewer FLOPs across tasks. In specific cases like CoLA, the speedup reached as high as 4.13x.
  • Accuracy: The performance impact was minimal. For example, on SST-2 sentiment analysis, accuracy only dipped slightly from 93.5% to 92.8% despite the 3x speedup.
  • Controllability: A user-specified sparsity hyperparameter ($\gamma$) acts as a "knob," allowing engineers to trade off performance for speed based on their specific hardware needs.

Conclusion

This work provides a practical, one-shot solution for slimming down BERT. By integrating token pruning directly into fine-tuning through the Mask Matching Module and ensuring clear decision-making with a bi-modal regularizer, Dynamic BERT offers a powerful balance between high-quality NLP and the efficiency required for real-world deployment.

Summary updated

BibTeX
@misc{jeong2021learning,
  author = {Seohyeong Jeong and Nojun Kwak},
  title = {{Learning Dynamic BERT via Trainable Gate Variables and a Bi-modal Regularizer}},
  year = {2021},
  eprint = {2102.09727},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2102.09727},
}
Figure