Improving Classifier Robustness through Active Generative Counterfactual Data Augmentation (2023)

Abstract: Counterfactual Data Augmentation (CDA) is a commonly used technique for improving robustness in natural language classifiers. However, one fundamental challenge is how to discover meaningful counterfactuals and efficiently label them, with minimal human labeling cost. Most existing methods either completely rely on human-annotated labels, an expensive process which limits the scale of counterfactual data, or implicitly assume label invariance, which may mislead the model with incorrect labels. In this paper, we present a novel framework that utilizes counterfactual generative models to generate a large number of diverse counterfactuals by actively sampling from regions of uncertainty, and then automatically label them with a learned auxiliary classifier. Our key insight is that we can more correctly label the generated counterfactuals by training a pairwise classifier that interpolates the relationship between the original example and the counterfactual. We demonstrate that with a small amount of human-annotated counterfactual data (10%), we can generate a counterfactual augmentation dataset with learned labels, that provides an 18-20% improvement in robustness and a 14-21% reduction in errors on 6 out-of-domain datasets, comparable to that of a fully human-annotated counterfactual dataset for both sentiment classification and question paraphrase tasks.

## introduction counterfactual data augmentation (cda) has been used to make models robust to distribution shift and mitigate biases towards spuriously correlated attributes. often, counterfactuals are generated as labeled examples through pre-specified templates @xcite or crowd-sourcing @xcite . while natural text templates codify a specific number of assumptions of how counterfactual sentences and labels might vary, crowd-sourcing that can cover various types of counterfactuals, can be expensive. on the other hand, many existing methods @xcite @xcite simply rely on a label-invariance assumption: the label of the generated counterfactual example is the same as the corresponding original example. however, this simple label-invariance assumption does not always hold @xcite @xcite and thus greatly increases the risk of using incorrect labels for counterfactuals during training. for example, for many nlp tasks a small perturbation can easily change the groundtruth label @xcite , e.g., changing the input from this movie is great to this movie is supposed to be great for sentiment classification, or changing the hypothesis from the lady has three children to the lady has many children for natural language inference. therefore, in this work, we mainly focus on addressing this challenging research problem: beyond costly human annotation or simplifying assumptions of label invariance, researchers have explored to use a classifier f that has learnt to predict the label on the original dataset (x, y ). such a classifier has been used to directly label generated examples (our "trust" baseline; @xcite ) or to weight generated examples based on the model uncertainty (our weighted-trust baseline; @xcite ). however, we see that using such simplistic labeling assumptions for counterfactual data augmentation have limited benefits for improving robustness (defined as the accuracy over a counterfactual test set of interest). in this paper we propose an alternative approach to this problem: we leverage the sample efficiency of generative models and exploration capabilities of active learning @xcite to 1) first generate a large number of diverse counterfactuals, and 2) then train an auxiliary classifier to automatically annotate the generated counterfactual data based on the difference between the original and counterfactual labels. specifically, we propose to generate counterfactual examples that lie in the region of uncertainty of the classifier f , and learn a pairwise classifier h to predict the counterfactual label y . the pipeline of our method is shown in figure 1 . in particular, we utilize a very small set of human-annotated counterfactual examples to train the pairwise counterfactual classifier h, which takes in the pair of original and counterfactual sentences (x, c s (x)) and the original label y as input. then in the inference stage, the pairwise counterfactual classifier h is used to predict the labels to produce a large counterfactual augmentation dataset used to fine-tune f to improve robustness. by using active sampling over counterfactual generators and auxiliary pairwise counterfactual classifiers, we show that we greatly reduce the number of counterfactual examples for which we need human annotation, while providing similar gains in robustness comparable to a fully human annotated counterfactual dataset. we attribute this to two core components of our method. first, the activelearning based sampling method helps diversify the types of generated counterfactuals and enables them to capture different robustness issues not previously captured by our classifier model. second, the proposed auxiliary pair-wise classifier can automatically annotate the generated counterfactuals with more accurate labels and help efficiently scale up the size of the counterfactual augmentation dataset. our core contributions in this work include: ## related work our work is built on advances from various domains as outlined below: adversarial text generation training against adversarial examples which perturb inputs in the vicinity of the existing training data by making geometric assumptions @xcite on a lower dimensionality of the data to improve robustness has been extensively studied recently. natural examples which are syntactically and semantically similar to the original sentence, but produce different model predictions have been produced @xcite . similarly, defenses against adversarial attacks on self-attentive models have shown improvement in robustness to label invariant examples @xcite . in fairgan @xcite , they showed it is possible for a discriminator to achieve statistical parity on the real dataset, while performing the auxiliary task of detecting real and generated examples. such controlled adversarial generative approaches @xcite have demonstrated the effectiveness of automating data augmentation in textbased tasks. generative models which optimize for fluency have passed human annotation checks where the model generated text is almost indistinguishable from human generated ones @xcite . we build on this body of work and utilize a generative model @xcite that captures template-based counterfactuals to improve robustness. generic adversar-ial notions of robustness however applicable, fail to incorporate specific counterfactuals directly in their training and orthogonal to our scope of study. through carefully disentangling specific attributes and the rest of the latent variables in text, we generate counterfactuals across all possibilities, and utilize human-annotated templates to label a small fraction of the generated examples to train a pairwise counterfactual classifier. semi-supervised and self-supervised learning labeling functions which provide crude estimates of the label have been used in semisupervised methods @xcite @xcite , and are further used to learn a generative model to generalize over them. further, utilizing unlabeled data @xcite to improve adversarial robustness leverages geometric smoothing-based techniques to bridge the sample complexity gap between accuracy and robustness @xcite . thus, semi-supervised learning approaches aim to generate examples where the discriminator is least confident about @xcite . language models with very large number of parameters have also shown to be few-shot learners with minimal supervision @xcite . similarly, reinforcement learning based approaches with minimal labels have been proposed to combine the objectives of accuracy and counterfactual robustness @xcite . generalization against counterfactual examples by making models not to rely on salient features (easy examples) have been extensively studied by modeling biases in corpora @xcite @xcite @xcite . while the goal in these works have been building ensembles or end-to-end bias mitigation models, our goal is to minimize the number of human labels required to achieve an equivalent improvement in robustness. in this spirit of efficiently capturing the patterns already prevalent in the original dataset, and learning only the new ones introduced in the counterfactual templates, we learn the pairwise counterfactual classifier on a small number of samples, and use it to capture the label variations in the remaining counterfactual dataset. ## methodology problem framing let x, y be the input sentence and its associated label in the original dataset, respectively. we assume @xmath0, 1} throughout the paper (i.e., we focus on binary classification tasks), but our framework can be extended to multi-class tasks as well. our core challenge is what is the true label y for a generated counterfactual x ? although we can further obtain human annotations, this can quickly become time consuming and budget intensive to do at scale. if we make the simplified assumption of label invariance throughout the counterfactual inputs x generated, which is a common assumption in adversarial literature @xcite @xcite , we could end up with an incorrect counterfactual dataset which might hurt robustness and accuracy. our goal is thus, to generate a counterfactual augmentation dataset that produces a comparable improvement in accuracy and robustness as that of human-annotated counterfactuals with minimal supervision. we frame this problem as how to learn when the labels flip, i.e., identifying when the label of the counterfactual is different from the label of the original sentence: p (@xmath1, (0 < δ < 1), in the counterfactual distribution @xmath2. given a generation model c, we denote c s (x) as the generated counterfactual over x by changing an attribute s in x. we also assume that a classifier f : @xmath3, y ) by optimizing for accuracy a. in our paper, the objective is to use the counterfactual data to train a model f that improves robustness, i.e., to make sure the models we trained generalize to unseen scenarios. we measure this by the counterfactual accuracy ã of f on multiple held-out counterfactual datasets (x , y ) split based on domains (ood), patterns (e.g. negation, insertion): in the remainder of this section, we first explain how the counterfactuals are generated using active learning. then, we explain how we account for the possibility that the label of the generated counterfactual c s (x) might have flipped, using a pairwise classifier. finally, we explain how when both these components are combined, we can further improve robustness. ## evaluation we evaluate on two nlp tasks, sentiment classification and question paraphrase, using two datasets namely the stanford sentiment treebank (sst-2) @xcite and the quora question pair (qqp) @xcite . when the capc classifier is used in conjunction with generated examples through active learning, we correspondingly prefix the model name as p-capc (pool-based sampling with no retraining as per eqn 5) or s-capc (examples synthesized with re-generation of counterfactuals optimizing eqn 5). ## conclusion counterfactual data augmentation approaches have been extensively used to train for counterfactual robustness. as the types of counterfactuals -both label-invariant and label-modifying, over which to evaluate natural language models increase, there is a need to adopt a methodology that can scale with increasing types of counterfactuals. we overcome a significant challenge in doing so, by learning an auxiliary pairwise counterfactual classifier that leverages the patterns of counterfactuals produced by vairous generative models. using only a small amount of human annotated counterfactual samples, we demonstrate that our method can produce a dataset that improves counterfactual robustness comparable to a fully human-annotated dataset. in this work, we have demonstrated new methods to safely use more diverse counterfactuals and their value, but in taking on this broader goal, we discover a number of further steps that could take the work further forward. one of the limitations of our paper is that the set of counterfactuals we improved robustness over is limited and restricted to perturbations in the english language. our analysis indicates the value of using more diverse counterfactual types that require a case-by-case contextual understanding. we show that adding more counterfactual types can be done in a sample efficient manner by using a generator trained to produce counterfactuals. however, this still suffers from the limitation that to extend to more counterfactuals and languages, a classifier which labels them by training on a small set of human annotations is required. further, we do not investigate the quality of the counterfactuals annotated, and we do not study the performance using more nuanced counterfactuals with low levels of inter-rater agreement. since we use an auxiliary classifier to label the generated counterfactuals, the risk of label drift remains a clear challenge and we do not control for this label drift based on the certainty of these labels from the auxiliary classifier. further, a natural drift in concepts based on active exploration might render invalid sentences that are not grammatically or semantically correct, and new methods would be needed to filter based on these text patterns. as in other generative models, the risk of perpetuating or amplifying biases in the generated text data continues to be important and while we believe counterfactual generation and augmentation can help address such biases, there is also uncertainty in using more flexible, generated counterfactuals. for example, it is quite possible that one of the generated counterfactuals relies on an identify term in the generated sentence, and attributes a negative sentiment spuriously based on prevalent stereotypes in the text corpus. for this reason, we refer the reader to incorporating bias mitigation strategies like @xcite in addition to improving counterfactual robustness. while we show generalization across label variance in templates, we cannot guarantee that by learning solely on label invariant counterfactuals, a classifier can generalize over label modifying counterfactuals or obtain the same levels of sample efficiency on harder classification tasks. while generators like polyjuice @xcite have been evaluated for fluency, diversity, etc., there is a need to evaluate them within the context of a task and its labels. however, the gains in robustness shown in figure 3 and