mllm-shap¶
Shapley-value attributions for conversational language models. mllm-shap separates
what you measure (estimand: Shapley or Banzhaf), how you sample coalitions (estimator) and
how you score outputs (value function), and archives every run for reanalysis.
What an explanation shows¶
Which photo region, spoken word or typed word decided a model’s answer? Parts are removed, the answer re-scored; credit adds up to the total change.
“Is there a dog in this picture?” Qwen2.5-VL-3B says yes. Two of 36 cells, a walker and a small dog, carry most of it.
Does the speed of sound vary with frequency “at constant temperature”? Qwen2-Audio-7B says no; “constant” drives it.
A refund request: “yes”, “no.” and “laptop” push the answer; “opened it.” pulls against it.
Start here¶
Install, explain a first prompt, check the values add up.
Stages of a run, counters, archives and hooks.
Cooperative games, Shapley axioms, estimands and when they diverge.
Business, compliance and operations use cases.
Public modules, protocols and re-exported symbols.
Runnable notebooks, end to end: estimands, masking, runtime, exact and approximate estimation.
Citing mllm-shap and its methods.
Setup, quality gates, pull requests.
Architecture, decisions, known issues and papers: an Obsidian vault in the repository.
How it compares¶
Latest PyPI releases, checked December 2026:
Package |
Inputs |
Methods |
Models |
Turns as players |
|---|---|---|---|---|
|
text, image, audio |
10 estimators, 4 estimands, 14 value functions |
Hugging Face, LM Studio, OpenAI-compatible APIs |
built in |
shap 0.54.1 |
text, image (captioning) |
Partition, Permutation, Exact |
Hugging Face, any callable |
no |
captum 0.9.0 |
text, image regions |
5 perturbation (3 Shapley), gradient |
Hugging Face, vLLM |
by hand (templates) |
inseq 0.7.1 |
text |
4 perturbation, gradient |
Hugging Face |
no |
interpreto 0.5.2 |
text |
4 perturbation (1 Shapley), 7 gradient |
Hugging Face |
no |
icx360 0.1.0 |
text |
MExGen, CELL, Token Highlighter |
Hugging Face, vLLM |
no |
context-cite 0.0.4 |
text context |
sparse linear surrogate |
Hugging Face |
no |
TokenSHAP 0.2.2 |
text |
sampled with/without difference |
Hugging Face, Ollama |
no |
lime 0.2.0.1 and ferret-xai 0.4.2 explain classifiers only.
Need |
|
|---|---|
Voice and vision |
Credits spoken words and image regions; the only package above that takes audio (Audio input, Image input). |
Chatbots |
A system prompt, a turn or a passage in its own message is a player (Masking views). |
Closed models |
Needs only the model’s answers, plus logprobs for some value functions (Generative backends). |
Audit trail |
Every run is archived; text value functions rescore it without model calls
( |
Checkable numbers |
Results name their estimand (Estimands: Shapley vs Banzhaf); |
Cost control |
Exact, sampling and regression estimators behind one setting (Approximate estimation). |
Quick install¶
pip install mllm-shap
Python 3.12 or newer; walkthrough: Getting started. Optional extras:
pip install "mllm-shap[transformers]" # Hugging Face backend
pip install "mllm-shap[lmstudio]" # LM Studio backend
pip install "mllm-shap[api]" # OpenAI-compatible HTTP API
pip install "mllm-shap[viz]" # matplotlib attribution charts
pip install "mllm-shap[proxy]" # scikit-learn: the ProxySHAP estimator
pip install "mllm-shap[infill]" # masked language model of the infill policy
pip install "mllm-shap[interactions]" # shapiq: exact pairwise interactions
pip install "mllm-shap[audio]" # audio decoding and alignment
pip install "mllm-shap[semantic]" # sentence, BERTScore and NLI encoders
pip install "mllm-shap[audio-semantic]" # SpeechBERTScore encoder and recognizer
pip install "mllm-shap[image]" # image players and fills
Extras and entry points: Extending mllm-shap.