Text Data Explanation Benchmarking: Abstractive Summarization

This notebook demonstrates how to use the benchmark utility to benchmark the performance of an explainer for text data. In this demo, we showcase explanation performance for partition explainer on an Abstractive Summarization model. The metric used to evaluate is “keep positive”. The masker used is Text Masker.

The new benchmark utility uses the new API with MaskedModel as wrapper around user-imported model and evaluates masked values of inputs.

import nlp
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer

import shap
import shap.benchmark as benchmark

Load Data and Model

tokenizer = AutoTokenizer.from_pretrained("sshleifer/distilbart-xsum-12-6")
model = AutoModelForSeq2SeqLM.from_pretrained("sshleifer/distilbart-xsum-12-6")
dataset = nlp.load_dataset("xsum", split="train")
Using custom data configuration default
s = dataset["document"][0:1]

Create Explainer Object

explainer = shap.Explainer(model, tokenizer)
explainers.Partition is still in an alpha state, so use with caution...

Run SHAP Explanation

shap_values = explainer(s)
Partition explainer: 2it [00:43, 21.70s/it]

Define Metrics (Sort Order & Perturbation Method)

sort_order = "positive"
perturbation = "keep"

Benchmark Explainer

sp = benchmark.perturbation.SequentialPerturbation(
    explainer.model, explainer.masker, sort_order, perturbation
xs, ys, auc = sp.model_score(shap_values, s)
sp.plot(xs, ys, auc)