Concepts Reconstruction Metrics¶
Concept reconstruction error measures the faithfulness of the concept space with respect to the explained model latent space. To do so, these metrics compute the distance between initial activations and the reconstructed activations.
from interpreto.concepts.metrics import MetricClass
metric = MetricClass(concept_explainer)
score = metric.compute(activations)
MSE¶
interpreto.concepts.metrics.MSE
¶
Bases: ReconstructionError
Code concepts/metrics/reconstruction_metrics.py
Evaluates wether the information reconstructed by the concept autoencoder corresponds to the original latent activations. It is a faithfulness metric. It is computed in the latent activations space through the Euclidean distance. It is also known as the reconstruction error.
With \(A\) latent activations obtained through \(A = h(X)\), \(t\) and \(t^{-1}\) the concept encoder and decoders, the MSE is defined as: $$ \sum_{a}^{A} ||t^{-1}(t(a)) - a||_2 $$
TODO: make formula work
Attributes:
Name | Type | Description |
---|---|---|
concept_explainer |
ConceptAutoEncoderExplainer
|
The explainer used to compute concepts. |
Source code in interpreto/concepts/metrics/reconstruction_metrics.py
compute
¶
compute(latent_activations)
Compute the reconstruction error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
LatentActivations | dict[str, LatentActivations]
|
The latent activations to use for the computation. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The reconstruction error. |
Source code in interpreto/concepts/metrics/reconstruction_metrics.py
FID¶
interpreto.concepts.metrics.FID
¶
Bases: ReconstructionError
Code concepts/metrics/reconstruction_metrics.py
Evaluates wether the information reconstructed by the concept autoencoder corresponds to the original latent activations. It corresponds to a faithfulness metric, it measures if the reconstructed distribution matches the original distribution. It is computed in the latent activations space through the Wasserstein 1D distance.
This metric was introduced by Fel et al. (2023)1
With \(A\) latent activations obtained through \(A = h(X)\), \(t\) and \(t^{-1}\) the concept encoder and decoders, and \(\mathcal{W}_1\) the 1-Wassertein distance, the FID is defined as:
TODO: make formula work
-
Fel, T., Boutin, V., Béthune, L., Cadène, R., Moayeri, M., Andéol, L., Chavidal, M., & Serre, T. A holistic approach to unifying automatic concept extraction and concept importance estimation. Advances in Neural Information Processing Systems. 2023. ↩
Attributes:
Name | Type | Description |
---|---|---|
concept_explainer |
ConceptAutoEncoderExplainer
|
The explainer used to compute concepts. |
Source code in interpreto/concepts/metrics/reconstruction_metrics.py
compute
¶
compute(latent_activations)
Compute the reconstruction error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
LatentActivations | dict[str, LatentActivations]
|
The latent activations to use for the computation. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The reconstruction error. |
Source code in interpreto/concepts/metrics/reconstruction_metrics.py
Custom¶
To tune the reconstruction error to your need, you can specify a reconstruction_space
and a distance_function
, note that the distance_function
should follow the interpreto.commons.DistanceFunctionProtocol
protocol.
interpreto.concepts.metrics.ReconstructionError
¶
Code concepts/metrics/reconstruction_metrics.py
Evaluates wether the information reconstructed by the concept autoencoder corresponds to the original latent activations. It corresponds to a faithfulness metric. The space where the distance thus error is computed and the distance function used can be specified.
Attributes:
Name | Type | Description |
---|---|---|
concept_explainer |
ConceptAutoEncoderExplainer
|
The explainer used to compute concepts. |
reconstruction_space |
ReconstructionSpaces
|
The space in which the reconstruction error is computed. |
distance_function |
DistanceFunctionProtocol
|
The distance function used to compute the reconstruction error. |
Source code in interpreto/concepts/metrics/reconstruction_metrics.py
compute
¶
compute(latent_activations)
Compute the reconstruction error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
LatentActivations | dict[str, LatentActivations]
|
The latent activations to use for the computation. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The reconstruction error. |
Source code in interpreto/concepts/metrics/reconstruction_metrics.py
interpreto.concepts.metrics.ReconstructionSpaces
¶
Bases: Enum
Enumeration of possible reconstruction spaces. Latent activations go through the concept autoencoder to obtain reconstructed latent activations. Then it is possible to compute the distance between the original and reconstructed latent activations. First directly in the latent space, second in the logits space.
Attributes:
Name | Type | Description |
---|---|---|
LATENT_ACTIVATIONS |
str
|
Reconstruction space in the latent space. |
LOGITS |
str
|
Reconstruction space in the logits space. |
interpreto.commons.DistanceFunctions
¶
Bases: Enum
Enum of callable functions for computing distances between tensors.
Members
WASSERSTEIN_1D: Computes the 1D Wasserstein (earth mover's) distance between two tensors. EUCLIDEAN: Computes the Euclidean (L2) distance between two tensors. AVERAGE_EUCLIDEAN: Computes the average Euclidean distance between two tensors of samples. LP: Computes the Lp distance (generalization of Euclidean) between two tensors. AVERAGE_LP: Computes the average Lp distance between two tensors of samples. KL: Computes the Kullback-Leibler divergence between two tensors.