{'fraction_non_alphanumeric': 0.031046530093695412, 'fraction_numerical': 0.008377004922979197, 'mean_word_length': 4.7001584068793845, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
A Model-Agnostic SAT-based Approach for Symbolic Explanation Enumeration

In this paper titled A Model-Agnostic SAT-based approach for Symbolic Explanation Enumeration we propose a generic agnostic approach allowing to generate different and complementary types of symbolic explanations. More precisely, we generate explanations to locally explain a single prediction by analyzing the relationship between the features and the output. Our approach uses a propositional encoding of the predictive model and a SAT-based setting to generate two types of symbolic explanations which are Sufficient Reasons and Counterfactuals. The experimental results on image classification task show the feasibility of the proposed approach and its effectiveness in providing Sufficient Reasons and Counterfactuals explanations.


Introduction
Modern machine learning (ML) and deep learning methods are nowadays widely used in many sensitive fields and industries. However, despite the good predictive performance of the ML models, there are critical applications that fundamentally require trust like applications applied to medicine, driverless cars and law enforcement. Therefore, it becomes increasingly important to explain the behavior of those models and their output to enhance trust in the model predictions and their adoption in real world applications. This leads to a rapid growth in attention to eXplainable AI (XAI). The XAI methods can be grouped into premodel (ante-hoc), in-model, and post-model (post-hoc) methods. In the latter, we identify two types of explanations: (1) symbolic (knowledge-driven) methods that are based on logical representations used for explanation (e.g. [28], [16]), verification and diagnostic purposes (e.g. [23], [26], [16]), and (2) numerical featurebased methods that provide insights into how much each feature contributed to that outcome (e.g. SHAP [20], LIME [24]). The main limitation to the existing explainability methods based on symbolic representations is the fact that they are generally intended to specific models and cannot be applied to any model arXiv:2206.11539v2 [cs.AI] 15 Aug 2022 (non agnostic). In the other hand, feature-based methods such as LIME [24] and SHAP [20] try to assess the amount of contribution of features into the predictions but fail at answering certain questions such as What are the feature values which are sufficient in order to trigger the prediction whatever the values of the other variables ? or Which values are sufficient to change in the instance x to have a different prediction ? To address the problem of answering this type of fundamental questions, we propose in this paper an approach to provide "different" and "complementary" types of symbolic explanations: the Sufficient Reasons (SRx for short) and the Counterfactuals (CF x for short). The main advantage of our approach is the fact of being model-agnostic, where we try to learn accurate yet simple models to emulate the given black-box. In the other hand, the approach is based on rigorous and well-known Boolean satisfiability concepts that allow us to exploit the availability of efficient SAT solvers. Accordingly, our approach is declarative and does not require the implementation of specific algorithms. We evaluate the feasibility and efficiency of our approach on image classification task.

Preliminaries and notations
We first introduce the necessary notations and recall some definitions used in the remainder of this paper. For the sake of simplicity, we will limit the presentation to binary classifiers with binary features. We also focus only on negative predictions where the outcome is 0. As for explaining positive predictions where the outcome is 1, the approach applies similarly as discussed in the Conclusion. A decision function describes the classifier's behavior independently from the way it is implemented. We define it as a function f : X → Y mapping each instantiation x of X to y=f (x). A data instance x is the feature vector associated with an instance of interest whose prediction from the ML model is to be explained. We use interchangeably in this paper f to designate the classifier and its decision function. Let us now define the representation framework we use. Definition 2. (SAT : The Boolean Satisfiability problem) Usually called SAT, the Boolean satisfiability problem is the decision problem, which, given a propositional logic formula, determines whether there is an assignment of propositional variables that makes the formula true.
The logic formulas are built from propositional variables and Boolean connectors "AND" (∧), "OR" (∨), "NOT" (¬). A formula is satisfiable if there is an assignment of all variables that makes it true. It is said inconsistent or unsatisfiable otherwise. A complete assignment of variables making a formula true is called a model while a complete assignment making it false is called a countermodel. Definition 3. (CNF (Clausal Normal Form)) is a set of clauses seen as a conjunction. A clause is a formula composed of a disjunction of literals. A literal is either a Boolean variable p or its negation ¬p. A quantifier-free formula is built from atomic formulae using conjunction ∧, disjunction ∨, and negation ¬. An interpretation µ assigns values from {0, 1} to every Boolean variable. Let Σ be a CNF formula, µ satisfies Σ iff µ satisfies all clauses of Σ.
Thanks to the achievements that the SAT field had known in the recent years, the modern SAT solvers 1 have gained in performance and efficiency where they can handle now problems with several million clauses and variables. Recall that we use a SAT oracle to generate our formal symbolic explanations. We encode the explanation generation problem as two common problems related to SATsolving which are enumerating minimal reasons why a formula is inconsistent and minimal changes to a formula in order to restore its consistency. Indeed, in the case of an unsatisfiable CNF, we can analyze the inconsistency by enumerating sets of clauses causing the inconsistency (called Minimal Unsatisfiable Subsets (MUS)), and other sets of clauses allowing to restore its consistency (called Minimal Correction Subsets (MCS)). The enumeration of MUS/MCS are well-known problems dealt with in many areas such as knowledge-base reparation. Several approaches and tools have been proposed in the SAT community for their generation (e.g [19], [9]).

Related Works
Explaining machine learning systems has been a hot research topic recently. There has been hundreds of papers on ML explainability but we will be focusing on the ones closely related to our work. In the context of model-agnostic explainers where the learning function of the input model and its parameters are not known (black-box), we can cite some post-hoc explanations methods such as: LIME (Local Interpretable Model-agnostic Explanations) [24] which explain black-box classifiers by training an interpretable model g on samples randomly generated in the vicinity of the data instance. We follow an approach similar to LIME, the difference is that we encode our surrogate model into a CNF to generate symbolic explanations. The authors in [25] proposed a High-precision model agnostic explanations called ANCHOR. It is based on computing a decision rule linking the feature space to a certain outcome, and consider it as an anchor covering similar instances. Something similar is done in SHAP (SHapley Additive exPlanations) [20] that provides explanations in the form of the game theoretically optimal called Shapley values. Due to its computational complexity, other model-specific versions have been proposed for linear models and deep neural networks (resp LinearSHAP and DeepSHAP) in [20]. The main difference with this rule sets/feature-based explanation methods is that we propose symbolic explanations using a formal method based on the logical representation of a model, and we use a substitution approach to make the model method agnostic.
Recently, some authors propose symbolic and logic-based XAI approaches that can be used for different purposes [7]. We can distinguish the compilationbased approaches where Boolean decision functions of classifiers are compiled into some symbolic forms. For instance, in [5,28] the authors showed how to compile the decision functions of naive Bayes classifiers into a symbolic representation, known as Ordered Decision Diagrams (ODDs). We proposed in a previous work [4] an approach designed to equip such symbolic approaches [28] with a module for counterfactual explainability. There are some ML models whose direct encoding into CNF is possible. For instance, the authors in [22] proposed a CNF encoding for Binarized Neural Networks (BNNs) for verification purposes. In [27], the authors propose a compilation algorithm of BNNs into tractable representations such as Ordered Binary Decision Diagrams (OB-DDs) and Sentential Decision Diagrams (SDDs). The authors in [29] proposed algorithms for compiling Naive and Latent-Tree Bayesian network classifiers into decision graphs. In [2], the authors dealt with a set of explanation queries and their computational complexity once classifiers are represented with compiled representations. However, the compilation-based approaches are hardly applicable to large sized models, and remain strongly dependent on the type of classifier to explain (non agnostic). Our approach can use those compilation algorithms to represent the whole classifier when the encoding remains tractable, but in addition, we propose a local approximation of the original model using a surrogate model built on the neighborhood of the instance at hand.
Recent works already address the enumeration of symbolic explanations using linear programming, mixed-integer programming, or SMT solvers. Authors in [16,15,21] deal with some explanations referred to as abductive explanations (AXp) and contrastive explanations (CXp) using SMT oracles and cover the enumeration of so-called generalized explanations. The work presented in [13] is about duality of abductive and contrastive explanations and their enumeration. In [12], the authors explain the prediction of decision list classifiers using a SATbased approach. Explaining random forests and decision trees is dealt with for instance in [2] and [14,17] respectively. The main difference with our work is that we propose a surrogate-based approach where we directly relate explanations with the notions of MCS and MUS in a Partial MaxSAT setting. This allows obtaining explanations thanks to the use of off-the-shelf tools for enumerating MCS and MUS.

Overview of the proposed approach
The objective of our approach is explaining the prediction made by a classifier for a given input data instance x. It associates a logical representation that is almost equivalent to the decision function of the model to explain. Figure 1 represents an overview of the proposed approach.
Given a predictive model f , our approach proceeds as follows: -Step 1 (CNF encoding of the classifier): the goal is to encode f into an equivalent symbolic representation Σ f . The generation of symbolic explana- The SAT solving is already used for providing some forms of symbolic explanations for some specific ML [4,12,18]. The novelty in our approach is the fact of being model-agnostic and succeeding in generating formal explanations based on rigorous concepts.

CNF encoding of classifiers
The starting point of our approach is the encoding of the input ML model f into a logical representation (CNF). This step is necessary in order to use a SAT oracle for the enumeration of the symbolic explanations. Mainly, two cases are considered: (1) an encoding of classifier f into an equivalent logical representation exists, in which case we can use it (e.g. Binarized Neural Networks (BNNs) [22], Naive and Latent-Tree Bayesian network [29]). (2) We consider the classifier f as a black-box and we use a surrogate model approach to approximate it in the vicinity of the instance to explain x (Agnostic option). The surrogate models are used to explain individual predictions of black-box ML models.
We set the focus on the agnostic option in this paper. This latter is applied when no direct CNF encoding exists for f or if the encoding is intractable.
Surrogate model encoding into CNF The approach proposed uses a surrogate model mainly characterized by its faithfulness to the initial model f (ensures same predictions) and its tractable logical representation (CNF). To ensure the local faithfulness to f , we use a surrogate model f S trained on data instances in the vicinity of the data instance x whose prediction from the model needs to be explained. We construct the vicinity of x noted V (x, r) by sampling new data instances within a radius r of x if the dataset is available 2 . A model that can guarantee a good trade-offs between faithfulness and giving a tractable CNF encoding is the one of random forests [10]. As shown in our experimental study, the random forest accuracy reflects a good level of faithfulness and its CNF encoding size remains tractable. The CNF encoding f S of a classifier f should guarantee the equivalence of the two representations stated as follows : Definition 4. (Equivalence of a classifier and its CNF encoding) A binary classifier f (resp. f S ) can be equivalently encoded as a CNF Σ f (resp. Namely, data instances x predicted positively (f (x)=1) by the classifier are models of the CNF encoding the classifier. Similarly, data instances x predicted negatively (f (x)=0) are countermodels of the CNF encoding the classifier.

CNF encoding of random forests
In this work, we adopted the random forest 3 as the surrogate model f S . Its associated CNF encoding resumes in i) encoding the decision trees individually and then ii) encoding the combination rule (which is a majority voting rule).
Encode in CNF every decision tree : Remember that all the features in our case are binary. Thus, each internal node of a decision tree DT i represents a binary test on one of the features. The result of a test is either true or false. For the leaves of a decision tree, each one is annotated with the predicted class (namely, 0 or 1). The Boolean function encoded by a decision tree can be captured in CNF as the conjunction of the negation of paths leading to leaves labelled 0.
Encode in CNF the combination rule : Let y i be a Boolean variable capturing the truth value of the CNF associated to a DT i . Hence, the majority rule used in random forests to combine the predictions of m decision trees can be seen as a cardinality constraint 4 [30] that can be stated as follows : where t is a threshold (usually t= m 2 ). To form the CNF corresponding to the entire random forest, it suffices to conjuct the m CNFs associated to the decisions trees, and, the CNF of the combination rule.

