Accelerating BERT Inference for Sequence Labeling via Early-Exit

Xiaonan Li, Yunfan Shao, Tianxiang Sun, Hang Yan, Xipeng Qiu +1 more
5/28/2021
cs.CLcs.AI

Official code: LeeSureman/Sequence-Labeling-Early-Exit (28 stars, Python, last commit 2022-08-19).

Abstract

Both performance and efficiency are crucial factors for sequence labeling tasks in many real-world scenarios. Although the pre-trained models (PTMs) have significantly improved the performance of various sequence labeling tasks, their computational cost is expensive.

Show full abstract

To alleviate this problem, we extend the recent successful early-exit mechanism to accelerate the inference of PTMs for sequence labeling tasks. However, existing early-exit mechanisms are specifically designed for sequence-level tasks, rather than sequence labeling. In this paper, we first propose a simple extension of sentence-level early-exit for sequence labeling tasks. To further reduce the computational cost, we also propose a token-level early-exit mechanism that allows partial tokens to exit early at different layers. Considering the local dependency inherent in sequence labeling, we employed a window-based criterion to decide for a token whether or not to exit. The token-level early-exit brings the gap between training and inference, so we introduce an extra self-sampling fine-tuning stage to alleviate it. The extensive experiments on three popular sequence labeling tasks show that our approach can save up to 66%-75% inference cost with minimal performance degradation. Compared with competitive compressed models such as DistilBERT, our approach can achieve better performance under the same speed-up ratios of 2X, 3X, and 4X.

View on arXivView PDF

Code Implementations(1)

Code for ACL 2021 paper: Accelerating BERT Inference for Sequence Labeling via Early-Exit

281PythonMay 18, 20214 years ago

Similar Papers

Cite this paper

@article{li2021accelerating,
  title  = {Accelerating BERT Inference for Sequence Labeling via Early-Exit},
  author = {Xiaonan Li and Yunfan Shao and Tianxiang Sun and Hang Yan and Xipeng Qiu and Xuanjing Huang},
  year   = {2021},
  eprint = {2105.13878},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2105.13878}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2105.13878.svg)](https://codeofpaper.com/paper/2105.13878)

Discussion