Improved Text Classification via Test-Time Augmentation

Helen Lu, Divya Shanmugam, Harini Suresh, John V. GuttagarXiv 2022 · OpenReview

Abstract: Test-time augmentation (TTA)—the aggregation of predictions across transformed examples of test inputs—is an established technique to improve the performance of image classification models. Importantly, TTA can be used to improve model performance post-hoc, without additional training. Although test-time augmentation (TTA) can be applied to any data modality, it has seen limited adoption in NLP due in part to the difficulty of identifying label-preserving transformations. In this paper, we present augmentation policies that yield significant accuracy improvements with language models. A key finding is that augmentation policy design—for instance, the number of samples generated from a single, non-deterministic augmentation—has a considerable impact on the benefit of TTA. Experiments across a binary classification task and dataset show that test-time augmentation can deliver consistent improvements over current state-of-the-art approaches.

Introduction

In computer vision, Test-Time Augmentation (TTA) is often considered a "free lunch" for performance. By applying simple, label-preserving transformations like flips or rotations to an input image and averaging the resulting predictions, models can overcome small spatial biases and produce more robust outputs.

In Natural Language Processing (NLP), however, TTA is significantly more challenging. Language is discrete and fragile; a single word change can invert a sentence's meaning (e.g., "I love this" vs. "I hate this"). Due to the difficulty of identifying transformations guaranteed to preserve labels, TTA has seen limited adoption in text tasks. This research investigates whether specific "augmentation policies" can overcome these hurdles to improve text classification accuracy post-hoc.

Methodology

The study evaluates TTA by taking a pre-trained classifier and a test input, applying various transformations, and averaging the resulting logit predictions. Transformations were sourced from the nlpaug library and categorized into:

  • Character-based: Random insertions, deletions, or substitutions of characters.
  • Word-based: Swapping adjacent words or substituting words with synonyms using databases like WordNet or PPDB (The Paraphrase Database).

Four distinct Policy Configurations were compared to determine the optimal balance of variety and redundancy:

  1. 1-sample, 1-augmentation (1S-1A): A single transformed version.
  2. 1-sample, 4-augmentations (1S-4A): One sample each from four different transformation types.
  3. 4-samples, 1-augmentation (4S-1A): Four different samples generated from the same stochastic (randomized) transformation.
  4. 4-samples, 4-augmentations (4S-4A): A comprehensive approach using 16 total samples (four from each of four transformations).

Dataset

The primary benchmark used was the WILDS CivilComments dataset, comprising 448,000 comments for binary toxicity classification. This dataset is a rigorous real-world benchmark, requiring models to maintain robustness across diverse demographic mentions and varied online commentary styles.

Mechanisms of Success: Corrections vs. Corruptions

A central finding of this work is that individual augmentations often decrease accuracy in isolation. The benefit of TTA arises from the "wisdom of the crowd" effect during aggregation.

Comparison of 1-sample vs. 4-sample augmentation effects on accuracy and the corresponding counts of corrections and corruptions.

When an augmentation "fixes" an incorrect baseline prediction (a correction), other augmented samples tend to agree with that fix. Conversely, when an augmentation "breaks" a correct prediction (a corruption), the resulting errors are typically random and inconsistent. Simple averaging acts as a filter, reinforcing consistent corrections while washing out the noise of random corruptions.

Experimental Results

TTA delivered significant gains on the CivilComments task, improving baseline accuracy from 92.3% to 93.7%. The choice of policy proved critical to these gains.

Accuracy delta across different TTA policy configurations. Note the significant performance jump when moving from 1-sample to 4-sample policies.

As shown in the results, the 4-samples, 1-augmentation (4S-1A) policy was particularly effective. While a single augmented sample (1S-1A) provided negligible gains, moving to multiple samples of the same transform yielded improvements between 0.6% and 0.9% across all word-based policies tested. Interestingly, the most complex policy (4S-4A) only provided a marginal 0.04% improvement over the 4S-1A policy, suggesting that sampling redundancy from a single high-quality transform is the most efficient strategy.

Discussion and Future Work

While TTA offers a training-free performance boost, it introduces computational overhead by multiplying the number of inferences required at test time. Future research may explore more sophisticated aggregation methods beyond simple logit averaging, such as weighted schemes that prioritize more reliable transformation types. Additionally, while word-level synonym substitution proved highly effective for toxicity classification, the label-preserving nature of these transforms may vary across other NLP tasks like sentiment analysis or natural language entailment.

Summary updated

BibTeX
@misc{lu2022improved,
  author = {Helen Lu and Divya Shanmugam and Harini Suresh and John V. Guttag},
  title = {{Improved Text Classification via Test-Time Augmentation}},
  year = {2022},
  eprint = {2206.13607},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2206.13607},
}
Figure