Token Masking Improves Transformer-Based Text Classification

Xianglong Xu, John Bowen, Rojin Taheri
5/16/2025
cs.CLcs.AI

No confident code implementation found for this paper.

Abstract

While transformer-based models achieve strong performance on text classification, we explore whether masking input tokens can further enhance their effectiveness. We propose token masking regularization, a simple yet theoretically motivated method that randomly replaces input tokens with a special [MASK] token at probability p. This introduces stochastic perturbations during training, leading to implicit gradient averaging that encourages the model to capture deeper inter-token dependencies. Experiments on language identification and sentiment analysis -- across diverse models (mBERT, Qwen2.5-0.5B, TinyLlama-1.1B) -- show consistent improvements over standard regularization techniques. We identify task-specific optimal masking rates, with p = 0.1 as a strong general default. We attribute the gains to two key effects: (1) input perturbation reduces overfitting, and (2) gradient-level smoothing acts as implicit ensembling.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{xu2025token,
  title  = {Token Masking Improves Transformer-Based Text Classification},
  author = {Xianglong Xu and John Bowen and Rojin Taheri},
  year   = {2025},
  eprint = {2505.11746},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2505.11746v1}
}

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

Discussion