A Survey on Natural Language Counterfactual Generation (2024)

Abstract: Natural language counterfactual generation aims to minimally modify a given text such that the modified text will be classified into a different class. The generated counterfactuals provide insight into the reasoning behind a model’s predictions by highlighting which words significantly influence the outcomes. Additionally, they can be used to detect model fairness issues and augment the training data to enhance the model’s robustness. A substantial amount of research has been conducted to generate counterfactuals for various NLP tasks, employing different models and methodologies. With the rapid growth of studies in this field, a systematic review is crucial to guide future researchers and developers. To bridge this gap, this survey provides a comprehensive overview of textual counterfactual generation methods, particularly those based on Large Language Models. We propose a new taxonomy that systematically categorizes the generation methods into four groups and summarizes the metrics for evaluating the generation quality. Finally, we discuss ongoing research challenges and outline promising directions for future work.

## introduction the recent advancements in natural language processing (nlp) are driven by a variety of large language models (llms), such as gpt-3 (175b) @xcite , palm (540b) @xcite , and gpt-4 (1.7t) @xcite . these llms have demonstrated superior performance on various downstream tasks. however, alongside the performance, there is a rising concern about their occasionally undesired behaviors, like hallucinations in their responses @xcite , and misalignment with human expectations @xcite . these phenomena coincide with the long-standing issue of training deep learning models, which were known to be vulnerable to spurious correlations with artifacts, shortcuts, and biases prevalent in real-world training data @xcite . hence, there is a growing demand for llm explainability to understand model decisions and enhance their robustness, particularly in high-stakes applications. counterfactual generation has emerged as an effective way to probe and understand the reasoning behind the prediction of a model by highlighting which parts of the input influence the outcomes @xcite . it makes minimal modifications to an original instance to create counterfactual examples (cfes) with different predicted classes. cfes can be used to detect model fairness issues within minority groups @xcite , and enhance the robustness and generalizability of the model by augmenting the training dataset @xcite @xcite . in the field of nlp, early studies @xcite were inspired by traditional cfe generators for tabular data. however, due to the vast and discrete perturbation space of each word, directly applying these techniques in the nlp domain becomes less effective and inefficient. additionally, textual cfes should adhere to lexicon and grammar rules, and follow the language context and logic @xcite @xcite . subsequent research has begun to utilize the controlled text generation model to either rewrite a given sentence for the target label @xcite or replace influential words for the current prediction with alternatives for the target prediction @xcite . until recently, the rise of llms has driven researchers to craft sophisticated prompts to obtain cfes on a one-off basis @xcite . as research on textual cfe generation expands rapidly, there is an urgent need for a systematic review specifically dedicated to this domain. however, existing surveys in counterfactual generation primarily focus on tabular data @xcite @xcite @xcite , and fail to offer comprehensive guidelines for researchers and developers within the nlp community. the challenge of reviewing this area arises from the following factors. firstly, the generation methods are inherently tied to the task definitions; different applications such as sentiment analysis and question answering require tailored generation strategies. secondly, the formulation of the generation problem varies depending on the modification strategies and language models chosen. finally, to fully comprehend and evaluate various algorithms, a comprehensive and interdisciplinary understanding that extends beyond nlp to include generative modeling, causality, and ai explanation is essential. this multidisciplinary requirement significantly enhances the complexity and challenge of conducting an exhaustive systematic review. in this survey, we review past research on natural language counterfactual generation and categorize these methods into four groups: (1) manual generation, where a human annotator is asked to edit a limited number of words for a given text to change its label @xcite ; (2) joint learning-based generation involves training an endto-end model that jointly minimizes the desired objectives using gradient descent @xcite ; (3) identify and then generate, a two-stage approach that pinpoints and then substitutes words to alter the labels @xcite @xcite ; and (4) llms prompting, which directly create the counterfactuals via prompting llms @xcite @xcite . we also summarize the qualitative and quantitative metrics used to evaluate the quality of the generated counterfactuals. finally, we discuss the remaining challenges in this field and outline promising research directions, particularly in the era of llms. the rest of this paper is organized as follows: section 2 introduces the definition of cfes and practical considerations during generation. section 3 presents our novel taxonomy and describes each group. section 4 summarizes the metrics used to evaluate generation quality. section 5 discusses ongoing challenges and promising research directions. finally, section 6 concludes the paper. ## definition of counterfactual example in machine learning, a counterfactual example (cfe), was initially proposed to explain model decisions on tabular data @xcite @xcite . cfe explains why the model predicts an instance x as the class y instead of its alternative y ′ by making minimal yet necessary changes to x to obtain the desired change in its prediction. we assume a trained model f : x ⊂ r @xmath0: f (x) = y. y represents a set of discrete labels for a classification task; whereas for a regression task, y denotes a continuous real space. given an input sentence @xmath1, a counterfactual generation method g : f × @xmath2, which alters the model's prediction to a desired class y ′ : f (c) = y ′ , where y ′ ̸ = y. hence, generating counterfactual examples can be achieved by solving the following constrained optimization problem, to concisely define our research scope, we distinguish between two similar yet distinct terms: 'adversarial examples' and 'style transfer', in section a, appendix. this definition outlines the fundamental principles of the cfe generation problem, which can be adapted to a range of nlp tasks by specifying the task-specific x and y ′ . for example, in question answering, the goal is to minimally revise the question x to satisfy a different answer y ′ . in figure 1 , we present examples of counterfactual generation across various nlp tasks. for detailed definition of cfe generation for those nlp tasks, please refer to section b in the appendix. in practice, researchers typically impose various constraints to guide the generation of cfes for specific objectives. below, we outline the commonly accepted desiderata. validity: a cfe is valid if it correctly classified as the desired prediction. optimizing validity will encourages a higher rate of successful label flips. proximity: it is the key constraint to create "close possible worlds" that preserve most of the original content while altering only the critical words to have a different prediction @xcite . diversity: a diverse set of cfes contains multiple possible revisions of a sentence to achieve the target prediction where each revision reveals a different prediction logic. such broad reasoning analysis enhances users' trust in a model's prediction @xcite . a diverse set of cfes also allows us to augment a model training for stronger robustness @xcite . fluency: it measures the smoothness and naturalness of a cfe, similar to plausibility in tabular cfe generation @xcite . encouraging fluency results in texts that are grammatically correct, semantically meaningful, and coherent, which is crucial for ensuring that a textual cfe is understandable. recent research also include desiderata such as controllability @xcite and stability @xcite to better control or stabilize the generation process. however, these desiderata do not directly describe the desired format of the final cfes @xcite . due to page limit, detailed discussion is omitted. ## counterfactual generation methods in this section, we carefully collect 66 studies for textual counterfactual generation. the detailed process of collection is described in section c of appendix. after that, we propose a novel taxonomy that categorizes existing methods into four groups. within each group, we further divide these methods into fine-grained subgroups or successive steps, to ensure that the taxonomy is systematically organized. the full taxonomic structure is shown in figure 4 of the appendix. ## evaluation metrics validity. it measures the proportion of cfes that achieve the desired target among all generated cfes. formally, the validity over n test samples is defined by, similarity. similarity measures the editing effort required of a cfe during generation @xcite , formally defined as, for lexical and syntactic similarity evaluations, widely used methods include the word-level levenshtein edit distance @xcite and the syntactic tree edit distance @xcite . for assessing semantic similarity, models foot_0 like sbert @xcite and the universal sentence encoder (use) @xcite are commonly used. they encode both the cfe and the input text and then calculate the cosine similarity between their sentence representations. diversity. this score is measured as the average pairwise distance between k returned cfes for a sentence x, defined as follows, for lexical diversity, self-bleu @xcite reports the average bleu score between any two cfes, while distinct-n @xcite gauges diversity by calculating the ratio of unique n-grams to the total number of n-grams in the generated cfes. when semantic diversity is assessed, the dist(•) function can be metrics like sbert embedding similarity @xcite , bertscore @xcite , semantic uncertainty @xcite . fluency. as fluency describes the resemblance of a cfe to human writing, a simple measurement is to ask human raters to evaluate a cfe based on cohesiveness, readability, and grammatical correctness @xcite . due to the irreproducibility and high cost of human evaluation, automated fluency evaluations such as the likelihood and the perplexity score have become popular in recent studies @xcite @xcite . model performance. as revision in cfes ideally reveal important features, we can either incorporating cfes into training to enhance model robustness @xcite or leverage cfes as test sets to evaluate existing model's generalization @xcite . researchers then report the classification performance, such as accuracy, f1-score, and the standard deviation of these metrics on outof-domain datasets or counterfactual test sets. the evaluation mentioned above can also be conducted by human evaluators where humans are instructed to rate cfes from various aspects @xcite . in appendix section d, we summarize the commonly used evaluation metrics. additionally, we also list the evaluation metrics used in experiments of each paper in appendix section e. ## challenges and future directions fair evaluation. the absence of ground truth makes it difficult to compare cfes generated from different methods. this challenge arises from two main aspects: (1) existing metrics evaluate cfes from various, often non-comparable perspectives. for example, prioritizing higher proximity (minimal changes to the original text) typically results in lower flip rate. optimizing one metric may compromises another metric, making it difficult to dominate across all metrics and conclusively identify the best method. (2) many methods use filtering techniques to discard undesired results. direct comparisons between filtered and unfiltered cfes may introduce bias in the evaluation process. for instance, methods employing gpt-2 to filter out grammatically incorrect or nonsensical sentences @xcite often outperform those that do not use such filters on fluency score. model privacy and security. privacy and security are crucial considerations in the model development and deployment. as cfes reveal sensitive changes near the decision boundary, researchers exploited cfes to efficiently extract high-fidelity surrogate models @xcite , which poses high risks to model privacy and security. future research should focus on strategies to mitigate model extraction risks while maintaining the utility of cfes. in recent years, there has been an increasing trend toward using llms to generate counterfactuals. following this, we outline and discuss the research challenges associated with prompting llms. ## conclusion in this survey, we systematically review recent advancements, including the latest llm-assisted generation approaches. based on algorithmic differences, we propose a novel taxonomy that categorizes these methods into four groups, providing an in-depth comparison, discussion, and summary for each group. additionally, we summarize the commonly used metrics to evaluate the quality of counterfactuals. lastly, we discuss research challenges and aim to inspire future directions. with the widespread use of black-box llms, issues such as explanations, fairness, and robustness have gained increasing attention. we believe this survey can serve as a comprehensive guideline to inspire future advancements that address these concerns.