MASKER: Masked Keyword Regularization for Reliable Text Classification

Seung Jun Moon, Sangwoo Mo, Kimin Lee, Jaeho Lee, Jinwoo Shin

Abstract

Pre-trained language models have achieved state-of-the-art accuracies on various text classification tasks, e.g., sentiment analysis, natural language inference, and semantic textual similarity. However, the reliability of the fine-tuned text classifiers is an often underlooked performance criterion. For instance, one may desire a model that can detect out-of-distribution (OOD) samples (drawn far from training distribution) or be robust against domain shifts. We claim that one central obstacle to the reliability is the over-reliance of the model on a limited number of keywords, instead of looking at the whole context. In particular, we find that (a) OOD samples often contain in-distribution keywords, while (b) cross-domain samples may not always contain keywords; over-relying on the keywords can be problematic for both cases. In light of this observation, we propose a simple yet effective fine-tuning method, coined masked keyword regularization (MASKER), that facilitates context-based prediction. MASKER regularizes the model to reconstruct the keywords from the rest of the words and make low-confidence predictions without enough context. When applied to various pre-trained language models (e.g., BERT, RoBERTa, and ALBERT), we demonstrate that MASKER improves OOD detection and cross-domain generalization without degrading classification accuracy.

Introduction

Pre-trained language models (PLMs) like BERT and RoBERTa have set new benchmarks in text classification. However, their reliability is often compromised by shortcut bias. During fine-tuning, these models tend to over-rely on a limited number of domain-specific keywords to make predictions, effectively ignoring the broader context. This creates two major failure modes: poor out-of-distribution (OOD) detection, where models confidently misclassify samples containing familiar keywords, and poor cross-domain generalization, where models fail when specific keyword shortcuts are absent.

Methodology: MASKER

The authors propose MASKER (Masked Keyword Regularization), an unsupervised debiasing method integrated into the fine-tuning phase. MASKER consists of three primary steps designed to shift the model's focus from keywords to context.

1. Keyword Selection

The first step involves identifying the keywords that act as shortcuts. The authors compared frequency-based selection (e.g., TF-IDF) with attention-based selection. They found that using attention weights from a vanilla-trained model identifies more generalizable and informative keywords compared to simple frequency statistics.

Comparison of frequency-based vs. attention-based keyword selection. Attention-based selection identifies more generalizable terms.

2. Masked Keyword Reconstruction (MKR)

In this step, the identified keywords are masked in the input text. The model is then tasked with reconstructing these missing keywords using the surrounding context. This forces the model to learn the semantic relationships between keywords and their context, rather than treating keywords as isolated signals.

3. Masked Entropy Regularization (MER)

To prevent the model from making high-confidence predictions based solely on keywords, MER introduces "cut-out-context" samples where non-keyword words are removed. The model is regularized to output a uniform distribution (maximum entropy) for these samples, teaching it that keywords alone are insufficient for a reliable prediction.

The Masked Entropy Regularization (MER) process forces the model to output a uniform distribution when context is removed.

Experimental Results

MASKER was evaluated across several standard NLP benchmarks to test OOD detection and cross-domain robustness.

  • OOD Detection Improvements: When applied to BERT, MASKER improved the Area Under the ROC Curve (AUROC) from 87.0% to 98.6% on the 20 Newsgroups to SST-2 task.
  • Cross-Domain Generalization: MASKER significantly reduced the generalization gap. For example, when training on Amazon Fine Food reviews and testing on IMDB, the gap shrank from 19.2% to 10.9%.
  • Accuracy Preservation: Unlike many debiasing methods that degrade standard performance, MASKER maintained or slightly improved in-distribution classification accuracy across all tested models.

Conclusion

MASKER effectively mitigates shortcut bias by encouraging context-based prediction. By forcing models to reconstruct keywords from context and penalizing high-confidence predictions when context is missing, it enhances both OOD detection and cross-domain generalization. While currently limited to classification tasks and requiring a two-stage training process for attention-based selection, MASKER provides a robust framework for building more reliable language models.

Summary updated

Abstract

Pre-trained language models have achieved state-of-the-art accuracies on various text classification tasks, e.g., sentiment analysis, natural language inference, and semantic textual similarity. However, the reliability of the fine-tuned text classifiers is an often underlooked performance criterion. For instance, one may desire a model that can detect out-of-distribution (OOD) samples (drawn far from training distribution) or be robust against domain shifts. We claim that one central obstacle to the reliability is the over-reliance of the model on a limited number of keywords, instead of looking at the whole context. In particular, we find that (a) OOD samples often contain in-distribution keywords, while (b) cross-domain samples may not always contain keywords; over-relying on the keywords can be problematic for both cases. In light of this observation, we propose a simple yet effective fine-tuning method, coined masked keyword regularization (MASKER), that facilitates context-based prediction. MASKER regularizes the model to reconstruct the keywords from the rest of the words and make low-confidence predictions without enough context. When applied to various pre-trained language models (e.g., BERT, RoBERTa, and ALBERT), we demonstrate that MASKER improves OOD detection and cross-domain generalization without degrading classification accuracy. Code is available at https://github.com/alinlab/MASKER.
BibTeX
@inproceedings{moon2021masker,
  author = {Seung Jun Moon and Sangwoo Mo and Kimin Lee and Jaeho Lee and Jinwoo Shin},
  title = {{MASKER: Masked Keyword Regularization for Reliable Text Classification}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2021},
  url = {https://openreview.net/forum?id=HafZDBASGM9},
}
Figure