Towards Self-Explainability of Deep Neural Networks with Heatmap
  Captioning and Large-Language Models
Heatmaps are widely used to interpret deep neural networks, particularly for
computer vision tasks, and the heatmap-based explainable AI (XAI) techniques
are a well-researched topic. However, most studies concentrate on enhancing the
quality of the generated heatmap or discovering alternate heatmap generation
techniques, and little effort has been devoted to making heatmap-based XAI
automatic, interactive, scalable, and accessible. To address this gap, we
propose a framework that includes two modules: (1) context modelling and (2)
reasoning. We proposed a template-based image captioning approach for context
modelling to create text-based contextual information from the heatmap and
input data. The reasoning module leverages a large language model to provide
explanations in combination with specialised knowledge. Our qualitative
experiments demonstrate the effectiveness of our framework and heatmap
captioning approach. The code for the proposed template-based heatmap
captioning approach will be publicly available.
Osman Tursun, Simon Denman, Sridha Sridharan, Clinton Fookes
Towards Self-Explainability of Deep Neural Networks with Heatmap Captioning and Large-Language Models

###### Abstract

Heatmaps are widely used to interpret deep neural networks, particularly for computer vision tasks, and the heatmap-based explainable AI (XAI) techniques are a well-researched topic. However, most studies concentrate on enhancing the quality of the generated heatmap or discovering alternate heatmap generation techniques, and little effort has been devoted to making heatmap-based XAI automatic, interactive, scalable, and accessible. To address this gap, we propose a framework that includes two modules: (1) context modelling and (2) reasoning. We proposed a template-based image captioning approach for context modelling to create text-based contextual information from the heatmap and input data. The reasoning module leverages a large language model to provide explanations in combination with specialised knowledge. Our qualitative experiments demonstrate the effectiveness of our framework and heatmap captioning approach. The code for the proposed template-based heatmap captioning approach will be publicly available.

## 1 Introduction

Deep neural networks have continued to achieve very promising results for various machine learning and computer vision applications. However, they are commonly referred to as "black-box" models, as their decision-making process lacks transparency and interpretability; though many attempts have been made to explain the hidden behaviour behind these models.

One widely studied interpretation approach is generating heatmaps to interrogate a neural network's decision. A heatmap is a graphical representation that highlights important elements of the data on which the neural network focuses for it's final decision. Heatmaps are useful for gaining insights into neural networks, and much research has been devoted to increasing the accuracy and improving the quality of heatmap visualisation [16, 18, 21]. However, accurately interpreting heatmaps requires contextual knowledge and specialised knowledge of deep neural networks themselves, and without this information, any interpretation may be incomplete or misleading. Moreover, end-user accessibility, scalability and the automation of heatmap interpreta

Figure 1: A demonstration of the proposed framework for self-explainable heatmap-based XAI. In this example, ChatGPT is used for generating an XAI report.
tion are limited. Therefore, here we focus on how to make heatmap-based explainable artificial intelligence (XAI) automatic, scalable, interpretable and interactive, so machine learning models will be more reliable and transparent across a range of applications and for users without specialist domain knowledge.

Our approach involves combining image captioning and with the power of large-language models such as GPT-3 [2], allowing us to extract critical task-related contextual information and easily access specialised expert knowledge. Both heatmap captioning and interaction with a large language model could be fully automatic, making the process scalable. The process can also be made interactive through user prompts based on the response of the large language model. For example, as shown in Figure 1, the heatmap captions are sent to ChatGPT 1, which is developed based on GPT-3.5 [11]. In this example, we asked ChatGPT to explain the capability of the neural network and comment on if it is able to separate the dog and cat classes. The chatbot generates a report which includes expert knowledge and is based on the specific context in this case, and the process is fully automatic. Based on needs, various general and technical questions can be asked. This makes heatmap-based XAI approachable, interactive, automatic and scalable.

Footnote 1: chat.openai.com

The primary objective of this study is on generating meaningful captions for heatmaps, which is not only the first step but also the most challenging part of our proposed framework. Although image captioning has achieved a marked improvement in recent years [1, 20], most methods are trained using natural image and text pairs in a supervised manner. To the best of our knowledge, there is no such dataset for heatmaps. Creating synthetic heatmap and text pairs is one potential approach, while generating synthetic captions for heatmaps is a non-trivial task as heatmaps have irregular shapes and positions in images. Moreover, heatmap captions take both source images and heatmap images into consideration. Therefore, existing approaches can't be directly applied to heatmap captioning.

