Understanding the Failure of Batch Normalization for Transformers in NLP

Jiaxi Wang, Ji Wu, Lei Huang
10/11/2022
cs.CLcs.LG
transformer-attention

Official code: wjxts/RegularizedBN (22 stars, Python, GPL-3.0, last commit 2022-12-30).

Abstract

Batch Normalization (BN) is a core and prevalent technique in accelerating the training of deep neural networks and improving the generalization on Computer Vision (CV) tasks. However, it fails to defend its position in Natural Language Processing (NLP), which is dominated by Layer Normalization (LN).

Show full abstract

In this paper, we are trying to answer why BN usually performs worse than LN in NLP tasks with Transformer models. We find that the inconsistency between training and inference of BN is the leading cause that results in the failure of BN in NLP. We define Training Inference Discrepancy (TID) to quantitatively measure this inconsistency and reveal that TID can indicate BN's performance, supported by extensive experiments, including image classification, neural machine translation, language modeling, sequence labeling, and text classification tasks. We find that BN can obtain much better test performance than LN when TID keeps small through training. To suppress the explosion of TID, we propose Regularized BN (RBN) that adds a simple regularization term to narrow the gap between batch statistics and population statistics of BN. RBN improves the performance of BN consistently and outperforms or is on par with LN on 17 out of 20 settings, involving ten datasets and two common variants of Transformer Our code is available at https://github.com/wjxts/RegularizedBN.

View on arXivView PDF

Code Implementations(1)

GPL-3.0
221Python, CudaSep 27, 20223 years agoGPL-3.0

Similar Papers

Cite this paper

@article{wang2022understanding,
  title  = {Understanding the Failure of Batch Normalization for Transformers in NLP},
  author = {Jiaxi Wang and Ji Wu and Lei Huang},
  year   = {2022},
  eprint = {2210.05153},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2210.05153}
}

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/2210.05153.svg)](https://codeofpaper.com/paper/2210.05153)

Discussion