Examples

The examples/ directory contains Jupyter notebooks with runnable nlp-shap workflows. They complement guides, theory pages, and the API reference.

Setup

Install the package:

pip install nlp-shap

From a local clone:

make install

Use the project .venv as the notebook kernel when working from source.

Notebooks

Each row links to the rendered walkthrough in these docs. Use Source to open the .ipynb on GitHub or browse the full catalog in examples/README.md.

Notebook

What it demonstrates

Source

Shapley vs Banzhaf on toy cooperative games

Shapley and Banzhaf aggregators on majority vs additive games; ExplainResult labelling and RunManifest wire format. CPU-only.

GitHub

Coalition masking and absence policies

Token partition, delete/pad/neutral absence policies, MaskedSnapshot, MaskCodec, and MaskSpace. CPU-only.

GitHub

Runtime archive, deduplication, and async scheduling

Run archive persistence, coalition dedup keys, hot LRU cache, and async InferenceScheduler metrics. CPU-only.

GitHub

Exact estimation with estimand plugins

ExactEstimator coalition enumeration and estimate_attributions() estimand delegation with budget guards. CPU-only.

GitHub

Estimator comparison: budget, variance, and accuracy

Eight-player benchmark (cap ≤ 20) plus five-player fraction sweep 0.1–0.5, MC bias analysis, multi-seed L1 vs exact Shapley. CPU-only.

GitHub

Token attribution visualization

Mock exact explain run with token_text and token_bar attribution renderers. Requires [viz].

GitHub

End-to-end text explainability

Refund-policy prompt explained with LM Studio and transformers backends on the same model id, then visualized with render_attribution(). Optional LM Studio at runtime.

GitHub