""" Minimal usage example for hv-tail. python example.py Scores five contrasting queries, shows the requery-history effect, and demonstrates calibration on both narrow-gap and wide-gap labeled data. """ from hv_tail import HVTail QUERIES = [ ("mean", "what is a black hole"), ("borderline", "explain this in the style of a Feynman diagram but not the " "standard textbook version"), ("tail", "in the language of category theory, is there a functor from the " "black hole information paradox to a broader framework of " "unitarity that doesn't assume the standard measurement postulate?"), ("meta", "your reasoning on that last answer seems inconsistent with what " "you said earlier. can you explain your calibration? are you sure " "the assumption you made is defensible?"), ("undecidable", "is it even possible to prove whether the halting problem is " "well-defined, or does it depend on the model of computation?"), ] HISTORY = [ "what is a black hole", "but why does the horizon have no local features", "and does that mean information is destroyed", ] def main() -> None: m = HVTail() print("=" * 72) print("Scores for contrasting queries") print("=" * 72) print(f" {'name':<12} {'score':>7} {'above':>6} {'below':>6} " f"{'conf':>6} recommendation") print(" " + "-" * 68) for name, q in QUERIES: r = m.score(q) print( f" {name:<12} {r['raw_score']:>7.3f} " f"{str(r['above_ceiling']):>6} " f"{str(r['below_ceiling']):>6} " f"{r['confidence']:>6.3f} {r['recommendation']}" ) print() print("=" * 72) print("Requery history effect") print("=" * 72) q = "then how does Hawking radiation preserve unitarity" r_no = m.score(q) r_with = m.score(q, history=HISTORY) print(f" query: {q}") print(f" without history : raw={r_no['raw_score']:.3f} " f"above={r_no['above_ceiling']} rec={r_no['recommendation']}") print(f" with history : raw={r_with['raw_score']:.3f} " f"above={r_with['above_ceiling']} rec={r_with['recommendation']}") print() print("=" * 72) print("Calibration: narrow gap") print("=" * 72) m2 = HVTail() narrow_above = [ QUERIES[2][1], # tail QUERIES[3][1], # meta "is there a way to prove this without the standard theorem?", ] narrow_below = [ QUERIES[0][1], # mean "how do I make coffee", "what time is it", ] a, b = m2.calibrate(narrow_above, narrow_below) print(f" above={a:.4f} below={b:.4f} gap={a-b:.4f}") print() print("=" * 72) print("Calibration: wide gap") print("=" * 72) m3 = HVTail() wide_above = [ QUERIES[2][1], # tail QUERIES[3][1], # meta "is there a way to prove the category of endofunctors is " "monoidal without appealing to the standard coherence theorem?", ] wide_below = [ QUERIES[0][1], # mean "how do I make coffee", "what time is it", "explain photosynthesis", "what is the capital of France", ] a, b = m3.calibrate(wide_above, wide_below) print(f" above={a:.4f} below={b:.4f} gap={a-b:.4f}") print() print("=" * 72) print("Verbose example (the tail query)") print("=" * 72) print(m.explain(QUERIES[2][1])) if __name__ == "__main__": main()