In this work, to address the aforementioned issues, we propose a simple template-based approach. The approach uses heatmaps to localise important regions in an image, and then extracts key attributes to generate captions. This approach is highly extendable as new attributes can be added to extract additional information from the heatmap and its source image.

Overall, the contribution of this work is summarised as: (i) We propose a fully-automatic framework for self-explainable heatmap-based XAI. This framework enables automatic, scalable and accessible XAI. (ii) We propose a template-based approach for captioning heatmaps, which is useful for extracting text-based contextual information from heatmaps. (iii) Through our qualitative experiments, we have demonstrated the potential of our framework and methodology.

## 2 Related Studies

In this study, our primary focus is on heatmap-based XAI approaches designed for black-box models such as neural networks. These approaches have gained popularity since the success of AlexNet, and many different techniques have been proposed for generating heatmaps to explain the behaviour of neural networks. These techniques are generally grouped into three categories: gradient-based [15, 17], class activation-based [14, 22], and perturbation-based [3, 4] methods.

Recently, the efficiency and quality of heatmap generation have significantly improved with the development of advanced techniques [12, 16, 18, 19, 21]. Despite these advancements, expert interpretation is still required to fully understand the heatmaps and take the given task context into consideration. As Kim _et al_. [7] discussed, a heatmap-based explanation is intuitive to high-AI background end-users, while not intuitive to low-AI background end-users. Heatmap captions and accessible specialised knowledge will reduce the gap between high-AI and low-AI end-users, making them more accessible as an interpretation method.

Human-in-the-loop XAI is an emerging area of research that focuses on incorporating human feedback into the XAI process. The proposed framework supports human feedback and interaction, making the XAI more approachable, consumable, and interactive. To address the importance of human feedback in XAI, Kim et al. [6] proposed a human-centred evaluation framework that takes into account the user's perspective in the evaluation process. Similarly, Lai et al. [8] presented a framework for generating selective explanations by leveraging human input, which enhances the understandability of AI explanations. These studies demonstrate the potential of human-in-the-loop XAI to improve the effectiveness and usability of XAI systems.

## 3 Method

In this work, we are proposing a new framework for scalable, self-interpretable, and interactive heatmap-based explainable artificial intelligence (XAI). As shown in Figure. 2, this framework consists of two main modules: _context_ and _reasoning_.

The context module extracts task-specific information from the input image and its corresponding heatmap(s), using the proposed heatmap captioning approach. The reasoning module leverages a large-language model to analyse this context information in combination with specialised expert knowledge. This process can be fully-automatic, making it highly scalable, but can also be made interactive by incorporating user feedback. For simplicity, we apply Chat
GPT, the state-of-the-art large language model-based dialogue bot, for reasoning, while for the context module we will use the approach described in the following section.

### Captioning Heatmap with A Template-based Approach

To extract context information, captioning the heatmap image is very important. We, therefore, propose a template-based method to generate captions for heatmaps. Compared to mainstream deep learning-based end-to-end image captioning methods, template-based approaches do not require supervised training on image-text pairs. Another advantage of the template-based approach is its extendibility. Additional attributes can be added if required. As shown in Figure 3, we extract four attributes from the objects located within the given heatmap. Here we briefly explain these attributes and the steps for extracting them.

To extract those four attributes, an image \(I\) and its grayscale heatmap \(H\) will be utilised. In this paper, SESS [18] with GradCAM [14] is chosen for extracting heatmaps. \(H\) is used to localise objects and salient regions while \(I\) is for the recognition and extraction of details. All objects under \(H\) are localised by thresholding \(H\) and applying connected component analysis. Each connected region is considered a single object and its rectangular bounding box is considered to be the bounding box of the object. Here, the notation \((x_{i},y_{i},w_{i},h_{i})\) represents the rectangle bounding box of the object \(i\). For each located object, the following four attributes will be extracted.

The first attribute is the object identity. To identify the object, CLIP [13], a language-image model, is applied as it has a strong zero-shot classification ability. For object \(i\), the cropped region \(I[x_{i}:x_{i}+w_{i},y_{i}:y_{i}+h_{i}]\) is sent to CLIP for classification. In this study, a ViT-B/16 Transformer model and COCO classification labels [9] are used for classification.

The second attribute is the global position and size of the object. The centre of the bounding box of the object is used to localise the object. \(I\) is equally divided into nine regions: top-left, centre-left, bottom-left, top-centre, centre, bottom-centre, top-right, centre-right and bottom-right. The region in which the object's centre \((x_{i},y_{i})\) is located is considered to be the object's position within the image. The relative size of the object relative to the image is also used included, which is equal to \((w_{i}*h_{i})/size(I)\).

