Exploring the Efficacy of Automatically Generated Counterfactuals for Sentiment Analysis (2021)

Abstract: While state-of-the-art NLP models have been achieving the excellent performance of a wide range of tasks in recent years, important questions are being raised about their robustness and their underlying sensitivity to systematic biases that may exist in their training and test data. Such issues come to be manifest in performance problems when faced with out-of-distribution data in the field. One recent solution has been to use counterfactually augmented datasets in order to reduce any reliance on spurious patterns that may exist in the original data. Producing high-quality augmented data can be costly and time-consuming as it usually needs to involve human feedback and crowdsourcing efforts. In this work, we propose an alternative by describing and evaluating an approach to automatically generating counterfactual data for the purpose of data augmentation and explanation. A comprehensive evaluation on several different datasets and using a variety of state-of-the-art benchmarks demonstrate how our approach can achieve significant improvements in model performance when compared to models training on the original data and even when compared to models trained with the benefit of human-generated augmented data.

## introduction deep neural models have recently made remarkable advances on sentiment analysis @xcite @xcite . however, their implementation in practical applications still encounters significant challenges. of particular concern, these models tend to learn intended behavior that is often associated with spurious patterns (artifacts) @xcite . as an example, in the sentence "nolan's films always shock people, thanks to his superb directing skills", the most influential word for the prediction of a positive sentiment should be "superb" instead of "nolan" or "film". the issue of spurious patterns also partially affects the out-ofdomain (ood) generalization of the models trained on independent, identical distribution (iid) data, leading to performance decay under distribution shift @xcite @xcite . researchers have recently found that such concerns about model performance decay and social bias in nlp come about out-of-domain because of a sensitivity to semantically spurious signals @xcite , and recent studies have uncovered a problematic tendency for gender bias in sentiment analysis @xcite @xcite . to this end, one of the possible solutions is data augmentation with counterfactual examples @xcite to ensure that models learn real causal associations between the input text and labels. for example, a sentiment-flipped counterfactual of last example could be "nolan's movies always bore people, thanks to his poor directorial skills.". when added to the original set of training data, such kinds of counterfactually augmented data (cad) have shown their benefits on learning real causal associations and improving the model robustness in recent studies @xcite @xcite . unlike gradient-based adversarial examples @xcite @xcite , which cannot provide a clear boundary between positive and negative instances to humans, counterfactuals could provide "human-like" logic to show a modification to the input that makes a difference to the output classification @xcite . recent attempts for generating counterfactual examples (also known as minimal pairs) rely on human-in-the-loop systems. @xcite proposed a human-in-the-loop method to generate cad by employing human annotators to generate sentiment-flipped reviews. the human labeler is asked to make minimal and faithful edits to produce counterfactual reviews. similarly, @xcite presented a framework to leverage strong prior (human) knowledge to understand the possible distribution shifts for a specific machine learning task; they use human commonsense reasoning as a source of information to build a more robust model against spurious patterns. although useful for reducing sensitivity to spurious correlations, collecting enough high-quality human annotations is costly and time-consuming. the theory behind the ability of cad to improve model robustness in sentiment analysis is discussed by @xcite , where researchers present a theoretical characterization of the impact of noise in causal and non-causal features on model generalization. however, methods for automatically generating cad have received less attention. the only existing approach @xcite has been tested on the logistic regression model only, despite the fact that recent state-of-the-art methods for sentiment classification are driven by neural models. also, their automatically generated cad cannot produce competitive performance compared to human-generated cad. we believe that their method does not sufficiently leverage the power of pre-trained language models and fails to generate fluent and effective cad. in addition, the relationships between out-of-domain generalization and sensitivity to spurious patterns were not explicitly investigated by @xcite . to address these issues, we use four benchmark datasets (imdb movie reviews as hold-out test while amazon, yelp, and twitter datasets for outof-domain generalization test) to further explore the efficacy of cad for sentiment analysis. first, we conduct a systematic comparison of several different state-of-the-art models @xcite . this reveals how large transformerbased models @xcite with larger parameter sizes may improve the resilience of machine learning models. specifically, we have found that for increasing parameter spaces, cad's per-formance benefit tends to decrease, regardless of whether cad is controlled manually or automatically. second, we introduce a novel masked language model for helping improve the fluency and grammar correctness of the generated cad. third, we add a fine-tuned model as a discriminator for automatically evaluating the edit-distance, using data generated with minimal and fluent edits (same requirements for human annotators in @xcite ) to ensure the quality of generated counterfactuals. experimental results show that it leads to significant prediction benefits using both hold-out tests and generalization tests. to the best of our knowledge, we are the first to automatically generate counterfactuals for use as augmented data to improve the robustness of neural classifiers, which can outperform existing, state-ofthe-art, human-in-the-loop approaches. we will release our code and datasets on github foot_0 . ## related work this work mainly touches on three important areas: approaches to evaluation that go beyond traditional accuracy measures @xcite , the importance of counterfactuals in explainable ai (xai) (byrne, 2019; keane and smyth, 2020), and out-of-domain generalization in sentiment analysis @xcite @xcite . there has been an increasing interest in the role of robustness causal thinking in ml, often by leveraging human feedback. recently, some of the standard benchmark datasets have been challenged @xcite , in which the model performance is significantly lower on contrast sets than on original test sets; a difference of up to 25% in some cases. researchers propose counterfactual data augmentation approaches for building robust models @xcite @xcite , and find that spurious correlations threaten the model's validity and reliability. in an attempt to address this problem, @xcite explore opportunities for developing human-in-the-loop systems by using crowd-sourcing to generate counterfactual data from original data, for data augmentation. @xcite shows the continuous effectiveness of cad in computer vision (cv) and nlp. original dataset identify causal terms with mlm classifiers sentiment dictionary hierarchical rm-ct hierarchical rep-ct moverscore moverscore is used to control the minimal edits of the automatically generated counterfactuals classifiers counterfactually augmented dataset original dataset sampled data points human annotators human-generated counterfactuals the approved counterfactual is added to the original dataset our method kaushik, hovy, and lipton (2020) wang and culotta (2021) original dataset identify likely causal features replace causal features with antonyms based on pydictionary original dataset classifiers counterfactually augmented dataset our method sentiment dictionary hierarchical rm-ct hierarchical rep-ct identify causal terms with scd moverscore classifiers moverscore is used to control the minimal edits of the automatically generated cad. figure 1: overview of previous cad methods are shown on the left side, while the pipeline of our method is shown on the right. hierarchical rm-ct (removing the casual terms) and hierarchical rep-ct (replacing the casual terms) are our methods for automatically generating cad, respectively. scd denotes sampling and sensitivity of contextual decomposition. sentiment dictionary refers to the opinion lexicon published by (hu and liu, 2004). also shares important conceptual features with our work. since human counterfactual explanations are minimal in the sense that they select a few relevant causes (byrne, 2019; keane and smyth, 2020) as is the requirement of minimal edits in our generation process. this has been explored more in the field of cv (goyal et al., 2019; kenny and keane, 2021), but investigated less in nlp. recent work (jacovi and goldberg, 2020) highlight explanations of a given causal format, and yang et al. (2020a) generate counterfactuals for explaining the prediction of financial text classification. we propose a similar but different research question, that is, whether the automatically generated counterfactual can be used for data augmentation to build more robust models, which has not been considered by the previous methods in xai @xcite @xcite . in the case of sentiment analysis, most of the previous works report experiments using a holdout test on the iid dataset @xcite @xcite . the current stateof-the-art methods make use of large pre-trained language models (e.g., bert @xcite , roberta @xcite and smart-roberta @xcite ) for calculating input represntations. it has been shown that these methods can suffer from spurious patterns @xcite . very recently, wang and culotta (2021) provide a starting point for exploring the efficacy of automatically generated cad for sentiment analysis, but it is still based on iid hold-out tests only. however, spurious patterns in the training and test sets could be tightly coupled, which may limit the possibility of observing their attendant accuracy issues using a hold-out test methodology. for this reason, we designed an indirect method for evaluating the robustness of models, by comparing the performance of models trained on original and augmented data using out-of-domain data. the prediction benefit for out-of-domain data should provide some evidence about whether a model's sensitivity to spurious patterns has been successfully mitigated. the resulting counterfactuals can be used for data augmentation and can also provide contrastive explanations for classifiers, and important and desirable consideration for the recent move towards more xai @xcite @xcite @xcite . ## detailed implementation we propose a new approach for automatically generating counterfactuals to enhance the robustness of sentiment analysis models by inverting the sentiment of causally important terms according to algorithm 1 and based on the following stages: the end result will be a set of counterfactuals that can be used to augment an existing dataset. ## datasets our evaluation uses three different kinds of datasets, in-domain data, challenge data, and outof-domain data. ## results and discussions we first describe the performance of the current state-of-the-art methods on sentiment analysis based on the sst-2 and imdb benchmark datasets. next, we will discuss the performance benefits by using our automatically generated counterfactuals on an in-domain test. we further compare our method, human-label method, and two state-of-theart style-transfer methods @xcite in terms of the model robustness on generalization test. notably, we provide an ablation study lastly to discuss the influence of edit-distance for performance benefits. ## conclusion we proposed a new framework to automatically generate counterfactual augmented data (cad) for enhancing the robustness of sentiment analysis models. by combining the automatically generated cad with the original training data, we can produce more robust classifiers. we further show that our methods can achieve better performance even when compared to models trained with humangenerated counterfactuals. more importantly, our evaluation based on several datasets has demonstrated that models trained on the augmented data (original & automatic cad) appear to be less af-fected by spurious patterns and generalize better to out-of-domain data. this suggests there exists a significant opportunity to explore the use of the cad in a range of tasks (e.g., natural language inference, natural language understanding, and social bias correction.).