Skip to content

Commit 6bdd89b

Browse files
Merge pull request #2252 from vijayasarathib:vijayasarathib-patch-1-1
PiperOrigin-RevId: 557575931
2 parents 007d8f4 + 8267376 commit 6bdd89b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

site/en/tutorials/interpretability/integrated_gradients.ipynb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"source": [
7474
"This tutorial demonstrates how to implement **Integrated Gradients (IG)**, an [Explainable AI](https://en.wikipedia.org/wiki/Explainable_artificial_intelligence) technique introduced in the paper [Axiomatic Attribution for Deep Networks](https://arxiv.org/abs/1703.01365). IG aims to explain the relationship between a model's predictions in terms of its features. It has many use cases including understanding feature importances, identifying data skew, and debugging model performance.\n",
7575
"\n",
76-
"IG has become a popular interpretability technique due to its broad applicability to any differentiable model (e.g. images, text, structured data), ease of implementation, theoretical justifications, and computational efficiency relative to alternative approaches that allows it to scale to large networks and feature spaces such as images.\n",
76+
"IG has become a popular interpretability technique due to its broad applicability to any differentiable model (e.g. images, text, structured data), ease of implementation, theoretical justifications, and computational efficiency relative to alternative approaches that allow it to scale to large networks and feature spaces such as images.\n",
7777
"\n",
7878
"In this tutorial, you will walk through an implementation of IG step-by-step to understand the pixel feature importances of an image classifier. As an example, consider this [image](https://commons.wikimedia.org/wiki/File:San_Francisco_fireboat_showing_off.jpg) of a fireboat spraying jets of water. You would classify this image as a fireboat and might highlight the pixels making up the boat and water cannons as being important to your decision. Your model will also classify this image as a fireboat later on in this tutorial; however, does it highlight the same pixels as important when explaining its decision?\n",
7979
"\n",
@@ -151,7 +151,7 @@
151151
"\n",
152152
"**Inputs**: The expected input shape for the model is `(None, 224, 224, 3)`. This is a dense 4D tensor of dtype float32 and shape `(batch_size, height, width, RGB channels)` whose elements are RGB color values of pixels normalized to the range [0, 1]. The first element is `None` to indicate that the model can take any integer batch size.\n",
153153
"\n",
154-
"**Outputs**: A `tf.Tensor` of logits in the shape of `(batch_size, 1001)`. Each row represents the model's predicted score for each of 1,001 classes from ImageNet. For the model's top predicted class index you can use `tf.math.argmax(predictions, axis=-1)`. Furthermore, you can also convert the model's logit output to predicted probabilities across all classes using `tf.nn.softmax(predictions, axis=-1)` to quantify the model's uncertainty as well as explore similar predicted classes for debugging."
154+
"**Outputs**: A `tf.Tensor` of logits in the shape of `(batch_size, 1001)`. Each row represents the model's predicted score for 1,001 classes from ImageNet. For the model's top predicted class index you can use `tf.math.argmax(predictions, axis=-1)`. Furthermore, you can also convert the model's logit output to predicted probabilities across all classes using `tf.nn.softmax(predictions, axis=-1)` to quantify the model's uncertainty and explore similar predicted classes for debugging."
155155
]
156156
},
157157
{
@@ -249,7 +249,7 @@
249249
},
250250
"source": [
251251
"### Classify images\n",
252-
"Let's start by classifying these images and displaying the top 3 most confident predictions. Following is a utility function to retrieve the top k predicted labels and probabilities."
252+
"Start by classifying these images and displaying the top 3 most confident predictions. The following is a utility function to retrieve the top k predicted labels and probabilities."
253253
]
254254
},
255255
{
@@ -534,7 +534,7 @@
534534
"id": "s4zFzbUBj684"
535535
},
536536
"source": [
537-
"Let's use the above function to generate interpolated images along a linear path at alpha intervals between a black baseline image and the example \"Fireboat\" image."
537+
"Use the above function to generate interpolated images along a linear path at alpha intervals between a black baseline image and the example \"Fireboat\" image."
538538
]
539539
},
540540
{
@@ -557,7 +557,7 @@
557557
"id": "QABFsuCvkO1h"
558558
},
559559
"source": [
560-
"Let's visualize the interpolated images. Note: another way of thinking about the $\\alpha$ constant is that it is consistently increasing each interpolated image's intensity."
560+
"Visualize the interpolated images. Note: another way of thinking about the $\\alpha$ constant is that it is consistently increasing each interpolated image's intensity."
561561
]
562562
},
563563
{
@@ -596,7 +596,7 @@
596596
"id": "tps0eWc0REqL"
597597
},
598598
"source": [
599-
"Now let's take a look at how to calculate gradients in order to measure the relationship between changes to a feature and changes in the model's predictions. In the case of images, the gradient tells us which pixels have the strongest effect on the models predicted class probabilities."
599+
"This section explains how to calculate the gradients to measure the relationship between changes to a feature and changes in the model's predictions. In the case of images, the gradient tells us which pixels have the strongest effect on the model's predicted class probabilities."
600600
]
601601
},
602602
{
@@ -643,7 +643,7 @@
643643
"id": "9BfRuzx4-c87"
644644
},
645645
"source": [
646-
"Let's compute the gradients for each image along the interpolation path with respect to the correct output. Recall that your model returns a `(1, 1001)` shaped `Tensor` with logits that you convert to predicted probabilities for each class. You need to pass the correct ImageNet target class index to the `compute_gradients` function for your image."
646+
"Compute the gradients for each image along the interpolation path with respect to the correct output. Recall that your model returns a `(1, 1001)` shaped `Tensor` with logits that you convert to predicted probabilities for each class. You need to pass the correct ImageNet target class index to the `compute_gradients` function for your image."
647647
]
648648
},
649649
{
@@ -741,7 +741,7 @@
741741
"source": [
742742
"* **left**: This plot shows how your model's confidence in the \"Fireboat\" class varies across alphas. Notice how the gradients, or slope of the line, largely flattens or saturates between 0.6 and 1.0 before settling at the final \"Fireboat\" predicted probability of about 40%.\n",
743743
"\n",
744-
"* **right**: The right plot shows the average gradients magnitudes over alpha more directly. Note how the values sharply approach and even briefly dip below zero. In fact, your model \"learns\" the most from gradients at lower values of alpha before saturating. Intuitively, you can think of this as your model has learned the pixels e.g. water cannons to make the correct prediction, sending these pixels gradients to zero, but is still quite uncertain and focused on spurious bridge or water jet pixels as the alpha values approach the original input image.\n",
744+
"* **right**: The right plot shows the average gradients magnitudes over alpha more directly. Note how the values sharply approach and even briefly dip below zero. In fact, your model \"learns\" the most from gradients at lower values of alpha before saturating. Intuitively, you can think of this as your model has learned the pixels e.g. water cannons to make the correct prediction, sending these pixel gradients to zero, but is still quite uncertain and focused on spurious bridge or water jet pixels as the alpha values approach the original input image.\n",
745745
"\n",
746746
"To make sure these important water cannon pixels are reflected as important to the \"Fireboat\" prediction, you will continue on below to learn how to accumulate these gradients to accurately approximate how each pixel impacts your \"Fireboat\" predicted probability.\n"
747747
]
@@ -1115,9 +1115,9 @@
11151115
"* Employing techniques like Integrated Gradients before deploying your model can help you develop intuition for how and why it works. Do the features highlighted by this technique match your intuition? If not, that may be indicative of a bug in your model or dataset, or overfitting.\n",
11161116
"\n",
11171117
"Limitations\n",
1118-
"* Integrated Gradients provides feature importances on individual examples, however, it does not provide global feature importances across an entire dataset.\n",
1118+
"* The Integrated Gradients technique provides feature importances on individual examples. However, it does not provide global feature importances across an entire dataset.\n",
11191119
"\n",
1120-
"* Integrated Gradients provides individual feature importances, but it does not explain feature interactions and combinations."
1120+
"* The Integrated Gradients technique provides individual feature importances, but it does not explain feature interactions and combinations."
11211121
]
11221122
},
11231123
{

0 commit comments

Comments
 (0)