Enhancing textual counterfactual explanation intelligibility through Counterfactual Feature Importance (2023)

Abstract: Textual counterfactual examples explain a prediction by modifying the tokens of an initial instance in order to flip the outcome of a classifier. Even under sparsity constraint, counterfactual generation can lead to numerous changes from the initial text, making the explanation hard to understand. We propose Counterfactual Feature Importance, a method to make non-sparse counterfactual explanations more intelligible. Counterfactual Feature Importance assesses token change importance between an instance to explain and its counterfactual example. We develop two ways of computing Counterfactual Feature Importance, respectively based on classifier gradient computation and counterfactual generator loss evolution during counterfactual search. Then we design a global version of Counterfactual Feature Importance, providing rich information about semantic fields globally impacting classifier predictions. Counterfactual Feature Importance enables to focus on impacting parts of counterfactual explanations, making counterfactual explanations involving numerous changes more understandable.

## introduction the recent development of the transformer architecture @xcite has led to great advances in natural language processing (nlp). the inherent complexity of these widespread black box models comes along with the difficulty to understand their predictions. the field of explainable artificial intelligence (xai) aims to develop methods to interpret and explain such model behaviour @xcite . a first main category of xai methods is called local feature importance. it consists in computing the impact of each input feature in the decision made by the considered machine learning system. a second family explains contrastively by identifying slight perturbations in the initial instance leading to another outcome. such modified instances are called counterfactual examples. when counterfactual examples involve numerous modifications in the initial instance, despite considering sparsity constraints, the identification of important token changes becomes difficult. in this paper we introduce the notion of counterfactual feature importance (cfi), to quantify the impact of each feature modification from an initial instance to its counterfactual example. for example, given a movie genre classifier and a specific counterfactual example provided with a given method, cfi highlights important modifications (see figure 1 ) to explain the label flipping. the main contributions of this paper are summarized as follows: this paper first recalls some basic principles of xai in nlp with a focus on counterfactual generation in section 2. we then formalize the cfi method at a local and global scale and propose two ways of computing cfi in section 3. we finally illustrate the relevance of cfi experimentally on counterfactual examples previously obtained to explain two different classifiers. ## xai background in this section, we recall some basic principles of xai methods and existing counterfactual generation methods in nlp. ## counterfactual feature importance this section introduces the notion of counterfactual feature importance (cfi). we present two instantiations of cfi, based either on gradient computation from the classifier or inherent information from the counterfactual generator initially used. we propose a modelspecific approach based on integrated gradients called ig-cfi and a method-specific one called tigtec-cfi directly resulting from the tigtec loss evolution during counterfactual search. finally we define the notion of global counterfactual feature importance to compute pairwise token importance at a global scale. ## experimental results this section presents the experimental results obtained on two data sets with two binary classifiers. ig-cfi and tigtec-cfi are computed and compared based on two related sets of counterfactual examples generated with tigtec. then we compute g-cfi in order to assess which token pairs impact globally the most these classifiers. ## discussion in this paper we have introduced the concept of counterfactual feature importance in textual framework. the purpose of cfi is to assess the impact of every feature modification, from an initial instance to its counterfactual example. when counterfactual examples are not sparse, cfi highlights important modifications, making the explanation more competitive. cfi can be aggregated at a global scale, giving valuable insights about the most important token pairs to switch label. while cfi-based explanations may appear intuitive, it is important to verify this through a human-in-the-loop evaluation before making any definitive conclusions. cfi can be built in different ways: two approaches have been developed, respectively based on integrated gradients and the tigtec counterfactual generator. we believe that cfi can also be computed in other ways. other local feature importance methods such as lime and shap can be used to compute cfi by computing decomposition difference of x cf from that of x 0 . loss break down from other sequential counterfactual generators such as mice can be used as well. besides, g-cfi can help in comparing textual counterfactual generators. since these generators differ how they target important tokens and generate new text, g-cfi could bring to light differences in the resulting semantic fields. such analyses could lead to a better understanding of textual counterfactual methods and foster their enhancement. finally, the diversity of cfi approaches raises the need of their comparison beyond the similarity analysis performed above. moreover, the qualitative assessment of the explanations provided by cfi requires human intervention. humangrounded experiments would enable to compare the quality of cfi explanations to classical counterfactual examples. ## conclusion textual counterfactual generators sometimes fail to provide sparse explanations. the high number of changed tokens between the initial instance and its counterfactual example make the explanation difficult to understand. we have proposed counterfactual feature importance (cfi) to assess which token changes are the most impactful. cfi enables to focus on important tokens, which is especially useful in the case of non-sparse explanations. such explanations can be aggregated at a global scale in order to assess the most important token pairs leading to label flipping. in this papier we have only focused on counterfactual explanations. however, cfi can also be applied to adversarial attacks in order to evaluate the token changes that have the most impact on label flipping to fool a model. cfi is one step further in the understanding of nlp classifiers. we believe that the concept of cfi is also applicable to image and tabular data, as long as counterfactual explanations are previously generated. therefore, cfi can benefit to any classifier by making counterfactual explanations easier to understand. the generalizability of cfi makes this concept particularly promising. the stronger the link between two tokens, the higher the importance of the pair.