AdapLeR: Speeding up Inference by Adaptive Length Reduction

Ali Modarressi, Hosein Mohebbi, Mohammad Taher Pilehvar · DOI

Abstract

Large-scale pre-trained language models like BERT have revolutionized natural language processing but remain computationally expensive to deploy. While existing methods focus on reducing model depth or distilling knowledge into smaller architectures, they often treat all inputs with the same computational budget. This paper introduces AdapLeR (Adaptive Length Reduction), a novel framework that speeds up inference by dynamically identifying and pruning unimportant tokens as they pass through the model's layers. By utilizing small "Contribution Predictors" trained on gradient-based saliency, AdapLeR achieves significant speedups—up to 22x on specific classification tasks—with minimal loss in accuracy.

Introduction

The high latency and memory requirements of models like BERT pose significant challenges for real-time applications and edge device deployment. Traditional efficiency methods, such as distillation or early exiting, are largely static or focus on the "depth" of the model. However, many NLP tasks do not require the full context of every token in a sequence to reach a correct conclusion. For example, a sentiment analysis model might only need a few key adjectives to classify a review accurately.

AdapLeR addresses this by focusing on "width reduction." It recognizes that for many tasks, the importance of specific tokens varies across layers. By pruning redundant tokens on the fly, the model reduces the total number of operations performed, leading to faster inference times that adapt to the complexity of the input text.

The AdapLeR Framework

The core innovation of AdapLeR is the Contribution Predictor (CP). A small Multi-Layer Perceptron (MLP) is integrated into each encoder layer to estimate the importance of every token representation.

Saliency-Based Supervision

Unlike previous methods that rely on raw attention weights—which can often be misleading indicators of importance—AdapLeR uses gradient-based saliency. During the training phase, the model calculates how much each token actually influences the final output. The CPs are then trained to mimic these saliency scores, ensuring that the tokens kept are those that truly contribute to the model's decision-making process.

Dynamic Pruning and Soft-Removal

At inference time, if a token's predicted contribution score falls below a user-defined threshold ($\delta$), it is dropped from the sequence. This results in progressively shorter sequences as data moves deeper into the model. To ensure the process is differentiable during training, the authors employ a "soft-removal" function. This function gradually masks out less important tokens, allowing the model to learn the optimal trade-off between performance and speed through standard backpropagation.

Protecting the [CLS] Token

The [CLS] token, which serves as the aggregate representation for classification, is treated as a special case. Because it initially lacks context, its saliency may start low. AdapLeR protects the [CLS] token from pruning and uses a trainable parameter ($\theta$) to allow it to "absorb" the importance of tokens that are removed, preserving the global context needed for the final prediction.

Experimental Evaluation

The authors evaluated AdapLeR across eight diverse text classification benchmarks, including sentiment analysis (SST-2, IMDB), topic classification (AG’s News), and natural language inference (MNLI, QNLI).

Performance and Speed

AdapLeR consistently outperformed existing state-of-the-art length reduction methods such as PoWER-BERT and TR-BERT. Key results include:

  • DBpedia: Achieved a 22.23x speedup while maintaining 98.9% accuracy (a negligible drop from the baseline 99.3%).
  • AG’s News: Achieved a 17.1x speedup. Qualitative analysis revealed the model could often identify topics like "Sports" by retaining only a single relevant token (e.g., "soccer") in the final layers.
  • Efficiency on Simple Inputs: Because the pruning is dynamic, the model naturally spends more computation on difficult, ambiguous sentences while quickly discarding "fluff" in simpler ones.

Alignment with Human Rationales

Using the ERASER benchmark (Movie Reviews and MultiRC), the authors compared AdapLeR’s token selection against human-annotated rationales. The results showed that AdapLeR’s selected tokens align much more closely with human judgment than attention-based methods. Specifically, the model demonstrated a significantly lower False Positive Rate, indicating it is highly selective about which tokens it deems necessary.

Conclusion and Future Work

AdapLeR demonstrates that adaptive length reduction is a highly effective strategy for accelerating BERT inference. By moving beyond static architectures and focusing on token-level saliency, it provides a granular way to manage the speed-accuracy trade-off.

While currently optimized for classification tasks and single-batch inference, future work could extend this method to sequence-to-sequence tasks like Question Answering. Additionally, combining AdapLeR’s "width-based" reduction with "depth-based" methods like early exiting could lead to even more efficient, multi-dimensional adaptive inference engines.

Summary updated

BibTeX
@inproceedings{modarressi2022adapler,
  author = {Ali Modarressi and Hosein Mohebbi and Mohammad Taher Pilehvar},
  title = {{AdapLeR: Speeding up Inference by Adaptive Length Reduction}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2022},
  url = {https://openreview.net/forum?id=BclsD7QCC3},
}
Figure