Create example.py
Browse files- example.py +117 -0
example.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Minimal usage example for hv-tail.
|
| 3 |
+
|
| 4 |
+
python example.py
|
| 5 |
+
|
| 6 |
+
Scores five contrasting queries, shows the requery-history effect,
|
| 7 |
+
and demonstrates calibration on both narrow-gap and wide-gap labeled
|
| 8 |
+
data.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from hv_tail import HVTail
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
QUERIES = [
|
| 15 |
+
("mean", "what is a black hole"),
|
| 16 |
+
("borderline",
|
| 17 |
+
"explain this in the style of a Feynman diagram but not the "
|
| 18 |
+
"standard textbook version"),
|
| 19 |
+
("tail",
|
| 20 |
+
"in the language of category theory, is there a functor from the "
|
| 21 |
+
"black hole information paradox to a broader framework of "
|
| 22 |
+
"unitarity that doesn't assume the standard measurement postulate?"),
|
| 23 |
+
("meta",
|
| 24 |
+
"your reasoning on that last answer seems inconsistent with what "
|
| 25 |
+
"you said earlier. can you explain your calibration? are you sure "
|
| 26 |
+
"the assumption you made is defensible?"),
|
| 27 |
+
("undecidable",
|
| 28 |
+
"is it even possible to prove whether the halting problem is "
|
| 29 |
+
"well-defined, or does it depend on the model of computation?"),
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
HISTORY = [
|
| 33 |
+
"what is a black hole",
|
| 34 |
+
"but why does the horizon have no local features",
|
| 35 |
+
"and does that mean information is destroyed",
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def main() -> None:
|
| 40 |
+
m = HVTail()
|
| 41 |
+
|
| 42 |
+
print("=" * 72)
|
| 43 |
+
print("Scores for contrasting queries")
|
| 44 |
+
print("=" * 72)
|
| 45 |
+
print(f" {'name':<12} {'score':>7} {'above':>6} {'below':>6} "
|
| 46 |
+
f"{'conf':>6} recommendation")
|
| 47 |
+
print(" " + "-" * 68)
|
| 48 |
+
for name, q in QUERIES:
|
| 49 |
+
r = m.score(q)
|
| 50 |
+
print(
|
| 51 |
+
f" {name:<12} {r['raw_score']:>7.3f} "
|
| 52 |
+
f"{str(r['above_ceiling']):>6} "
|
| 53 |
+
f"{str(r['below_ceiling']):>6} "
|
| 54 |
+
f"{r['confidence']:>6.3f} {r['recommendation']}"
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
print()
|
| 58 |
+
print("=" * 72)
|
| 59 |
+
print("Requery history effect")
|
| 60 |
+
print("=" * 72)
|
| 61 |
+
q = "then how does Hawking radiation preserve unitarity"
|
| 62 |
+
r_no = m.score(q)
|
| 63 |
+
r_with = m.score(q, history=HISTORY)
|
| 64 |
+
print(f" query: {q}")
|
| 65 |
+
print(f" without history : raw={r_no['raw_score']:.3f} "
|
| 66 |
+
f"above={r_no['above_ceiling']} rec={r_no['recommendation']}")
|
| 67 |
+
print(f" with history : raw={r_with['raw_score']:.3f} "
|
| 68 |
+
f"above={r_with['above_ceiling']} rec={r_with['recommendation']}")
|
| 69 |
+
|
| 70 |
+
print()
|
| 71 |
+
print("=" * 72)
|
| 72 |
+
print("Calibration: narrow gap")
|
| 73 |
+
print("=" * 72)
|
| 74 |
+
m2 = HVTail()
|
| 75 |
+
narrow_above = [
|
| 76 |
+
QUERIES[2][1], # tail
|
| 77 |
+
QUERIES[3][1], # meta
|
| 78 |
+
"is there a way to prove this without the standard theorem?",
|
| 79 |
+
]
|
| 80 |
+
narrow_below = [
|
| 81 |
+
QUERIES[0][1], # mean
|
| 82 |
+
"how do I make coffee",
|
| 83 |
+
"what time is it",
|
| 84 |
+
]
|
| 85 |
+
a, b = m2.calibrate(narrow_above, narrow_below)
|
| 86 |
+
print(f" above={a:.4f} below={b:.4f} gap={a-b:.4f}")
|
| 87 |
+
|
| 88 |
+
print()
|
| 89 |
+
print("=" * 72)
|
| 90 |
+
print("Calibration: wide gap")
|
| 91 |
+
print("=" * 72)
|
| 92 |
+
m3 = HVTail()
|
| 93 |
+
wide_above = [
|
| 94 |
+
QUERIES[2][1], # tail
|
| 95 |
+
QUERIES[3][1], # meta
|
| 96 |
+
"is there a way to prove the category of endofunctors is "
|
| 97 |
+
"monoidal without appealing to the standard coherence theorem?",
|
| 98 |
+
]
|
| 99 |
+
wide_below = [
|
| 100 |
+
QUERIES[0][1], # mean
|
| 101 |
+
"how do I make coffee",
|
| 102 |
+
"what time is it",
|
| 103 |
+
"explain photosynthesis",
|
| 104 |
+
"what is the capital of France",
|
| 105 |
+
]
|
| 106 |
+
a, b = m3.calibrate(wide_above, wide_below)
|
| 107 |
+
print(f" above={a:.4f} below={b:.4f} gap={a-b:.4f}")
|
| 108 |
+
|
| 109 |
+
print()
|
| 110 |
+
print("=" * 72)
|
| 111 |
+
print("Verbose example (the tail query)")
|
| 112 |
+
print("=" * 72)
|
| 113 |
+
print(m.explain(QUERIES[2][1]))
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
if __name__ == "__main__":
|
| 117 |
+
main()
|