Generating symbolic explanations
This section will cover the presentation of both Sufficient Reasons and Counterfactuals explanations as well as the SAT-based setting we use to generate such explanations. This corresponds to Step 2 within the Fig.1. This step takes as input the CNF encoding of a classifier Σ f and a sample data instance Σ x .

A SAT-based setting for the enumeration of explanations
We propose two complementary types of symbolic explanations: the Sufficient Reasons which are a minimal subset of the input data, that if fixed, lead to a given prediction and the Counterfactuals which are a minimal subset of the input data that we can act on to obtain a different outcome. The enumeration of those symbolic explanations in our approach is based on two very common concepts in SAT which are MUS and MCS (defined formally in the following). We use a variant of the SAT problem called Partial-Max SAT [3] in order to restrict the explanations only to clauses encoding the input data x and do not include clauses that encode the classifier f . The Partial-Max SAT problem can be efficiently solved by the existing tools implementing the enumeration of MUSes and MCSes such as the tool in [8]. It is composed of two disjoint sets of clauses where Σ H denotes the hard clauses (those that could not be relaxed) and Σ S denotes the soft ones (those that could be relaxed). Concretely in our approach, the set of hard clauses corresponds to Σ f and the soft clauses to Σ x . The CNF Σ x encoding the data instance x is formed by unit clauses where each clause α ∈ Σ x is composed of exactly one literal (∀α ∈ Σ x , |α| = 1) and each literal representing a Boolean variable of Σ x corresponds to a Boolean variable {X i ∈ X} where X is the feature space of f . Thanks to this Partial-MAX SAT setting, it is possible to both identify the subsets of Σ x responsible for the unsatisfiability of a given CNF Σ f ∪Σ x (corresponding to SRx of f (x)=0), and the subsets allowing to restore the consistency of Σ f ∪Σ x (corresponding to CF x allowing to change the prediction to f (x)=1).

