March 06, 2023
The proliferation of deep neural networks in various domains has seen an increased need for the interpretability of these models, especially in scenarios where fairness and trust are as important as model performance. A lot of independent work is being carried out to: i) analyze what linguistic and non-linguistic knowledge is learned within these models, and ii) highlight the salient parts of the input. We present NxPlain, a web application that provides an explanation of a model’s prediction using latent concepts. NxPlain discovers latent concepts learned in a deep NLP model, provides an interpretation of the knowledge learned in the model, and explains its predictions based on the used concepts. The application allows users to browse through the latent concepts in an intuitive order, letting them efficiently scan through the most salient concepts with a global corpus-level view and a local sentence-level view. Our tool is useful for debugging, unraveling model bias, and for highlighting spurious correlations in a model. A hosted demo is available here: https://nxplain.qcri.org1
Interpretation of deep neural networks (DNNs) has gained a lot of attention in recent years, especially in NLP, where state-of-the-art models are being widely deployed and used in practice. Work done in interpretation can be broadly classified into two branches: i) representation analysis and ii) attribution analysis. The former attempts to understand what knowledge is learned within the representation [1], [2] and the latter is focused on how the model predicts the output [3]–[5].3
Figure 1: Examples of Latent Concepts.. a — Terms used in hate-speech against immigration policies, b — Syntactic concept of hyphenated words, c — Concept made up of numbers, d — Lexical concept (hyphenation) representing ages, e — Morphological concept (adjectives with common suffix est signifying superlative adjectives, f — Named entities in Germany
A drawback of the methods in representation analysis is that it does not gauge whether the model uses what it has learned in making a prediction. On the other hand, the drawback of attribution analysis is that their explanations are limited to discrete units (e.g. words, some specific piece of the network), and the abstract nuances behind these discrete units are lost in the explanation, resulting in an inadequate or implausible explanation. Some efforts have been made in trying to connect representation and attribution analysis [9], [10].
In this work, we present NxPlain, a web-app that provides a holistic view by combining representation and attribution analysis. More specifically, we discover latent concepts in the model using the Latent Concept Analysis [11] and connect these concepts to specific predictions using Integrated Gradients [12], a model and input saliency method.
NxPlain allows the users to:
Discover latent concepts in transformers [13] models via an interactive GUI
Align the concepts using human-defined ontologies and task specific concepts
Explain predictions using saliency-based attributions and extracted latent concepts
The analysis presented by NxPlain can enable a practitioner to understand a trained model better and be aware of the kinds of concepts a model is using to perform its tasks. For example, the word immigrant can appear as part of a neutral concept (if the model clusters it with other "roles" related to a person’s status like "non-immigrant", "resident", etc), or it can appear as part of a negative concept (if the model clusters it with other hate-speech related terms like "alien", "illegal" etc.) as in Figure 1. Understanding which of these categorizations a model is learning and relying on can be a strong signal of the underlying biases of the model. A more benign example of debugging would also be able to see a purely lexical concept being used for prediction (say words ending in "y"), when the lexical property should not have any bearing on the task at hand. The target users for our system can be broadly divided into two categories: i) researchers/practitioners who want to understand their model better, and ii) other systems that want to use the concepts extracted by NxPlain to better explain predictions to their customers.
The overall system behind the NxPlain application is split into three distinct components. See Figure 2 for a pictorial representation.
Backend: This part of the app integrates the pipeline, which handles i) extraction of latent concepts, ii) computation of various orderings, and iii) computation of the concepts relevant to particular
sentences etc. A database is used to store all of the computed results so that the other two components can then use these results.
Rest API: This piece displays the results from the Backend in an organized and machine-readable fashion. Users can use this to access the latent concepts and their relevant metadata for their
applications.
Frontend: This is the primary user-facing module of the app, and runs in a Web browser. The frontend provides an easy to use the graphical interface to add models to the computation queue and retrieve the
extracted concepts once they are ready. Figure 4 shows the Model Explanations page, where one can browse all the extracted concepts, sort them according to various criteria and analyze the knowledge
learned in the selected model.
For extracting the concepts, we use the code provided by [11]. We then tag the input corpus with various human-defined tagsets such as Parts-of-Speech and Semantic tags, and align the latent concepts with these, as done by [14]. The results are then stored in a database, and retrieved later via a Python server implemented using Flask. The backend exposes a Rest API which can be used as-is by users in their own applications. We also provide an Angular frontend app that uses the Rest API to present the concepts in a GUI. For sentence-level explanations, we use the [15] tookit’s Integrated Gradients implementation to perform attribution analysis.
The NxPlain application provides an easy interface to analyze the latent knowledge learned within a deep NLP model, as well as connect these latent concepts to specific predictions. In order to do this, the pipeline in the
Backend relies on three key components proposed by recent literature: i) concept discovery, ii) concept alignment, and iii) attribution analysis.
The first component, responsible for extracting the latent concepts learned by a model is based on work done by , called Latent Concept Analysis. At a high level, feature vectors (contextualized representations) are first generated by performing a forward pass on the model. These representations are then clustered using agglomerative hierarchical clustering [16] to discover the encoded concepts. The hypothesis is that contextualized word representations learned within pretrained language models capture meaningful groupings based on a coherent concept such as lexical, syntactic and semantic similarity, or any task or data specific pattern that groups the words together [11]. Figure 1 shows example concepts discovered in the model space of a base and finetuned BERT model. The concepts discovered are a mix of linguistic, lexical and semantic concepts.
The second component uses an alignment framework proposed by to align each of the latent concepts to some pre-existing ontology like part-of-speech, semantic tags, WordNet etc. This enables richer explanations for the latent concepts, and also allows for the application to sort all of the concepts based on criteria relevant to the user. For instance, if the user is only interested in morphological latent concepts, the application can easily filter and sort all of the latent concepts based on this property after the alignment has been performed.
The alignment of a concept to a specific property (e.g. Noun) is done by checking if most of the words (above a certain threshold) in the concept are labeled with that property. For example, \(C_{pos} (JJR) = \{greener, taller, happier, \dots \}\) would be aligned to the property of "comparative adjectives" in the POS tagging task, \(C_{sem} (MOY) = \{January, February, \dots, December\}\) defines a concept containing months of the year in the semantic tagging task, and \(C_{muslim} (names) = \{Ahmed, Muhammad, Karim, Hamdy, \dots \}\) represents a concept of Muslim names. Explanations based on human-defined concepts are not always applicable or available as these models learn very fine-grained hierarchies of knowledge and concepts that are very task-specific, hence not every latent concept is aligned to some pre-existing tag/ontology.
Our first two components are geared towards understanding what the model has learned, however, it does not necessarily imply that this knowledge is utilized during prediction and provides no insight into how these concepts are being used. To bridge this gap, our third component uses Integrated Gradients (IG) [12], which is a powerful axiomatic attribution method for deep neural networks that computes the importance of input features and model components based on their contribution to model’s prediction. More concretely, IG is used to extract the salient input features (words) used to make a certain prediction, and these salient features are then mapped to latent concepts to expand on the explanation. For example in Figure 5 highlights “captures" to be the most salient input feature used in predicting the sentiment of the sentence.
The goal of NxPlain is to provide an easy method for users to extract and analyze latent knowledge learned within a deep NLP model and connect them to the prediction. The Frontend helps achieve this goal by providing a
intuitive yet powerful GUI that can be used to interact with a model’s latent concepts and predictions. The user can upload a model and a corpus that they want to analyze. The computational queue of the application discovers latent concepts and aligns them
using the components mentioned in Section 3. The user can then use the Frontend, where they can switch between three major views:
This view presents a high-level overview of the concepts learned by the model. Specifically, we can see i) the number of concepts learned, ii) statistics on the concepts aligned with the human-fined concepts, iii) a summary of the size distribution of these concepts, iv) and salient concepts in the data and model. Figure 3 shows a sample overview page for a Sentiment analysis model.
This view presents the latent concepts in a paginated view, along with controls to sort the concepts. Users can sort the concepts i) by size, ii) by their affinity to the linguistic phenomenon (using the alignments computed earlier), iii) by their relation to the various output classes (in classification models) and iv) by their overall relevance. Each concept is accompanied by a unique label to keep track of important concepts. See Figure 4 for a sample model explanation view.
This view allows the user to look at concepts used in making a prediction and facilitates a deeper view of the behavior of the model on specific sentences. The attribution analysis component is used to get a salience map of the input tokens, as well as the matching concepts that contain these tokens in similar contexts. Figure 5 displays the prediction view, where the user can select the sentences that they want to analyze. Here NxPlain shows that “captures" was the most influential word used by the model to make the prediction. The model used a latent concept representing positive verbs to make the prediction.
A number of toolkits have been made available to carry out analysis of neural network models. Google’s What-If tool [17] inspects machine learning models and provides users an insight into the trained model based on the predictions. Seq2Seq-Vis [18] enables the user to trace back the prediction decisions to the input in NMT models. Captum [15] provides generic implementations of a number of gradient and perturbation-based attribution algorithms. NeuroX [19] and Ecco [20] use probing classifiers to examine the representations pre-trained language models. ConceptX [21] provides a framework for analyzing and annotating latent concepts in pre-trained language models. [22] facilitates debugging of pLMs through interactive visualizations. Our work is different from these toolkits. Our toolkit bridges the gap between representation analysis and causation by using attribution-based method. NxPlain provides enriched explanations using traditional linguistic knowledge and human-defined ontologies.
A large number of studies primarily focus on understanding the knowledge learned within a trained model. Researchers have proposed numerous analysis frameworks such as diagnostic classifiers [1], [23], corpus analysis [24]–[26], linguistic correlation analysis [27], [28]. A plethora of work has been carried out using these analyses frameworks to analyze what concepts are learned within the representations through relevant extrinsic phenomenon varying from word morphology [1], [29], [30] to high level concepts such as structure [3], [31], [32] and semantics [33], [34] or more generic properties such as sentence length [35], [36].
While the work done on representation analysis unwraps interesting insights about the knowledge learned within the network and how it is preserved, it’s only limited to human-defined concepts. More recent work has discovered that these models capture novel ontologies [11], [37], [38] learning linguistic concepts [14], as well as the task-specific concepts [39] that emerge as the pre-trained language models are fine-tuned towards a task.
Another line of work in interpretability focuses on attribution analysis that characterizes the role of model components and input features towards a specific prediction [3]–[5]. The explanations are categorized based on two aspects: local or global [40]. The former gives a view of explanation at a level of individual instance [41], [42], whereas the latter explains the general behavior of the model at corpus level [43], [44].
We presented NxPlain, a web-app for connecting concept analysis with model prediction. The application bridges representation analysis and attribution analysis to better explain the models’ predictions, and provides a intuitive, yet powerful graphical interface to explore the knowledge learned by a model, and also to pinpoint the knowledge used in specific predictions. In the future, we plan to enable human-in-the-loop to enhance concept alignment, as well as incorporate feedback into the explanation system. A hosted version of the application can be accessed at https://nxplain.qcri.org.