mllm-shap¶
Shapley-value attributions for conversational language models. mllm-shap
separates what you measure (the estimand: Shapley or Banzhaf), how you sample
coalitions (the estimator) and how you score outputs (the value function), and
archives every run so it can be reproduced and re-analysed.
Install mllm-shap and explain a first prompt, then check that the values
add up.
The stages of an explanation run, its counters, archives and hooks.
Shapley axioms, cooperative games, estimands, and when they diverge.
Business, compliance, and LLM operations use cases for attribution.
Typed public modules, protocols, and re-exported symbols.
Runnable Jupyter notebooks with end-to-end walkthroughs (estimands, masking, runtime, exact and approximate estimation).
How to cite mllm-shap and the methods behind it.
Development setup, quality gates and pull request conventions.
Architecture, design decisions, known issues and papers, kept as an Obsidian vault in the repository.
How it compares¶
shap (KernelExplainer, PartitionExplainer), captum
(ShapleyValueSampling) and TokenSHAP also estimate Shapley values for text.
mllm-shap differs in four ways:
the estimand (Shapley or Banzhaf) is an explicit label on every result, separate from the estimator (Estimands: Shapley vs Banzhaf);
every run is archived and can be rescored without backend calls (
reanalyze(), Runtime core);backends are plugins: mock, LM Studio, Hugging Face
transformersand OpenAI-compatible APIs (Generative backends);complementary-contribution and Neyman estimators sit next to Monte Carlo and exact enumeration (Approximate estimation).
Quick install¶
pip install mllm-shap
Requires Python 3.12 or newer. See Getting started for a full walkthrough.
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
See Extending mllm-shap for the full extras and entry-point matrix.