Sufficient Reason Explanations (SR x )
We are trying to find explanations that identify the relevant variables that could justify why the prediction is negative. This is carried out by identifying a subset of our input which causes the inconsistency of the CNF formula Σ f ∪Σ x (recall that the prediction f (x) is captured by the truth value of Σ f ∪Σ x ). The identified subsets of the input x represent Sufficient Reasons for the prediction to be negative. We formally define the Sufficient Reasons explanations as follow: (SR x explanations) Let x be a data instance and f (x)=0 its prediction by the classifier f . A sufficient reason explanationx of x is such that: ∀x,x ⊂x : f (x)=f (x) (x suffices to trigger the prediction) 3. There is no partial instancex ⊂x satisfying 1 and 2 (minimality) Intuitively, a sufficient reasonx is defined as the part of the data instance x such thatx is minimal and causes the prediction f (x)=0. Namely, to explain the classification it is "sufficient" to observe those features with disregard to the others. We define now the Minimal Unsatisfiable Subsets : A MUS for Σ f ∪Σ x comes down to a subset of soft clauses, namely a part of x that is causing the inconsistency, hence the prediction f (x)=0.
Proposition 1. Let f be a classifier, let Σ f be its CNF representation. Let also x be a data instance predicted negatively (f (x) = 0) and Σ f ∪Σ x the corresponding Partial Max-SAT encoding. Let SR(x, f ) be the set of Sufficient Reasons of x wrt. f . Let MUS(Σ f,x ) be the set of MUses of Σ f ∪ Σ x . Then: Proposition 1 states that each MUS of the CNF Σ f ∪Σ x is a Sufficient Reason for the prediction f (x)=0 and vice versa.

