Skip to main content

Latest PyPI version Documentation Status HuggingFace Spaces Demo YouTube Video arxiv preprint downloads badge

Ferret circular logo with the name to the right

A python package for benchmarking interpretability techniques on Transformers.

from transformers import AutoModelForSequenceClassification, AutoTokenizer
from ferret import Benchmark

name = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
model = AutoModelForSequenceClassification.from_pretrained(name)
tokenizer = AutoTokenizer.from_pretrained(name)

bench = Benchmark(model, tokenizer)
explanations = bench.explain("You look stunning!", target=1)
evaluations = bench.evaluate_explanations(explanations, target=1)

bench.show_evaluation_table(evaluations)

Installation

pip install -U ferret-xai

Features

ferret offers a painless integration with Hugging Face models and naming conventions. If you are already using the transformers library, you immediately get access to our Explanation and Evaluation API.

Supported Post-hoc Explainers

Supported Evaluation Metrics

Faithfulness measures:

Plausibility measures:

See our paper for details.

Visualization

The Benchmark class exposes easy-to-use table visualization methods (e.g., within Jupyter Notebooks)

bench = Benchmark(model, tokenizer)

# Pretty-print feature attribution scores by all supported explainers
explanations = bench.explain("You look stunning!")
bench.show_table(explanations)

# Pretty-print all the supported evaluation metrics
evaluations = bench.evaluate_explanations(explanations)
bench.show_evaluation_table(evaluations)

Dataset Evaluations

The Benchmark class has a handy method to compute and average our evaluation metrics across multiple samples from a dataset.

import numpy as np
bench = Benchmark(model, tokenizer)

# Compute and average evaluation scores one of the supported dataset
samples = np.arange(20)
hatexdata = bench.load_dataset("hatexplain")
sample_evaluations =  bench.evaluate_samples(hatexdata, samples)

# Pretty-print the results
bench.show_samples_evaluation_table(sample_evaluations)

Planned Developement

See the changelog file for further details.

  • ✅ GPU acceleartion support for inference (v0.4.0)

  • ✅ Batched Inference for internal methods’s approximation steps (e.g., LIME or SHAP) (v0.4.0)

  • ⚙️ Simplified Task API to support NLI, Zero-Shot Text Classification, Language Modeling (branch).

  • ⚙️ Multi-sample explanation generation and evaluation

  • ⚙️ Support to explainers for seq2seq and autoregressive generation through inseq.

  • ⚙️ New evaluation measure: Sensitivity, Stability (Yin et al)

  • ⚙️ New evaluation measure: Area Under the Threshold-Performance Curve (AUC-TP) (Atanasova et al.)

  • ⚙️ New explainer: Sampling and Occlusion (SOC) (Jin et al., 2020)

  • ⚙️ New explainer: Discretized Integrated Gradient (DIG) (Sanyal and Ren, 2021)

  • ⚙️ Support additional form of aggregation over embeddings’ hidden dimension.

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Logo and graphical assets made by Luca Attanasio.

If you are using ferret for your work, please consider citing us!

@article{attanasio2022ferret,
  title={ferret: a Framework for Benchmarking Explainers on Transformers},
  author={Attanasio, Giuseppe and Pastor, Eliana and Di Bonaventura, Chiara and Nozza, Debora},
  journal={arXiv preprint arXiv:2208.01575},
  year={2022}
}

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ferret-xai-0.4.1.tar.gz (52.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ferret_xai-0.4.1-py2.py3-none-any.whl (52.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file ferret-xai-0.4.1.tar.gz.

File metadata

  • Download URL: ferret-xai-0.4.1.tar.gz
  • Upload date:
  • Size: 52.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for ferret-xai-0.4.1.tar.gz
Algorithm Hash digest
SHA256 7d052cd9f47362239b9fff20dfdd87ff2a910e5fa0c5093fe4f08cc82c629d9f
MD5 50b24f199240504709fac1ee7b411fde
BLAKE2b-256 08232c78ad51cee99818f8e78daf5078ab4766aa2c45d65bf32613ee1da5f259

See more details on using hashes here.

File details

Details for the file ferret_xai-0.4.1-py2.py3-none-any.whl.

File metadata

  • Download URL: ferret_xai-0.4.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 52.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for ferret_xai-0.4.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1528a2a2e8cf80b732b2bc137b1863c90ba21796361434cd9a4572b481e30b72
MD5 4a1962f4e8387cfc9eaa4e7d85fe4436
BLAKE2b-256 408296beae895909dfec4c396107b8e4bf1bab643f150f6178a239e487b70c30

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page