Explainable Artificial Intelligence (VTR UGE 21), day 3 of 5

Explaining Deep Networks

Prof. Dr. Utku Kose, Süleyman Demirel University

Saliency lab

Part A repeats a gradient by hand with its check, step by step, with sliders for its numbers. Part B shows maps of six methods computed by the network of the notebook on real test images, drawn with the four steps of a heat map. Part C repeats Integrated Gradients on a saturated model step by step. Part D follows Grad-CAM, short for gradient-weighted class activation mapping, inside the digits network of the notebook and computes it by hand. Part E repeats a rank correlation step by step. Part F asks whether a map came from the trained network or from random weights. Part G solves GEMEX, short for Geodesic Entropic Manifold Explainability, step by step for a weather app. In Parts A, C, E and G every intermediate value is rounded, and the next step continues with the rounded value, as in a calculation by hand.

Part A: A gradient by hand, step by step

The worked example of the lecture: a model of three pixels with the output \(f(x)\)​\({} = 4\, \mathrm{ReLU}(x_1 - 0.5)\)​\({} - 2 x_2\)​\({} + 0.5 x_3\). The sliders set the three pixels and the step \(h\) of a check by a finite difference. The steps compute the output, the three partial derivatives, the check, the saliency values and gradient times input. The figure draws the output as a function of the first pixel, with the tangent whose slope is the derivative and the secant of the check.

Back to the lecture: Saliency: following the gradient, where the text continues after the box of this part.

Part B: Six methods as heat maps, trained and random

The maps below were computed by the NumPy network of the notebook on real test images: six positive images, all with the corner marker, and two negative images without it. Choose an image and a method, and compare the trained network with the same architecture with random weights. A faithful map should depend on the weights; a map that looks the same for random weights is showing the image, not the model.

The second row of controls applies the four steps of a heat map from the lecture to the same numbers: the scale of the values, the colour scale, an overlay on the image with its opacity and, for the two Grad-CAM maps, the enlargement of the 8 by 8 cells. With one scale for both networks, the colour 1 stands for the largest value of the trained and of the random network together, so that their sizes can be compared.

Back to the lecture: From numbers to a heat map. The lecture continues there with Section 2 of the Colab notebook: Open it from the next orange box.

Part C: Integrated Gradients on a saturated model

The worked example of the lecture: a model of two pixels with the output \(f(x) = \min(c,\, 4 x_1 + 2 x_2)\), which grows with both pixels and stops at the cap \(c\). The baseline is the black image. The sliders set the two pixels, the cap and the number \(m\) of points on the path. The steps compute the output and the plain gradient, the points of the path, the average gradient, the contributions and the check of completeness. The left figure draws the output along the path, and the right one compares gradient times input with Integrated Gradients.

Back to the lecture: Better maps: SmoothGrad and Integrated Gradients. The lecture continues there with Section 3 of the Colab notebook: Open it from the next orange box.

Part D: Grad-CAM inside a network, and by hand

The network of Section 4 of the notebook reads handwritten digits of 8 by 8 pixels, the way the first networks of this kind read postcodes on letters. It has two convolutional layers with 16 filters each, max pooling after the first one and global average pooling after the second one, and it labels 97.1 percent of 450 test digits correctly. Choose a test digit or draw one, and choose the class to explain. The page runs the network itself: the 16 feature maps of 4 by 4 cells of the last layer, the weight of every map, which is its output weight divided by 16, the weighted sum, its positive part, the enlargement to the 8 by 8 pixels of the digit and the overlay. The saliency map of the same score is drawn for comparison with the pixels.

Questions to try: Which part of a 9 speaks for the class 9, and which part of the same drawing would speak for a 3? What happens to the map of a 1 when a short horizontal stroke is added at its top? Find a map whose weight is the largest positive one for the predicted class, and look where that map is bright.

Grad-CAM by hand

A convolutional layer produced two maps of 3 by 3 cells. Grad-CAM weights each map by the average of its gradient, 0.5 for map 1 and -0.25 for map 2, adds the weighted maps and keeps only positive values. Compute three cells.

map 1        map 2
0  1  2      2  0  0
1  3  1      0  1  0
0  1  0      0  0  3

Back to the lecture: Class activation maps: Grad-CAM. The lecture continues there with Section 4 of the Colab notebook: Open it from the next orange box.

Part E: A rank correlation, step by step

The worked example of the lecture: two maps give five pixels their values. The first map is fixed, with the values 0.9, 0.1, 0.4, 0.7 and 0.2, and the sliders set the values of the second map. The steps rank the pixels in each map, from rank 1 for the largest value, form the differences of the ranks and compute the rank correlation of Spearman. In the figure, every line joins the rank of a pixel in the first map with its rank in the second: Parallel lines mean the same order, and crossing lines a different one.

Back to the lecture: Are the maps right?, where the text continues after the box of this part.

Part F: Trained or random?

Each map below was computed by the network of the notebook, either with its trained weights or with random weights. A map that explains the model should look different when the weights are random. Decide for each map and press Check my answers.

Back to the lecture: Are the maps right?. The lecture continues there with Section 6 of the Colab notebook: Open it from the next orange box.

Part G: GEMEX in a weather app, step by step

The worked example of the lecture: a weather app gives the probabilities of sun, clouds and rain from the air pressure \(x_1\) in hectopascal (hPa) and the humidity \(x_2\) in percent, with the scores \(z_{\text{sun}} = 0.12 (x_1 - 1013)\), \(z_{\text{clouds}} = 0\) and \(z_{\text{rain}}\)​\({} = 0.08 (x_2 - 60) - 0.5\) and the softmax function. The sliders set today and the reference, a typical day. The steps compute the probabilities, the derivatives of their logarithms, the Fisher information matrix, its eigenvalues, the length of the step from the reference and its alignment with each feature. The last step reads the scores of GEMEX along its geodesic of 40 points, computed in this page with the steps of GEMEX for a model of two features. Every intermediate value is rounded, as in a calculation by hand.

Back to the lecture: Explaining with GEMEX, where the text continues after the box of this part.