value¶
Responsibility¶
Score one coalition generation against the Base generation; the score is the coalition payoff
v(S)(Value function).Build the generation records both
explainandreanalyzescore.
Public surface¶
TfIdfCosineValue(tfidf_cosine, the default): aFittableValueFunction.fit(corpus)freezes inverse document frequencies over the base and all coalition records.scoreis the cosine similarity of term frequency-inverse document frequency (TF-IDF) vectors built fromtext_token_rowsofGenerationRecordinputs.EmbeddingValue: abstract base holding the embedding mode (explanation.embedding_modethrough the plugin context), the provider andscore;needs_embeddingsis true, so subclasses satisfyRequiresEmbeddings(Embeddings computed only when the value function needs them).CosineEmbeddingValue(embedding_cosine) andEuclideanEmbeddingValue(embedding_euclidean,1 / (1 + distance)) setregistered_nameand the metric. Both readembedding, orcontextual_embeddingincontextualmode.ReferenceWerValue(reference_wer, optionreference):1 - min(1, word_error_rate(target, candidate)), the target beingreferenceor the base text;word_error_rateis word-level Levenshtein over lowercased[\w']+words (empty reference: 0 or 1).LogprobValue(logprob): mean of the candidate’slogprobs(0 for an empty generation); ignores the base;needs_logprobsmakes itRequiresLogprobs; a record withlogprobs is NoneraisesLogprobsUnavailableError(logprob value).generation_record_from_text(text, context_id=None): token rows fromtext.split()withstable_token_id(56-bitblake2b) and 8-dimensionalhash_embeddingvectors.embedding = hash_embedding(text)andcontextual_embedding = hash_embedding(text + "\0"), so every field depends on the generated text only.context_idis ignored and emits aDeprecationWarning(removal in 0.2.0; Contextual hash embedding derived from text only).Private helpers:
_metrics.py(cosine and Euclidean similarity),_token_hash.py(TokenHasher, maps token rows to dense ids).
Data flow¶
Invariants¶
explainandreanalyzescore the same records for text-based value functions andlogprob, and for embedding value functions when the backend has no model embeddings. They return the same values on the same archive (C15).TF-IDF weights are fitted once per scoring pass on exactly the corpus that is scored (both Neyman phases are rescored together).
score(base, base)is the grand-coalition payoff; fortfidf_cosineit is 1 for any non-empty base text.
Known issues¶
Embedding values of a transformers run differ between
explain(model embeddings) andreanalyze(hash embeddings of archived text), because archives store text only; documented in the 0.1.18 release notes.Fixed: C08, C15 (Fixed issues).