NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

ferret: a Framework for Benchmarking Explainers on Transformers

Giuseppe Attanasio, Eliana Pastor, Chiara Di Bonaventura, Debora Nozza

TL;DR

This paper introduces ferret, a Python library designed to simplify the use and comparison of explainable AI (XAI) methods for Transformer models. It addresses the challenge of fragmented XAI tools by providing a unified framework for generating, evaluating, and visualizing explanations, making it easier for researchers and practitioners to understand and trust complex NLP models.

What Problem Does This Paper Address?

Transformers have become the backbone of many state-of-the-art Natural Language Processing (NLP) applications, achieving remarkable performance. However, their "black-box" nature makes it difficult to understand why they make specific predictions. This lack of interpretability is a significant hurdle for practitioners who need to debug models, ensure fairness, and build trust. While various XAI techniques exist, they are often scattered across different implementations, lack standardized evaluation metrics, and are not easily integrated with popular Transformer libraries like Hugging Face's transformers. This fragmentation makes it challenging to compare different XAI methods effectively and choose the best one for a given task.

Methods

ferret is built on four core principles:

  • Built-in Post-hoc Interpretability: It integrates four state-of-the-art post-hoc feature attribution methods (Gradient, Integrated Gradient, SHAP, and LIME) and three interpretability corpora. This allows users to explain any text with an arbitrary model and provides annotated datasets for testing new methods.
  • Unified Explanation Benchmarking: ferret offers a unified API for evaluating explanations, supporting six metrics based on the principles of faithfulness and plausibility.
  • Transformers-readiness: It provides a direct interface with models from the Hugging Face Hub, allowing users to load models and tokenizers easily and apply XAI methods.
  • Modularity and Abstraction: The library is structured into three core modules (Explainers, Evaluation, and Datasets) with abstract interfaces, facilitating future extensions and contributions.

Key evaluation metrics include:

  • Faithfulness: Measures how accurately an explanation reflects the model's inner workings. Metrics include Comprehensiveness (how well the explanation captures relevant tokens), Sufficiency (whether the explanation is enough for the model's prediction), and Correlation with Leave-One-Out scores.
  • Plausibility: Assesses how well explanations align with human reasoning. Metrics include Intersection-Over-Union (IOU), token-level F1 scores, and Area Under the Precision-Recall curve (AUPRC).

Datasets

ferret integrates several datasets for evaluation:

  • HateXplain: Contains English instances labeled for hate speech, target groups, and word-level human rationales.
  • MovieReviews: Includes movie reviews with sentiment labels and phrase-level human rationales.
  • Stanford Sentiment Treebank (SST): A sentiment classification dataset with binary labels and human annotations for word phrases.
  • Thermostat Datasets: Provides pre-computed feature attribution scores for tasks like news topic classification and sentiment analysis.

The paper does not introduce new benchmarks but rather leverages existing ones to facilitate unified evaluation.

Key Insights and Ideas

  • Bridging the XAI Fragmentation: The most significant contribution is consolidating scattered XAI tools into a single, user-friendly Python library, directly addressing a major pain point for NLP researchers.
  • Unified Evaluation is Crucial: The paper emphasizes the importance of standardized metrics (faithfulness and plausibility) for comparing XAI methods, moving beyond ad-hoc evaluations.
  • SHAP Shines in Benchmarks: Across sentiment analysis and hate speech detection tasks, SHAP consistently emerged as a strong performer, often providing the most faithful and plausible explanations.
  • Context Matters for Explanations: The paper highlights how different XAI methods can lead to different conclusions, underscoring the need for careful selection and evaluation based on the specific task and model.
  • Practical Integration: The seamless integration with Hugging Face's transformers library makes ferret an easy addition to existing NLP pipelines.

Key Results

In case studies on sentiment analysis and hate speech detection, ferret demonstrated that:

  • SHAP was identified as the most consistent explainer for both single- and multiple-sample scenarios, showing high faithfulness and plausibility. For example, in a sentiment analysis misclassification, SHAP correctly identified "great" as a key contributor to the incorrect positive prediction.
  • Gradient and Gradient (x Input) methods often showed poor sufficiency and comprehensiveness.
  • LIME and Gradient (x Input) were found to return untrustworthy explanations based on faithfulness metrics.

The paper also shows that ferret can aggregate evaluation metrics across multiple instances, providing a more robust assessment of explainer performance.

Limitations and Future Work

  • Limitations: The authors acknowledge that interpretability is a broader field than post-hoc feature attribution, which is the focus of ferret. They also note that removal-based evaluation criteria can have limitations, such as inputs falling out of the model's distribution. The current metrics, while comprehensive, may not capture every nuance of explanation quality.
  • Future Work: The ferret team plans to:
  • Integrate more advanced interpretability methods, including those requiring training complementary models (e.g., Sampling and Occlusion, Minimal Contrastive Editing).
  • Add support for more NLP tasks beyond classification, such as Mask Filling Prediction, Natural Language Inference, and Zero-Shot Text Classification.
  • Improve interoperability with other libraries, like Inseq, for text generation tasks.
  • Include additional evaluation measures like sensitivity, stability, and AUC-TP.

Summary updated

BibTeX
@inproceedings{attanasio2023ferret,
  author = {Giuseppe Attanasio and Eliana Pastor and Chiara Di Bonaventura and Debora Nozza},
  title = {{ferret: a Framework for Benchmarking Explainers on Transformers}},
  booktitle = {EACL (System Demonstrations)},
  year = {2023},
  doi = {10.18653/v1/2023.eacl-demo.29},
}
Figure