Pipeline configuration¶
Explain pipeline configuration schema.
- class nlp_shap.pipeline.config.BackendConfig(*, kind: str, model_id: str, api_host: str | None = None, hub_search: str | None = None, quantization: str = 'Q4_K_M', auto_download: bool = True, serialize_generate: bool = True)[source]¶
Bases:
BaseModelBackend selection and connection parameters.
- model_config = {'extra': 'forbid', 'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class nlp_shap.pipeline.config.GenerationConfig(*, max_new_tokens: int = 128, temperature: float = 0.0, top_k: int = 1, precompute_base: bool = True)[source]¶
Bases:
BaseModelGeneration parameters for the base and coalition evaluations.
- model_config = {'extra': 'forbid', 'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class nlp_shap.pipeline.config.BudgetConfig(*, fraction: Annotated[float, Gt(gt=0.0), Le(le=1.0)] = 1.0)[source]¶
Bases:
BaseModelEstimator budget controls replacing standard/limited split configs.
- model_config = {'extra': 'forbid', 'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class nlp_shap.pipeline.config.ArchiveConfig(*, path: str = './runs/{run_id}', flush_every: Annotated[int, Ge(ge=1)] = 50)[source]¶
Bases:
BaseModelRun archive persistence options.
- model_config = {'extra': 'forbid', 'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class nlp_shap.pipeline.config.DedupConfig(*, enabled: Literal['auto', 'on', 'off'] = 'auto')[source]¶
Bases:
BaseModelCoalition deduplication options.
- model_config = {'extra': 'forbid', 'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class nlp_shap.pipeline.config.KvCacheConfig(*, enabled: bool = True)[source]¶
Bases:
BaseModelPrefix cache options for supported backends.
- model_config = {'extra': 'forbid', 'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class nlp_shap.pipeline.config.NeymanConfig(*, use_standard_method: bool = False, initial_fraction: float | None = None, initial_num_samples: int | None = None)[source]¶
Bases:
BaseModelNeyman-CC estimator controls used when
estimatorisneyman_cc.- model_config = {'extra': 'forbid', 'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class nlp_shap.pipeline.config.ExplanationConfig(*, estimand: Estimand = Estimand.SHAPLEY, estimator: str = 'neyman_cc', value_fn: str = 'tfidf_cosine', normalizer: str = 'identity', players: str = 'tokens', absence_policy: str = 'delete', budget: BudgetConfig = BudgetConfig(fraction=1.0), include_minimal_masks: bool = False, neyman: NeymanConfig = NeymanConfig(use_standard_method=False, initial_fraction=None, initial_num_samples=None), max_inflight: Annotated[int, Ge(ge=1)] = 2, archive: ArchiveConfig = ArchiveConfig(path='./runs/{run_id}', flush_every=50), dedup: DedupConfig = DedupConfig(enabled='auto'), kv_cache: KvCacheConfig = KvCacheConfig(enabled=True), embedding_mode: EmbeddingMode = EmbeddingMode.STATIC, seed: int = 42)[source]¶
Bases:
BaseModelExplanation algorithm and runtime controls.
- model_config = {'extra': 'forbid', 'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- budget: BudgetConfig¶
Estimator budget controls.
- neyman: NeymanConfig¶
Neyman-CC controls applied when the Neyman estimator is selected.
- archive: ArchiveConfig¶
Run archive persistence settings.
- dedup: DedupConfig¶
Coalition deduplication settings.
- kv_cache: KvCacheConfig¶
Prefix cache settings for supported backends.
- embedding_mode: EmbeddingMode¶
Embedding mode used by embedding-based value functions.
- class nlp_shap.pipeline.config.ExplainConfig(*, backend: BackendConfig, generation: GenerationConfig = GenerationConfig(max_new_tokens=128, temperature=0.0, top_k=1, precompute_base=True), explanation: ExplanationConfig = ExplanationConfig(estimand=<Estimand.SHAPLEY: 'shapley'>, estimator='neyman_cc', value_fn='tfidf_cosine', normalizer='identity', players='tokens', absence_policy='delete', budget=BudgetConfig(fraction=1.0), include_minimal_masks=False, neyman=NeymanConfig(use_standard_method=False, initial_fraction=None, initial_num_samples=None), max_inflight=2, archive=ArchiveConfig(path='./runs/{run_id}', flush_every=50), dedup=DedupConfig(enabled='auto'), kv_cache=KvCacheConfig(enabled=True), embedding_mode=<EmbeddingMode.STATIC: 'static'>, seed=42))[source]¶
Bases:
BaseModelTop-level explain pipeline configuration.
- model_config = {'extra': 'forbid', 'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- backend: BackendConfig¶
Backend selection and connection parameters.
- generation: GenerationConfig¶
Generation parameters for base and coalition evaluations.
- explanation: ExplanationConfig¶
Explanation algorithm and runtime controls.
- nlp_shap.pipeline.config.explain_config_from_yaml(text: str) ExplainConfig[source]¶
Parse YAML text into a validated
ExplainConfig.
- nlp_shap.pipeline.config.explain_config_to_yaml(config: ExplainConfig) str[source]¶
Serialize a config to YAML with stable key ordering within sections.
Explain pipeline result types.
- class nlp_shap.pipeline.result.ExplainResult(estimand: Estimand, values: tuple[float, ...])[source]¶
Bases:
objectAttribution output for a single explain run.
- class nlp_shap.pipeline.result.ExplainRunOutput(result: ExplainResult, metrics: SchedulerMetrics, run_id: str, manifest: RunManifest, perf: PerfSummary | None = None)[source]¶
Bases:
objectExplain pipeline output including scheduler metrics.
- result: ExplainResult¶
Aggregated and normalized attribution values.
- metrics: SchedulerMetrics¶
Coalition scheduler counters for the run.
- manifest: RunManifest¶
Manifest metadata persisted with optional archives.
- perf: PerfSummary | None¶
Optional wall-clock breakdown for the run.
Run archive manifest schema stubs.
- class nlp_shap.pipeline.manifest.RunManifestPayload[source]¶
Bases:
TypedDictJSON-compatible manifest payload persisted with a run archive.
- class nlp_shap.pipeline.manifest.RunManifest(estimand: Estimand, run_id: str)[source]¶
Bases:
objectTop-level metadata persisted alongside a run archive.
- to_dict() RunManifestPayload[source]¶
Serialize manifest fields to JSON-compatible primitives.
- nlp_shap.pipeline.manifest.parse_manifest(payload: RunManifestPayload) RunManifest[source]¶
Parse a typed manifest payload into a run manifest.
Public explain pipeline entry point.
- class nlp_shap.pipeline.runner.ExplainRunner(config: ExplainConfig, registry: PluginRegistry | None = None, telemetry: ObservabilitySink | None = None, progress: CoalitionProgress | None = None)[source]¶
Bases:
objectRun the explain pipeline for a conversation snapshot.
- async explain(snapshot: ConversationSnapshot) ExplainRunOutput[source]¶
Execute the async explain pipeline.
- explain_sync(snapshot: ConversationSnapshot) ExplainRunOutput[source]¶
Execute the explain pipeline on the current event loop policy.
- reanalyze(archive_root: Path | str) ExplainRunOutput[source]¶
Rescore an archived run with the runner’s current explain settings.
Explain pipeline orchestration.
- class nlp_shap.pipeline.orchestrator.ExplainOrchestrator(context: ExplainContext, backend: GenerativeBackend)[source]¶
Bases:
objectWire partition, sampling, generation, scoring, and aggregation.
- async run() ExplainRunOutput[source]¶
Execute the configured explain pipeline and return attributions.