End-to-end explain pipeline

The explain pipeline wires masking, runtime, estimation, and value-function plugins into a single run.

Quick start

from nlp_shap import ExplainConfig, ExplainRunner
from nlp_shap.domain.conversation import ConversationSnapshot, Message, Turn
from nlp_shap.domain.enums import Role

snapshot = ConversationSnapshot.from_turns((
    Turn(messages=(Message(role=Role.USER, text="hello world"),)),
))
config = ExplainConfig.model_validate({
    "backend": {"kind": "mock", "model_id": "stub"},
    "explanation": {
        "estimator": "exact",
        "estimand": "shapley",
        "value_fn": "tfidf_cosine",
        "normalizer": "identity",
    },
})

output = ExplainRunner(config).explain_sync(snapshot)
print("values:", output.result.values)
print("requested:", output.metrics.requested)
print("executed:", output.metrics.executed)

Output

values: (0.2747891770937262, 0.2747891770937262)
requested: 3
executed: 3

The mock backend is deterministic and requires no GPU or optional extras. delete, pad, and neutral absence policies all support the empty coalition required by exact Shapley (delete yields empty message text).

For remote or local model servers see Generative backends.

See Configuration for the full configuration schema.