Domain types¶
Domain types for cooperative-game explainability.
@domain domain @see [[knowledge/architecture/domain]]
Conversation and explanation enumerations for the text MVP.
@domain domain @see [[knowledge/architecture/domain]] @tested-by [[tests/domain/test_enums.py]]
- class mllm_shap.domain.enums.Role(*values)[source]¶
Bases:
StrEnumParticipant role attached to a message or token.
- USER = 'user'¶
End-user or human-provided input.
- ASSISTANT = 'assistant'¶
Model-generated output.
- SYSTEM = 'system'¶
System-level instruction or steering text.
- mllm_shap.domain.enums.RoleName¶
A
Rolevalue as plugin options spell it.alias of
Literal[‘user’, ‘assistant’, ‘system’]
- class mllm_shap.domain.enums.EmbeddingMode(*values)[source]¶
Bases:
StrEnumWhether value functions use static or contextual embeddings.
- STATIC = 'static'¶
Embeddings computed from final generated tokens only.
- CONTEXTUAL = 'contextual'¶
Embeddings derived from model internal states.
Immutable conversation snapshots without backend or IO.
@domain domain @see [[knowledge/architecture/domain]] @tested-by [[tests/domain/test_conversation.py]]
- class mllm_shap.domain.conversation.TextPart(text: str)[source]¶
Bases:
objectText content of a message.
- class mllm_shap.domain.conversation.AudioPart(source: Path | bytes, sample_rate: int)[source]¶
Bases:
objectAudio content of a message, held in memory or referenced by path.
- mllm_shap.domain.conversation.ContentPart = mllm_shap.domain.conversation.TextPart | mllm_shap.domain.conversation.AudioPart¶
One part of a message’s content.
- class mllm_shap.domain.conversation.Message(role: Role, text: str | None = None, content: tuple[TextPart | AudioPart, ...] | None = None, speaker: str | None = None)[source]¶
Bases:
objectOne message of a conversation: a role and ordered content parts.
Build text messages with
Message(role=..., text=...)and multimodal messages withMessage(role=..., content=(TextPart(...), AudioPart(...))).- with_text(text: str) Message[source]¶
Return a copy whose text parts are replaced by one part holding
text.Non-text parts keep their order; the new text part takes the position of the first text part (or comes first when the message had none).
- with_audio(audio: AudioPart) Message[source]¶
Return a copy whose first audio part is replaced by
audio.- Raises:
ValueError – If the message has no audio part.
- class mllm_shap.domain.conversation.Turn(messages: tuple[Message, ...])[source]¶
Bases:
objectOne conversational turn composed of ordered messages.
- class mllm_shap.domain.conversation.PartPayload[source]¶
Bases:
TypedDictJSON form of one content part.
- text: NotRequired[str]¶
Text of a text part.
- path: NotRequired[str]¶
Audio file of an audio part, relative to the snapshot’s
base_dir.
- data: NotRequired[str]¶
Base64 audio bytes of an audio part, instead of
path.
- sample_rate: NotRequired[int]¶
Sample rate of an audio part in hertz.
- class mllm_shap.domain.conversation.MessagePayload[source]¶
Bases:
TypedDictJSON form of a message:
textfor one text part, elsecontent.- text: NotRequired[str]¶
Message text, when the message is a single text part.
- content: NotRequired[list[PartPayload]]¶
Ordered content parts, for messages with audio or several parts.
- speaker: NotRequired[str]¶
Speaker name; omitted when the message has none.
- class mllm_shap.domain.conversation.TurnPayload[source]¶
Bases:
TypedDictJSON form of a turn.
- messages: list[MessagePayload]¶
Ordered messages of the turn.
- class mllm_shap.domain.conversation.SnapshotPayload[source]¶
Bases:
TypedDictJSON form of a text conversation snapshot.
- turns: list[TurnPayload]¶
Ordered turns of the conversation.
- snapshot_id: NotRequired[str]¶
Snapshot id when it is not the one derived from the content.
- class mllm_shap.domain.conversation.ConversationSnapshot(turns: tuple[Turn, ...], snapshot_id: str)[source]¶
Bases:
objectFrozen conversation state used as the explainability input.
- classmethod from_turns(turns: tuple[Turn, ...]) Self[source]¶
Build a snapshot with a stable content-derived identifier.
- messages() tuple[Message, ...][source]¶
Return every message in conversation order (turns flattened).
- classmethod from_json(text: str, base_dir: Path | None = None) Self[source]¶
Parse
{"turns": [{"messages": [{"role": ..., "text": ...}]}]}.A message may add
"speaker", and gives either"text"or a"content"list of{"type": "text", "text": ...}and{"type": "audio", "path" or "data": ..., "sample_rate": ...}parts; relative audio paths resolve againstbase_dir(default: the working directory) and"data"is base64. An optional top-level"snapshot_id"sets the id; without it the id is derived from the content, as infrom_turns().- Raises:
ValueError – If
textis not valid JSON, a role is unknown, or a turn, the snapshot or its id is empty.TypeError – If the JSON does not have the documented shape.
- to_json(indent: int | None = 2) str[source]¶
Serialize the snapshot in the
from_json()format."snapshot_id"is written only when it differs from the id derived from the content, sofrom_json()restores the same id either way. Audio held in memory is written as base64"data", audio files as"path".
Player indexing for cooperative-game explainability.
@domain domain @see [[knowledge/architecture/domain]] @tested-by [[tests/domain/test_players.py]]
- class mllm_shap.domain.players.PlayerSpan(message_index: int, start: int, end: int, text: str, speaker: str | None = None, label: str | None = None, samples: tuple[int, int] | None = None)[source]¶
Bases:
objectWhere one player sits in the conversation it was partitioned from.
- label: str | None¶
Display label set by the partitioner;
display_labelfalls back to the text.
- class mllm_shap.domain.players.PlayerSet(player_ids: tuple[str, ...], spans: tuple[PlayerSpan, ...] = (), hidden_text: tuple[int, ...] = ())[source]¶
Bases:
objectOrdered explainability players aligned with coalition masks.
- spans: tuple[PlayerSpan, ...]¶
Player locations in mask order, filled by the partitioner.
Absence policies and label helpers need them; estimators do not.
Message indices whose text parts absence policies drop from every coalition: a transcript used only to align the audio, which the model must not read.
Coalition masks over explainability players.
@domain domain @see [[knowledge/architecture/domain]] @tested-by [[tests/domain/test_coalition.py]]
- class mllm_shap.domain.coalition.CoalitionMask(present: tuple[bool, ...])[source]¶
Bases:
objectBoolean presence mask aligned with a player set.
Cooperative-game domain types.
@domain domain @see [[knowledge/architecture/domain]] @tested-by [[tests/domain/test_game.py]]
- class mllm_shap.domain.game.CooperativeGame(player_set: PlayerSet)[source]¶
Bases:
objectPlayer set and reference values for a characteristic function.
Generation payloads scored by value functions.
@domain domain @see [[knowledge/architecture/domain]]
- class mllm_shap.domain.generation.GenerationRecord(text: str, text_token_rows: tuple[tuple[int, ...], ...] = (), audio_token_rows: tuple[tuple[int, ...], ...] = (), logprobs: tuple[float, ...] | None = None, embedding: tuple[float, ...] = (), contextual_embedding: tuple[float, ...] = ())[source]¶
Bases:
objectConcrete generation output consumed by built-in value functions.
- text_token_rows: tuple[tuple[int, ...], ...] = ()¶
Token rows hashed for TF-IDF similarity (multimodal text stream).
- audio_token_rows: tuple[tuple[int, ...], ...] = ()¶
Token rows hashed for TF-IDF similarity (multimodal audio stream).
Estimand labels for attribution outputs and archive manifests.
@domain domain @see [[knowledge/architecture/domain]] @tested-by [[tests/domain/test_estimands.py]]
- mllm_shap.domain.estimands.EstimandWire¶
Wire values used in manifests and configuration payloads.
alias of
Literal[‘shapley’, ‘banzhaf’]
- class mllm_shap.domain.estimands.Estimand(*values)[source]¶
Bases:
StrEnumSupported cooperative-game value formulations.
- SHAPLEY = 'shapley'¶
Shapley value with coalition weights k!(n-k-1)!/n!.
- BANZHAF = 'banzhaf'¶
Banzhaf index with uniform coalition weights 1/2^(n-1).
- mllm_shap.domain.estimands.estimand_to_wire(estimand: Estimand) Literal['shapley', 'banzhaf'][source]¶
Serialize an estimand enum member to its wire value.
Generation and runtime settings shared by backends, runtime and pipeline.
@domain domain @see [[knowledge/architecture/domain]]
- class mllm_shap.domain.config.GenerationConfig(*, max_new_tokens: int = 128, temperature: float = 0.0, top_k: int = 1, compute_embeddings: bool = False)[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 mllm_shap.domain.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 mllm_shap.domain.config.KvCacheConfig(*, enabled: bool = False, max_entries: Annotated[int, Ge(ge=1)] = 8)[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].