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.

Source on GitHub