Value functions¶
Coalition utility scoring plugins.
@domain value @see [[knowledge/architecture/value]]
Frozen-corpus TF-IDF cosine value function.
@domain value @see [[knowledge/architecture/value]] @tested-by [[tests/value/test_tfidf.py]]
- class mllm_shap.value.tfidf.TfIdfCosineValue(context: PluginContext | None = None)[source]¶
Bases:
objectScore generations with cosine similarity of frozen TF-IDF vectors.
- options_model¶
Accepts no
explanation.plugin_options.alias of
PluginOptions
- fit(corpus: Sequence[GenerationRecord]) None[source]¶
Freeze inverse document frequency weights from
corpus.
- score(base: GenerationResult, candidate: GenerationResult) float[source]¶
Return TF-IDF cosine similarity between
candidateandbase.
Embedding-based value functions.
@domain value @see [[knowledge/architecture/value]] @tested-by [[tests/value/test_embedding.py]]
- class mllm_shap.value.embedding.EmbeddingValue(context: PluginContext | None = None, embedding_mode: EmbeddingMode = EmbeddingMode.STATIC, provider: EmbeddingProvider | None = None)[source]¶
Bases:
ABCSimilarity between static or contextual embedding vectors.
- options_model¶
Accepts no
explanation.plugin_options.alias of
PluginOptions
- score(base: GenerationResult, candidate: GenerationResult) float[source]¶
Return the similarity of the two embedding vectors.
- class mllm_shap.value.embedding.CosineEmbeddingValue(context: PluginContext | None = None, embedding_mode: EmbeddingMode = EmbeddingMode.STATIC, provider: EmbeddingProvider | None = None)[source]¶
Bases:
EmbeddingValueCosine similarity between static or contextual embeddings (U1/U2).
- class mllm_shap.value.embedding.EuclideanEmbeddingValue(context: PluginContext | None = None, embedding_mode: EmbeddingMode = EmbeddingMode.STATIC, provider: EmbeddingProvider | None = None)[source]¶
Bases:
EmbeddingValueSimilarity
1 / (1 + distance)between embeddings (U4).
Logprob-based value function.
@domain value @see [[knowledge/architecture/value]] @tested-by [[tests/value/test_logprob.py]]
- class mllm_shap.value.logprob.LogprobValue(context: PluginContext | None = None)[source]¶
Bases:
objectScore a coalition by the model’s confidence in its own generation.
v(S)is the mean natural-log probability of the tokens the backend generated for coalitionS(itsGenerationRecord.logprobs), so it lies in(-inf, 0]; an empty generation scores 0. The base generation is not read:v(N)is the base generation’s own mean logprob.- options_model¶
Accepts no
explanation.plugin_options.alias of
PluginOptions
- score(base: GenerationResult, candidate: GenerationResult) float[source]¶
Return the mean token logprob of
candidate.- Raises:
LogprobsUnavailableError – If
candidatecarries no logprobs.
Word error rate against a reference text as a coalition value.
@domain value @see [[knowledge/architecture/value]] @tested-by [[tests/value/test_wer.py]]
- mllm_shap.value.wer.word_error_rate(reference: str, hypothesis: str) float[source]¶
Return word-level edit distance over the reference’s word count.
Words are lowercased runs of letters, digits,
_and', so case and punctuation do not count. An empty reference gives 0 for an empty hypothesis and 1 otherwise.
- class mllm_shap.value.wer.ReferenceWerOptions(*, reference: str | None = None)[source]¶
Bases:
PluginOptionsOptions of the
reference_wervalue function.- 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.value.wer.ReferenceWerValue(context: PluginContext | None = None)[source]¶
Bases:
objectScore
1 - min(1, WER)of a coalition’s answer against a reference.With
referenceset,v(S)measures how correct the answer is (a transcription task); without it, how close it stays to the full answer. Values lie in[0, 1].- options_model¶
Options accepted from
explanation.plugin_options.alias of
ReferenceWerOptions
- reference¶
Target text;
Nonescores against the base generation.
- score(base: GenerationResult, candidate: GenerationResult) float[source]¶
Return
1 - min(1, WER)ofcandidateagainst the target.
Build generation records from generated text for value-function scoring.
@domain value @see [[knowledge/architecture/value]] @tested-by [[tests/value/test_generation_records.py]]
- mllm_shap.value.generation_records.EMBED_DIM: Final[int] = 8¶
Dimension of the deterministic hash embedding used by mock and archive paths.
- mllm_shap.value.generation_records.generation_record_from_text(text: str, context_id: str | None = None) GenerationRecord[source]¶
Build a record whose token rows and embeddings derive from
textonly.explainandreanalyzeboth score records built here, so a value function sees the same inputs whether the text came from a backend or an archive.contextual_embeddinghashestextwith a separator so it differs fromembedding; it takes no prompt or snapshot id, which a backend sees for the rendered coalition andreanalyzenever sees.- Parameters:
text – Generated text.
context_id – Deprecated and ignored; passing it emits a
DeprecationWarning. It saltedcontextual_embeddinguntil 0.1.18, which made backend records differ fromreanalyze.