The third attribute is the salient regions of the object, where we seek to find the most important region of the object which contributes most to the decision of the model. For object \(i\), \(H[x_{i}:x_{i}+w_{i},y_{i}:y_{i}+h_{i}]\) is equally divided into nine regions as we did for the global position attribute. The three regions with the highest mean intensity values are considered the most salient.

The last attribute of the object specifies its dominant colour. This is determined using a colour naming algorithm applied to the HSV colour space, which is capable of naming the colour of a pixel with one of 93 semantic colour names, as described in [10]. To identify the dominant colours for object \(i\), the algorithm selects foreground pixels from the region \(I[x_{i}:x_{i}+w_{i},y_{i}:y_{i}+h_{i}]\) based on their heatmap intensity values. A pixel is from the foreground if its intensity exceeds 0.5. The algorithm then assigns a colour name to each selected pixel and calculates the percentage of each colour. The three colours with the highest percentage are then identified as the dominant colours for the object.

After the attribution extraction process is complete, the resulting attributes are inserted into predetermined templates to generate the final caption, as shown in Figure 3.

Figure 3: A diagram of the proposed template-based heatmap captioning method, which combines four different attributes to generate a heatmap caption.

Figure 2: An illustration of the proposed framework. It consists of two main modules: _context_ and _reasoning_. The context module generates contextual information through captioning heatmaps. The reasoning module leverages a large language model for analysing contextual information and user feedback in combination with specialised knowledge.
## 4 Experiment

In this section, we provide some qualitative results including generated captions and XAI reports generated with ChatGPT.

In Figure 4, we display examples of the generated captions through the proposed template-based heatmap captioning approach. Those heatmaps are extracted from the ResNet50 [5]. The proposed method can generate captions for both single-object scenes (a, b, c) and multiple-object scenes (d), covering all four key attributes. The generated captions are sensitive to changes in the heatmap, as demonstrated in (a-b). However, there are some specific instances where the generated captions are not entirely correct. For example, in (c), the heatmap covers both the "human driver" and "go-kart," but the caption only includes one object identified as a "car." Similarly, in (d), one object is labelled as "kite," while the other, which is identical, is labelled as "bird." These errors are due to the limitations of heatmap-based object localization and zero-shot classification, which can be minimised with the SOTA object localisation and classification techniques.

### Generating XAI Reports with ChatGPT

To test out if the generated captions are informative enough for generating meaningful XAI report with a large-language model such as ChatGPT, we generated some reports with ChatGPT by sending generated captions to ChatGPT. We asked ChatGPT to answer questions including (i) Is a model working properly? (ii) What is the possible shortcoming of the model? (iii) Is a classification model able to locate certain types of objects?

When the correct captions and well-formed prompts are given, ChatGPT produces a well-written and informative XAI report. Examples of these reports are presented in the supplementary materials. The prompt for ChatGPT includes the following content:

* How a heatmap is generated. For example, which neuron is used for extracting the heatmap.
* Heatmap caption(s). This is generated with the proposed template-based heatmap captioning approach, and are shown in Figure 4 of the main paper. However, we slightly modified the captions from Figures (c-d) to help obtain a reasonable answer from ChatGPT.
* A question regarding the neural network. We underlined these questions in the following examples. We also underlined the key parts of ChatGPT's responses to those questions.

**Prompt for Figure 4 (a-b)**: _A neural network is used for extracting two heatmaps for an image, with Heatmap1 being a

Figure 4: Qualitative results of generated captions. In each example, a caption is generated based on the image and its heatmap.
generated form the "tiger cat" neuron and showing the activation on a cat object in the given image, and Heatmap 2 being generated from the "bull mastif" neuron and showing the activation on a dog object in the given object. Here are detailed information about heatmaps: Heatmap1: In this image, one object is detected under the heatmap. Object 1 is located on the top-center side of the image. It occupies 13.33% of the image. It is a dog. Its center, center-right and top-center parts are mostly considered important by the model. The main colours of it and its background are pale orange, orange, and pale bright orange. Heatmap2: In this image, one object is detected under the heatmap. Object 1 is located on the bottom-middle side of the image. It occupies 23.79% of the image. It is a cat. Its bottom-left, center-left and center-right parts are mostly considered important by the model.The main colours of it and its background are pale orange, orange, and pale yellow. Can this neural network accurately classify the image as either a cat or dog, and what is the basis for this conclusion?_

