Protocols¶
Protocol contracts for pipeline plugins.
@domain protocols @see [[knowledge/architecture/protocols]]
Generative backend protocol.
@domain protocols @see [[knowledge/architecture/protocols]]
- class mllm_shap.protocols.backend.GenerationResult(*args, **kwargs)[source]¶
Bases:
ProtocolMinimal generation output consumed by value functions.
- class mllm_shap.protocols.backend.GenerativeBackend(*args, **kwargs)[source]¶
Bases:
ProtocolExecute model generation for a masked conversation snapshot.
- async generate(snapshot: ConversationSnapshot, generation: GenerationConfig) GenerationResult[source]¶
Generate model output for the given snapshot.
- class mllm_shap.protocols.backend.SupportsKvCache(*args, **kwargs)[source]¶
Bases:
ProtocolBackend that can reuse prompt-prefix KV state across coalitions.
- class mllm_shap.protocols.backend.SupportsLogprobs(*args, **kwargs)[source]¶
Bases:
ProtocolBackend whose records carry
GenerationRecord.logprobs.The
logprobvalue function requires it; a record that still arrives without logprobs (a server that omits them) raisesLogprobsUnavailableErrorwhen scored.
- class mllm_shap.protocols.backend.SupportsAclose(*args, **kwargs)[source]¶
Bases:
ProtocolBackend holding resources (clients, models) released by
aclose.
Estimator strategy protocols.
@domain protocols @see [[knowledge/architecture/protocols]]
- class mllm_shap.protocols.estimator.EstimatorStrategy(*args, **kwargs)[source]¶
Bases:
ProtocolSample coalitions and turn their payoffs into attributions.
- bind_snapshot(snapshot: ConversationSnapshot) None[source]¶
Attach the conversation snapshot under explanation.
- sample_masks(player_set: PlayerSet, budget_fraction: float, include_minimal_masks: bool, seed: int) Iterator[CoalitionMask][source]¶
Yield coalition masks to evaluate for the player set.
- estimate_attributions(masks: Sequence[CoalitionMask], payoffs: Sequence[float], aggregator: EstimandAggregator) list[float][source]¶
Aggregate evaluated coalitions into per-player attributions.
- class mllm_shap.protocols.estimator.TwoPhaseEstimator(*args, **kwargs)[source]¶
Bases:
ProtocolEstimator that allocates a second sampling phase from first-phase payoffs.
- begin_allocation(masks: Sequence[CoalitionMask], payoffs: Sequence[float]) None[source]¶
Consume phase-one payoffs and plan phase two.
- sample_allocation_masks() Iterator[CoalitionMask][source]¶
Yield phase-two coalition masks.
Estimand aggregation protocol.
@domain protocols @see [[knowledge/architecture/protocols]]
- class mllm_shap.protocols.estimand.EstimandAggregator(*args, **kwargs)[source]¶
Bases:
ProtocolAggregate coalition payoffs into per-player attributions.
Value function protocol.
@domain protocols @see [[knowledge/architecture/protocols]]
- class mllm_shap.protocols.value.ValueFunction(*args, **kwargs)[source]¶
Bases:
ProtocolScore coalition utility relative to a base generation.
- score(base: GenerationResult, candidate: GenerationResult) float[source]¶
Return utility for
candidaterelative tobase.
- class mllm_shap.protocols.value.FittableValueFunction(*args, **kwargs)[source]¶
Bases:
ValueFunction,ProtocolValue function that must see the run’s corpus before it scores.
The pipeline calls
fit()with the base generation and every coalition generation before anyscore()call, inexplainandreanalyze.
- class mllm_shap.protocols.value.RequiresLogprobs(*args, **kwargs)[source]¶
Bases:
ProtocolValue function that scores
GenerationRecord.logprobs.When
needs_logprobsis true the pipeline refuses backends that are notSupportsLogprobsandreanalyzerefuses archives whose rows have no logprobs.
- class mllm_shap.protocols.value.RequiresEmbeddings(*args, **kwargs)[source]¶
Bases:
ProtocolValue function that scores model embeddings rather than text.
When
needs_embeddingsis true the pipeline setsGenerationConfig.compute_embeddingsfor its backend calls, so backends that can (transformers) attach static and contextual embeddings to their records, and scores those records.
Attribution normalizer protocol.
@domain protocols @see [[knowledge/architecture/protocols]]
- class mllm_shap.protocols.normalizer.Normalizer(*args, **kwargs)[source]¶
Bases:
ProtocolScale aggregated attributions for presentation without mutating archives.
Player partition protocol.
@domain protocols @see [[knowledge/architecture/protocols]]
- class mllm_shap.protocols.partition.PlayerPartitioner(*args, **kwargs)[source]¶
Bases:
ProtocolPartition a conversation snapshot into explainability players.
- partition(snapshot: ConversationSnapshot) PlayerSet[source]¶
Derive ordered players and their spans from the snapshot.
The returned
PlayerSetmust carry onePlayerSpanper player; absence policies and labels read the spans instead of re-tokenising.
Masking and absence policy protocols.
@domain protocols @see [[knowledge/architecture/protocols]]
- class mllm_shap.protocols.masking.AbsencePolicy(*args, **kwargs)[source]¶
Bases:
ProtocolRender absent players when building a masked snapshot view.
- apply(snapshot: ConversationSnapshot, players: PlayerSet, mask: CoalitionMask) ConversationSnapshot[source]¶
Return a masked snapshot view for coalition evaluation.
Embedding provider protocol.
@domain protocols @see [[knowledge/architecture/protocols]]
- class mllm_shap.protocols.embedding.EmbeddingProvider(*args, **kwargs)[source]¶
Bases:
ProtocolExpose embeddings for value functions that operate in embedding space.
- embed(generation: GenerationResult) tuple[float, ...][source]¶
Return an embedding vector for the generation.
Attribution renderer protocol.
@domain protocols @see [[knowledge/architecture/protocols]]
- class mllm_shap.protocols.renderer.AttributionRenderer(*args, **kwargs)[source]¶
Bases:
ProtocolRender per-player attribution values for human review.
Options contract for plugins configured through explanation.plugin_options.
@domain protocols @see [[knowledge/architecture/protocols]]
- class mllm_shap.protocols.plugin.PluginOptions[source]¶
Bases:
BaseModelOptions a plugin accepts; the base class accepts none.
Subclasses declare one field per option. Unknown keys and values of the wrong type are rejected (
extra="forbid", strict types; integers are accepted for float fields).- model_config = {'extra': 'forbid', 'frozen': True, 'strict': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class mllm_shap.protocols.plugin.DeclaresPluginOptions(*args, **kwargs)[source]¶
Bases:
ProtocolPlugin class that declares the options it accepts.
The registry validates
explanation.plugin_optionsfor the plugin againstoptions_modelbefore building it. Plugins without the attribute get their options unchecked.- options_model: ClassVar[type[PluginOptions]]¶
Pydantic model listing the accepted options.