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.
Toy-game walkthrough¶
The notebook below is rendered inline. It compares Shapley and Banzhaf aggregators on a three-player majority game and shows why estimand labelling matters.
Masking walkthrough¶
Partition a conversation into token players, build shared masked views, and compare delete, pad, and neutral absence policies.
Runtime walkthrough¶
Persist coalition rows, deduplicate repeated masks, and schedule async generation with bounded concurrency.
Exact estimation walkthrough¶
Enumerate every coalition on tiny player sets and delegate attribution to Shapley or Banzhaf estimand plugins.
Gallery¶
- estimands_toy_game.ipynb
End-to-end walkthrough of the 0.1.1 estimand API: Shapley and Banzhaf aggregators (labels, coalition weights, aggregation), majority vs additive games,
ExplainResultlabelling,RunManifestwire format, and plugin entry-point resolution. CPU-only; no optional extras.- masking_views.ipynb
End-to-end walkthrough of the 0.1.3 masking API: token partition,
DeletePolicy,PadPolicy, andNeutralPolicy(defaults and custom parameters),MaskedSnapshot,MaskCodec,MaskSpace, plugin registry resolution, and validation guards. CPU-only; no optional extras.- runtime_core.ipynb
End-to-end walkthrough of the 0.1.4 runtime API: run archive persistence, coalition dedup keys, hot LRU cache, and async
InferenceSchedulerwith scheduler metrics. CPU-only; no optional extras.- exact_estimation.ipynb
End-to-end walkthrough of the 0.1.5 exact estimation API:
ExactEstimatorenumeration,estimate_attributions()estimand delegation, budget guard, and plugin resolution. CPU-only; no optional extras.