Improving BERT Fine-tuning with Embedding Normalization

Wenxuan Zhou, Junyi Du, Xiang Ren · DOI

TL;DR

This paper identifies a problem with how BERT's [CLS] token embeddings are used during fine-tuning: they can be "biased" (non-zero centered and concentrated on a few dimensions), leading to unstable training and degraded performance. The authors propose simple normalization techniques for these embeddings, which significantly improve performance on various text classification tasks.

What Problem Does This Paper Address?

Large pre-trained language models like BERT have revolutionized NLP by allowing us to fine-tune them for specific downstream tasks. A common practice for sequence classification is to take the final embedding of the special [CLS] token and feed it into a task-specific classifier. However, the authors observe that these [CLS] embeddings, as output by BERT after its pre-training phase, often exhibit a "biased distribution." This means the values tend to cluster around certain dimensions and are not centered around zero. This bias can cause problems during fine-tuning: gradients during backpropagation can become unstable, potentially exploding and hindering the model's ability to learn effectively, ultimately degrading performance. The paper aims to understand this bias and propose a solution to mitigate its negative effects.

Methods

The core of the paper's contribution lies in its analysis of the [CLS] embedding bias and the proposed normalization methods.

  1. Analysis of Bias: The authors systematically analyze the [CLS] embeddings from BERT on several sequence classification datasets. They visualize these distributions and examine the average values of each embedding dimension, confirming the presence of non-zero centering and concentrated values.
  2. Proposed Normalization: To address the identified bias, the authors propose applying simple normalization techniques to the [CLS] embeddings during the fine-tuning process. They explore three methods:
  3. Z-normalization: This standard technique rescales the embeddings to have a mean close to 0 and a standard deviation close to 1 for each dimension, based on the statistics of the entire training dataset.
  4. Min-Max Normalization: This method linearly transforms each dimension of the embedding to a specific range (e.g., -1 to 1), ensuring all dimensions are on a similar scale and preventing extreme values.
  5. L2 Normalization: This technique constrains the L2 norm of each embedding to an average value of 1, aiming to prevent large embedding values that could lead to exploding gradients.

Crucially, the normalization statistics (like mean and standard deviation) are computed on the training set and then applied to both training and prediction phases. The pre-trained BERT model's parameters are updated during fine-tuning, but the normalization statistics themselves are kept fixed.

Datasets

The paper uses several standard datasets for evaluation:

  • GLUE Benchmark: The authors evaluate their methods on four tasks from the General Language Understanding Evaluation (GLUE) benchmark:
  • MRPC (Microsoft Research Paraphrase Corpus)
    • RTE (Recognizing Textual Entailment)
    • SST-2 (Stanford Sentiment Treebank v2)
    • COLA (Corpus of Linguistic Acceptability)
  • Additional GLUE Datasets: They also conduct experiments on MNLI (Multi-Genre Natural Language Inference) and QNLI (Question Natural Language Inference) for further validation.

Key Insights and Ideas

  • The [CLS] token isn't inherently "perfect" for downstream tasks: While BERT's pre-training (NSP and MLM) is powerful, the resulting [CLS] embedding might carry inductive biases or distributions that aren't optimal for all downstream classification tasks.
  • Embedding bias is a real problem for fine-tuning: The non-zero-centered and concentrated nature of [CLS] embeddings can lead to unstable gradients, making optimization harder and potentially causing performance degradation. This is analogous to why careful initialization is crucial when training models from scratch.
  • Simple normalization can be surprisingly effective: The paper demonstrates that straightforward techniques like Z-normalization, Min-Max normalization, and L2 normalization, applied to the [CLS] embedding, can significantly improve fine-tuning performance.
  • L2 Normalization shows the most consistent gains: Among the proposed methods, L2 normalization appears to be the most robust and effective across the tested tasks.

Key Results

The paper reports consistent improvements when using their normalization methods compared to standard fine-tuning with BERT-base.

  • BERT-base: L2 normalization consistently improved performance across MRPC, RTE, and SST-2. For example, on RTE, L2 normalization achieved 72.4% accuracy compared to BERT-base's 71.1%.
  • BERT-large-wwm: L2 normalization also provided benefits, though the gains were less pronounced than with BERT-base.
  • Additional Datasets: L2 normalization also showed improvements on MNLI and QNLI.

Limitations and Future Work

  • Limitations: The authors note that while L2 normalization is generally effective, Min-Max and Z-normalization sometimes yielded worse results. They hypothesize this might be due to these methods amplifying noise when dimensions have very small variance, suggesting that careful selection of the epsilon parameter ($\epsilon$) could mitigate this. They also mention that the normalization statistics are fixed during fine-tuning, which might be a simplification.
  • Future Work: The authors suggest applying their normalization methods to more datasets and other pre-trained encoders like RoBERTa and XLNet. They also propose exploring more normalization techniques.

Summary updated

Abstract

Large pre-trained sentence encoders like BERT start a new chapter in natural language processing. A common practice to apply pre-trained BERT to sequence classification tasks (e.g., classification of sentences or sentence pairs) is by feeding the embedding of [CLS] token (in the last layer) to a task-specific classification layer, and then fine tune the model parameters of BERT and classifier jointly. In this paper, we conduct systematic analysis over several sequence classification datasets to examine the embedding values of [CLS] token before the fine tuning phase, and present the biased embedding distribution issue---i.e., embedding values of [CLS] concentrate on a few dimensions and are non-zero centered. Such biased embedding brings challenge to the optimization process during fine-tuning as gradients of [CLS] embedding may explode and result in degraded model performance. We further propose several simple yet effective normalization methods to modify the [CLS] embedding during the fine-tuning. Compared with the previous practice, neural classification model with the normalized embedding shows improvements on several text classification tasks, demonstrates the effectiveness of our method.
BibTeX
@misc{zhou2019improving,
  author = {Wenxuan Zhou and Junyi Du and Xiang Ren},
  title = {{Improving BERT Fine-tuning with Embedding Normalization}},
  year = {2019},
  eprint = {1911.03918},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1911.03918},
}
Figure