Extending nlp-shap¶
nlp-shap is built around a small plugin registry. Third-party packages can
register estimators, value functions, backends, and renderers without forking
the core library.
Optional extras¶
Install only what your deployment needs:
pip install nlp-shap # core only (no torch)
pip install "nlp-shap[transformers]" # Hugging Face text backend
pip install "nlp-shap[lmstudio]" # LM Studio SDK backend
pip install "nlp-shap[api]" # OpenAI-compatible HTTP backend
pip install "nlp-shap[viz]" # matplotlib token attribution charts
Entry-point groups¶
Register plugins under project.entry-points in your package
pyproject.toml:
Group |
Purpose |
|---|---|
|
Coalition sampling strategies ( |
|
Payoff aggregation ( |
|
Coalition scoring utilities ( |
|
Post-aggregation scaling ( |
|
Player definitions ( |
|
Masked snapshot rendering ( |
|
Model inference connectors ( |
|
Attribution visualization ( |
Example custom value function¶
[project.entry-points."nlp_shap.value_fns"]
my_metric = "my_package.values:MyMetricValue"
Your class should satisfy ValueFunction.
Resolve it by name in ExplainConfig:
explanation:
value_fn: my_metric
Running with a custom registry¶
Pass an explicit PluginRegistry to
ExplainRunner when you need to load entry points from
multiple distributions or override builtins in tests:
from nlp_shap import ExplainRunner, PluginRegistry
from nlp_shap.plugins import PluginGroup
registry = PluginRegistry()
registry.load_entry_points(PluginGroup.VALUE_FNS)
runner = ExplainRunner(config, registry=registry)
Further reading¶
Plugins — registry API and built-in groups
Protocols — strategy protocols for plugins
Configuration —
ExplainConfigschema