**ChatGPT**: _Based on the information provided, the neural network has generated two heatmaps, one for detecting a cat and another for detecting a dog in the image. The description of Heatmap1 shows that the detected object is a dog, located on the top-center side of the image and occupying 13.33% of the image. The network has identified the center, center-right, and top-center parts of the dog as the most important for its detection, and the main colors of the object and its background are pale orange, orange, and pale bright orange. On the other hand, the description of Heatmap2 shows that the detected object is a cat, located on the bottom-middle side of the image and occupying 23.79% of the image. The network has identified the bottom-left, center-left, and center-right parts of the cat as the most important for its detection, and the main colors of the object and its background are pale orange, orange, and pale yellow. Since the network has generated separate heatmaps for detecting a cat and a dog in the image, and each heatmap shows a high degree of activation on the corresponding object, it is likely that the neural network is capable of accurately classifying the image as either a cat or a dog. However, without additional information about the neural network's training data, architecture, and performance, it is difficult to make a definitive conclusion about its accuracy. It is possible that the network may have difficulty distinguishing between similar-looking objects or may not generalize well to other images. Further evaluation and testing would be necessary to determine the neural network's classification accuracy more precisely._

**Prompt for Figure 4 (c)**: _A neural network classified an image as "go-kart", and a heatmp is generated through visualising its most activated neuron. Here is the description of this heatmap: "In this image, one object is detected under the heatmap. Object 1 is located on the center side of the image. It occupies 68.44% of the image. It is a go-kart with a human driver. Its top-center, bottom-center and center parts are mostly considered important by the model. The main colours of it and its background are pale yellow, pale orange, and black." What is the possible shortcoming of this neural network. hint: the human driver and the go-cart objects have the same degree of saliency._

**ChatGPT**: _One possible shortcoming of this neural network is its lack of attention to distinguishing features that could differentiate the human driver from other objects or individuals. The fact that the model assigns the same degree of saliency to both the go-kart and the human driver suggests that the network may not be taking into account important details or features that could impact its classification._

_For example, if the network is trained on a dataset of go-karts without human drivers, it may not have learned to differentiate between a go-kart with and without a driver. Alternatively, it is possible that the network's architecture or training data may not have been optimized to detect and classify human drivers accurately._

_In either case, the lack of attention to distinguishing features could be a potential shortcoming of this neural network, as it may result in misclassifications or incorrect predictions when applied to other images. To address this issue, the network could be trained on a more diverse dataset that includes images of go-karts with and without human drivers, as well as other types of vehicles and objects to ensure that it can accurately distinguish between them. Additionally, modifications to the network's architecture or training data may be necessary to improve its ability to identify and differentiate between relevant features._

**Prompt for Figure 4 (d)**: _A neural network is used for extracting a heatmap for an image. Detailed information of the heatmap: In this image, two objects are detected under the heatmap. Object 1 is located on the center-left side of the image. It occupies 12.28% of the image. It is a bird. Its center, center-right and top-center parts are mostly considered important by the model. The main colours of it and its background are blue, pale yellow, and grey. Object 2 is located on the center-right side of the image. It occupies 8.93% of the image. It is a bird. Its center, center-right and top-center parts are mostly considered important by the model. The main colours of it and its background are blue, pale yellow, and white. Based on the heatmap information, is this network useful for locating a bird object?_

**ChatGPT**: _Based on the information provided, it is likely that the neural network is capable of accurately detecting and locating bird objects in an image. The heatmap generated by the network indicates that two bird objects were detected in the image, each occupying a distinct region of the image and identified by specific regions of importance, including the center, center-right, and top-center parts of
each object. Furthermore, the description of the main colors of each object and its background suggests that the network is capable of identifying and distinguishing between different color patterns associated with bird objects. Overall, the heatmap information provided suggests that the neural network is useful for locating bird objects in images, particularly those with distinct color and feature patterns that are easily distinguishable by the network. However, it is important to note that the accuracy and effectiveness of the network may vary depending on the quality and diversity of the training data and the complexity and adaptability of the network's architecture._

## 5 Future Work and Conclusion

In this study, we present a promising framework for automatic, interactive, and scalable XAI report generation using a large-language model. Specifically, we utilized a proposed template-based heatmap caption generation approach to provide contextual information for a large-language-based reasoning module, such as ChatGPT. Our results demonstrate the promise of this approach, yet also highlight the importance of an accurate template-based captioning approach, and we note that further improvements are required to realise a fully automatic XAI report generation. We observe that while the generated captions were informative, they lack diversity and can contain redundant information. Future research could explore the use of deep learning-based image captioning approaches to address these limitations. Furthermore, we found that the reports generated by ChatGPT were not concise and required well-designed prompts. Despite these shortcomings, designing a large-language model specifically for XAI report generation shows promise as a research direction.