Counterfactual Explanations (CF x )
We are also interested in another type of explanation which would allow us to figure out what changes can be made to the input data in order to alter the initial outcome. Let us formally define the concept of counterfactual explanation.

Definition 7.
(CF x Explanations) Let x be a complete data instance and f (x) its prediction by the decision function of f . A counterfactual explanationx of x is such that: In definition 7, the term x[x] denotes the data instance x where variables included inx are inverted. In our approach, Counterfactuals are enumerated thanks to the Minimal Correction Subset enumeration [8].
Following our modeling, an MCS for Σ f ∪Σ x comes down to a subset of soft clauses denotedx, namely a part of x that is enough to remove (or reverse) in order to restore the consistency, hence to alter the prediction Proposition 2. Let f be the decision function of the classifier, let Σ f be its CNF representation. Let also x be a data instance predicted negatively (f (x) = 0) and Σ f ∪Σ x the corresponding Partial Max-SAT encoding. Let CF x(x, f ) be the set of counterfactuals of Proposition 2 states that each MCS of the CNF Σ f ∪Σ x represents a CF x⊆x for the prediction f (x)=0 and vice versa.

Empirical evaluation
Experimentation set-up The black-box models considered are "one-vs-all" binary neural networks (BNNs) 5 trained on the widely used MNIST database 6 . MNIST is composed of 70,000 images of size 28 × 28 pixels. We use the pytorch implementation 7 of the Binary-Backpropagation algorithm "BinaryNets" [11] to train the BNN classifiers (one per digit from 0 to 9) on the binarized images (threshold T = 127). All experiments have been conducted on Intel Core i7-7700 (3.60GHz ×8) processors with 32Gb memory on Linux.
Results The surrogate model considered is a random forest (RF) classifier trained on the vicinity of the input sample using the hyper-parameters nb trees = 10 and max depth = 24. We try out different values for the radius r but we only present the results for r = 250 with an average of 200 neighbors around x due to the limited number of pages. The black-box models (BNNs) trained to recognize the "0","2","5","6" and "8" digits are used as predictive models 8 . Around 1000 to 1500 images were picked randomly from the MNIST database for the experimental study conducted on each classifier. 5 defined as a neural networks with binary weights and activations at run-time 6 MNIST: handwritten digit databse, available at http://yann.lecun.com/exdb/mnist/ 7 available at: https://github.com/itayhubara/BinaryNet.pytorch 8 results for the other digits are similar but not be reported because of space limitation Evaluating the CNF encoding in practice : We are interested in evaluating the size of the CNF encoding using the setting mentioned above. We use the Tseitin Transformation [31] to encode the propositional formulae into an equisatisfiable CNF formulae. The size of this latter is linear in the size of the original formulae. The results are presented in Table 1. The high accuracy of f S shows that the generated RF classifier provide interesting results in term of fidelity. The number of variables/clauses of the CNF indicates that the logical representation remains tractable and makes the logical representation easily handled by the current SAT-solvers which confirms the feasibility of the approach.  Evaluating the feasibility of the enumeration of explanations : We want to assess the practical feasibility of the enumeration of Sufficient Reasons and Counterfactual explanations. To enumerate the CF x, we use the EnumELSRM-RCache tool 1 with a timeout set to 600s. Thanks to the duality between MUSes and MCSes, the enumeration of SRx can be done by computing the minimal hitting set of CF x. However, the results in this paper only cover the enumeration of CF x due to the page limitation. In Table 1, we report the average runtime (enumtime) needed to enumerate all the explanations within the timeout whereas in reality the solver manages to find explanations instantly in the majority of cases. Accordingly, the enumeration time remains reasonable and shows the practical feasibility of the enumeration of such explanations for medium size classifiers (like the BNNs used). Additionally, we notice that the number of CF x enumerated is significant and that it quickly becomes unmanageable for a user to process the result. This reinforces the need for quality metrics to filter the generated explanations. SR x and CF x for MNIST : We use the "one-vs-all" BNN f 8 trained to recognize the eight "8" digit (positive prediction for an image representing "8", negative otherwise) that has achieved an accuracy of 97%. Fig.2 shows a few data samples negatively predicted by f 8 . Heatmaps in the 3 rd column of Fig.2 show examples of CF x highlighting the necessary changes to be made on the input data sample in order to alter the outcome of f 8 from negative to positive. We can visually distinguish a sort of pattern of the digit "8" highlighting the pixels we need to act on. This actually matches the definition of CF x. Although the underlying mechanisms of our approach and SHAP differ which may lead to very different explanations for the same input, we can see that our explanations are visually simpler, clearer and easier to understand and use compared to SHAP explanations in the last column.

Concluding remarks and Discussions
We try to explain individual outcomes of black-box models by the mean of a novel model agnostic generic approach presented within this paper in order to provide two complementary types of explanations: Sufficient reasons and Counterfactuals. The approach is based on the Boolean satisfiability concepts which allow us to take advantage of the strengths of already existing and proven solutions, and the powerful practical tools for the generation of MCS/MUS. We use the notion of surrogate model to overcome the complexity of encoding a ML classifier into an equivalent logical representation. It is a local encoding since we approximate the original model in the vicinity of the sample of interest. The same mechanism is used to explain positively predicted instances. It suffices to work with the negation of the representation of f (¬f ) to enumerate the explanations in a similar way. We intend in future works to assess the relevance of explanations and features individually w.r.t a set of properties allowing to evaluate explanations in ways that are closer to how users consume them.