Skip to content

Sobol Attribution

Bases: MultitaskExplainerMixin, AttributionExplainer

Sobol is a variance-based sensitivity analysis method used to quantify the contribution of each input component to the output variance of the model.

It estimates both the first-order (main) and total (interaction) effects of features using Monte Carlo sampling strategies. In NLP, Sobol helps assess which words or tokens are most influential for the model’s decision, including how they interact with one another.

Reference: Fel et al. (2021). Look at the variance! Efficient black-box explanations with Sobol-based sensitivity analysis. Paper

Examples:

>>> from interpreto import Granularity, Sobol
>>> from interpreto.attributions import InferenceModes
>>> method = Sobol(model, tokenizer, batch_size=4,
>>>                inference_mode=InferenceModes.LOGITS,
>>>                n_token_perturbations=8,
>>>                granularity=Granularity.WORD,
>>>                sobol_indices_order=Sobol.sobol_indices_orders.FIRST_ORDER,
>>>                sampler=Sobol.samplers.SOBOL))
>>> explanations = method(text)

Parameters:

Name Type Description Default

model

PreTrainedModel

model to explain

required

tokenizer

PreTrainedTokenizer

Hugging Face tokenizer associated with the model

required

batch_size

int

batch size for the attribution method

4

granularity

Granularity

The level of granularity for the explanation (e.g., token, word, sentence).

WORD

inference_mode

Callable[[Tensor], Tensor]

The mode used for inference. It can be either one of LOGITS, SOFTMAX, or LOG_SOFTMAX. Use InferenceModes to choose the appropriate mode.

LOGITS

n_token_perturbations

int

the number of perturbations to generate

32

sobol_indices

SobolIndicesOrders

Sobol indices order, either FIRST_ORDER or TOTAL_ORDER.

required

sampler

SequenceSamplers

Sobol sequence sampler, either SOBOL, HALTON or LatinHypercube.

SOBOL

device

device

device on which the attribution method will be run

None