incerto.llm.SemanticEntropy#
- class incerto.llm.SemanticEntropy[source]#
Bases:
objectSemantic entropy - entropy over semantically clustered responses.
Clusters responses by meaning (not exact text) and computes entropy. Requires a semantic similarity model.
- Reference:
Kuhn et al., “Semantic Uncertainty: Linguistic Invariances for Uncertainty Estimation in Natural Language Generation”, ICLR 2023.
- __init__()#
Methods
__init__()compute(responses[, similarity_threshold, ...])Compute semantic entropy by clustering similar responses.
- static compute(responses, similarity_threshold=0.85, embedding_model=None)[source]#
Compute semantic entropy by clustering similar responses.
- Parameters:
- Returns:
semantic_entropy: Entropy over semantic clusters
num_clusters: Number of semantic clusters found
clusters: List of cluster assignments
- Return type:
Dictionary with