TokenMixup: Efficient Attention-guided Token-level Data Augmentation for Transformers

Hyeong Kyu Choi, Joonmyung Choi, Hyunwoo J. Kim

TL;DR

TokenMixup is a novel data augmentation strategy for Vision Transformers that uses internal attention maps as a "free" saliency detector to guide token mixing. By replacing unimportant tokens with salient ones from other images or even previous layers, it achieves a 15x speedup over gradient-based methods and sets a new state-of-the-art for from-scratch models on CIFAR-100.

What Problem Does This Paper Address?

Data augmentation techniques like Mixup (linearly blending two images) and CutMix (pasting a patch from one image onto another) are essential for regularizing deep learning models. However, standard versions are "saliency-blind"—they might mix a background patch of a dog image with a background patch of a cat image, creating a confusing training sample that lacks the actual objects of interest.

While saliency-aware mixup methods exist, they typically rely on computing gradients to find important regions. For parameter-heavy models like Transformers, this extra backpropagation step is computationally expensive and slows down training significantly. The authors of TokenMixup asked: Can we use the Transformer's own internal mechanisms to find salient regions for free?

Methods

The authors propose two primary techniques and a curriculum learning wrapper to optimize the augmentation process.

Horizontal TokenMixup Pipeline
  1. Horizontal TokenMixup (HTM): This mixes tokens between two different images in a batch. Instead of using gradients, it uses the attention map from the subsequent layer as a proxy for saliency. To maximize the information in a batch, they use the Hungarian Matching algorithm to optimally pair images so that the most salient tokens are preserved and the least salient ones are replaced.
  2. ScoreNet & Curriculum Learning: Not all samples should be mixed. The authors introduce ScoreNet, a tiny MLP that estimates the difficulty of a sample. In a curriculum learning fashion, TokenMixup is only applied to "easy" samples that the model already understands well. As training progresses and the model gets better, more samples become "easy," naturally increasing the intensity of the augmentation.
Vertical TokenMixup Architecture
  1. Vertical TokenMixup (VTM): This is a unique intra-sample augmentation. It takes salient tokens from earlier layers and injects them into deeper layers using a cross-attention mechanism. This provides the model with multi-scale feature information, helping it "remember" fine-grained details that might get smoothed out in deeper layers.

Datasets

The researchers evaluated their methods on three standard image classification benchmarks:

  • CIFAR-10 & CIFAR-100: Small-scale datasets often used to test a model's ability to learn from scratch without massive pre-training.
  • ImageNet-1K: The gold standard for large-scale image classification.

Key Insights and Ideas

  • Attention is a "Free" Saliency Map: Transformers are built on attention. The authors realized that the attention weights already highlight what the model thinks is important. Using these weights for augmentation avoids the 15x overhead of gradient-based saliency detection.
  • The Importance of Optimal Pairing: Simply mixing random pairs of images is sub-optimal. By treating image pairing as an optimization problem (solved via Hungarian matching), they ensure that the resulting "mixed" images contain the maximum possible amount of useful information.
  • Curriculum Augmentation: Standard Mixup can sometimes be too difficult for a model to learn from early in training. By using ScoreNet to gate the augmentation, the model "masters the basics" on clean images before being challenged with complex, mixed-up tokens.

Key Results

  • Efficiency: TokenMixup is 15x faster at detecting salient regions than previous gradient-based methods like Co-Mixup.
  • State-of-the-Art (SOTA): On CIFAR-100, using the Compact Convolutional Transformer (CCT) baseline, TokenMixup reached 83.57% accuracy, a new record for models trained from scratch (without pre-training on larger datasets).
  • ImageNet Gains: On ImageNet-1K, adding TokenMixup to a standard ViT-B/16 improved Top-1 accuracy from 81.2% to 82.37%.
  • Ablation Success: The authors showed that every component—ScoreNet, Optimal Assignment, and Saliency-based labeling—contributed significantly to the final accuracy boost.

Limitations and Future Work

  • Parameter Overhead: While efficient, HTM does add a small number of parameters (about 0.7M) due to the ScoreNet and matching logic.
  • Implementation Complexity: Vertical TokenMixup (VTM) requires careful handling of cross-attention across layers, which might be more complex to implement in standard deep learning pipelines compared to simple input-level Mixup.
  • Beyond Vision: The paper focuses entirely on computer vision. A promising future direction would be applying TokenMixup to Natural Language Processing (NLP), where "tokens" are words or sub-words, to see if attention-guided mixing helps in language modeling or translation.

Summary updated

BibTeX
@inproceedings{choi2022tokenmixup,
  author = {Hyeong Kyu Choi and Joonmyung Choi and Hyunwoo J. Kim},
  title = {{TokenMixup: Efficient Attention-guided Token-level Data Augmentation for Transformers}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=EVK_2kdm46},
}
Figure