Spaces:
Sleeping
Sleeping
File size: 2,366 Bytes
a66815f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | def generate_explanation(
confidence: float,
risk: str,
claim_results: list[dict],
robustness: float
) -> list[str]:
"""
Build structured, human-readable reasons from signals.
Each item is a standalone insight the user can act on.
"""
reasons = []
# Creative tasks have a completely different interpretation
if risk == "CREATIVE":
reasons.append("This is a creative task β variation across outputs is expected and normal.")
reasons.append("Confidence reflects output quality and fluency, not factual accuracy.")
if confidence > 0.65:
reasons.append("The response appears well-formed and stylistically coherent.")
else:
reasons.append("The response may benefit from more specificity or structure.")
return reasons
if robustness < 0.6:
reasons.append("Model responses varied significantly across sampling runs.")
if robustness >= 0.6 and robustness < 0.8:
reasons.append("Moderate consistency across response variants.")
contradicted = sum(1 for c in claim_results if c["status"] == "contradicted")
uncertain = sum(1 for c in claim_results if c["status"] == "uncertain")
supported = sum(1 for c in claim_results if c["status"] == "supported")
if supported > 0:
reasons.append(f"{supported} claim{'s' if supported > 1 else ''} verified as factually supported.")
if contradicted == 1:
reasons.append("1 claim appears to be factually incorrect β highlighted in the response.")
elif contradicted > 1:
reasons.append(f"{contradicted} claims appear to be factually incorrect β highlighted in the response.")
if uncertain == 1:
reasons.append("1 claim could not be independently verified.")
elif uncertain > 1:
reasons.append(f"{uncertain} claims could not be independently verified.")
if confidence > 0.8 and (contradicted > 0 or uncertain > 0):
reasons.append("Model shows signs of overconfidence β the score is high despite unverifiable claims.")
if risk == "RISKY" and not reasons:
reasons.append("High contradiction rate or very low verifiability β treat with significant caution.")
if not reasons:
reasons.append("All signals are within acceptable ranges. The response appears reliable.")
return reasons
|