[Paper Review] ferret: a Framework for Benchmarking Explainers on Transformers
ferret is a Python framework that simplifies benchmarking and comparing post-hoc explainability methods for transformer-based NLP models by integrating with Hugging Face's transformers library. It enables users to explain predictions using four state-of-the-art methods, evaluate explanations via six faithfulness and plausibility metrics, and test on standardized interpretability datasets, with SHAP emerging as the most consistent explainer across sentiment analysis and hate speech detection tasks.
As Transformers are increasingly relied upon to solve complex NLP problems, there is an increased need for their decisions to be humanly interpretable. While several explainable AI (XAI) techniques for interpreting the outputs of transformer-based models have been proposed, there is still a lack of easy access to using and comparing them. We introduce ferret, a Python library to simplify the use and comparisons of XAI methods on transformer-based classifiers. With ferret, users can visualize and compare transformers-based models output explanations using state-of-the-art XAI methods on any free-text or existing XAI corpora. Moreover, users can also evaluate ad-hoc XAI metrics to select the most faithful and plausible explanations. To align with the recently consolidated process of sharing and using transformers-based models from Hugging Face, ferret interfaces directly with its Python library. In this paper, we showcase ferret to benchmark XAI methods used on transformers for sentiment analysis and hate speech detection. We show how specific methods provide consistently better explanations and are preferable in the context of transformer models.
Motivation & Objective
- To address the lack of standardized, interoperable tools for comparing explainability methods on transformer-based NLP models.
- To provide a unified, accessible interface for applying and evaluating post-hoc explanation techniques on any Hugging Face-hosted transformer model.
- To support the evaluation of explanations using faithfulness and plausibility metrics across multiple datasets and tasks.
- To facilitate community contributions through modular, abstracted APIs for explainers, evaluators, and datasets.
- To streamline the comparison of XAI methods in real-world NLP applications such as sentiment analysis and hate speech detection.
Proposed method
- ferret provides a unified API to apply four state-of-the-art post-hoc explanation methods: Gradient, Integrated Gradients, LIME, and SHAP.
- It integrates natively with Hugging Face’s transformers library, allowing direct loading and explanation of models using standard model names.
- The framework supports six evaluation metrics based on faithfulness (e.g., comprehensiveness, sufficiency, leave-one-out) and plausibility (e.g., intersection-over-union, area under precision-recall curve).
- It includes access to four benchmark datasets: HateXplain (hate speech), MovieReviews and SST (sentiment analysis), and Thermostat (generic text).
- The library exposes abstract base classes (e.g., BaseExplainer, BaseEvaluator) to enable extensibility for new explainers, metrics, and datasets.
- It enables end-to-end workflows: loading a model, generating explanations, and evaluating them using standardized metrics in a single pipeline.
Experimental results
Research questions
- RQ1Which XAI method produces the most faithful and plausible explanations for transformer-based text classification models?
- RQ2How do different explanation methods perform consistently across multiple datasets and NLP tasks?
- RQ3To what extent can a unified framework improve the comparability and reproducibility of XAI evaluations in NLP?
- RQ4Can a standardized evaluation suite detect differences in explanation quality that are not apparent through qualitative inspection alone?
- RQ5How does the integration of Hugging Face’s ecosystem enhance accessibility and interoperability for XAI tools in NLP?
Key findings
- SHAP consistently outperformed other XAI methods in terms of faithfulness across both single-sample and multiple-sample explanation scenarios.
- The framework successfully enabled automated, standardized evaluation of explanations using six metrics grounded in faithfulness and plausibility principles.
- ferret demonstrated that integrated evaluation on benchmark datasets like HateXplain and SST enables reliable comparison of explanation quality across different methods.
- The library’s modular design allows for seamless extension with new explainers, evaluation metrics, and datasets through abstract base classes.
- The integration with Hugging Face’s transformers library enables immediate use of pre-trained models without complex setup or model conversion.
- Case studies on sentiment analysis and hate speech detection confirmed that SHAP provided the most stable and interpretable explanations across diverse input types.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.