Regression explanations with Xplique¶
Attributions: Regression and Tabular data tutorial
Which kind of tasks are supported by Xplique?¶
With the operator's api you can treat many different problems with Xplique. There is one operator for each task.
Task and Documentation link | operator parameter value from xplique.Tasks Enum |
Tutorial link |
---|---|---|
Classification | CLASSIFICATION |
|
Object Detection | OBJECT_DETECTION |
|
Regression | REGRESSION |
|
Semantic Segmentation | SEMANTIC_SEGMENTATION |
Info
They all share the API for Xplique attribution methods.
Warning
In Xplique, for now with regression, predictions can only be explained output by output. Indeed, explaining several output simultaneously brings new problematic and we are currently working on an operator to solve this.
Simple example¶
import xplique
from xplique.attributions import Saliency
from xplique.metrics import Deletion
# load inputs and model
# ...
# for regression, `targets` indicates the output of interest, here output 3
targets = tf.one_hot([2], depth=nb_outputs, axis=-1)
# compute explanations by specifying the regression operator
explainer = Saliency(model, operator=xplique.Tasks.REGRESSION)
explanations = explainer(inputs, targets)
# compute metrics on these explanations
metric = Deletion(model, inputs, targets, operator=xplique.Tasks.REGRESSION)
score_saliency = metric(explanations)
How to use it?¶
To apply attribution methods, the common API documentation describes the parameters and how to fix them. However, depending on the task and thus on the operator
, there are three points that vary:
-
The
operator
parameter value, it is an Enum or a string identifying the task, -
The model's output specification, as
model(inputs)
is used in the computation of the operators, and -
The
targets
parameter format, indeed, thetargets
parameter specifies what to explain and the format of such specification depends on the task.
The operator
¶
How to specify it¶
In Xplique, to adapt attribution methods, you should specify the task to the operator
parameter. In the case of regression, with either:
Method(model, operator="regression")
# or
Method(model, operator=xplique.Tasks.REGRESSION)
The computation¶
The regression operator works similarly to the classification operator, it asks for the output of interest via targets
and returns this output. See targets section for more detail.
scores = tf.reduce_sum(model(inputs) * targets, axis=-1)
The behavior¶
- In the case of perturbation-based methods, the perturbation score corresponds to the difference between the initial value of the output of interest and the same output for predictions over perturbed inputs.
- For gradient-based methods, the gradient of the model's predictions for the output of interest.
Model's output¶
We expect model(inputs)
to yield a \((n, d)\) tensor or array where \(n\) is the number of input samples and \(d\) is the number of variables the model should predict (possibly one).
The targets
parameter¶
Role¶
The targets
parameter specifies what is to explain in the inputs
, it is passed to the explain
or to the __call__
method of an explainer or metric and used by the operators. In the case of regression it indicates which of the output should be explained.
Format¶
The targets
parameter in the case of regression should have the same shape as the model's output as they are multiplied. Hence, the shape is \((n, d)\) with \(n\) the number of samples to be explained (it should match the first dimension of inputs
) and \(d\) is the number of variables (possibly one).
In practice¶
In the simple example, the targets
value provided is computed with tf.one_hot
. Indeed, the regression operator takes as targets
the one hot encoding of the index of the output to explain.