keepfold 0.6.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- keepfold/__init__.py +1 -0
- keepfold/_proc.py +102 -0
- keepfold/access.py +154 -0
- keepfold/agent_eval.py +162 -0
- keepfold/agent_text.py +56 -0
- keepfold/anki.py +285 -0
- keepfold/app/__init__.py +5 -0
- keepfold/app/actions.py +690 -0
- keepfold/app/desktop.py +677 -0
- keepfold/app/exports.py +254 -0
- keepfold/app/hello.py +79 -0
- keepfold/app/launch.py +114 -0
- keepfold/app/news.py +60 -0
- keepfold/app/server.py +3142 -0
- keepfold/app/status.py +811 -0
- keepfold/app/targets.py +1374 -0
- keepfold/app/winpath.py +54 -0
- keepfold/app/wizard.py +506 -0
- keepfold/ask.py +475 -0
- keepfold/askfile.py +322 -0
- keepfold/assets/LICENSE-d3.txt +13 -0
- keepfold/assets/agent_eval.json +235 -0
- keepfold/assets/app/app.css +611 -0
- keepfold/assets/app/app.js +2712 -0
- keepfold/assets/app/capture.html +16 -0
- keepfold/assets/app/capture.js +91 -0
- keepfold/assets/app/index.html +149 -0
- keepfold/assets/brain3d.js +3730 -0
- keepfold/assets/chat_eval.json +454 -0
- keepfold/assets/d3.v7.min.js +2 -0
- keepfold/assets/dashboard.css +774 -0
- keepfold/assets/dashboard.html.tmpl +170 -0
- keepfold/assets/dashboard.js +4262 -0
- keepfold/assets/help/GUIDE.md +544 -0
- keepfold/assets/help/help.md +83 -0
- keepfold/assets/keepfold.ico +0 -0
- keepfold/assets/whats_new.json +162 -0
- keepfold/backup.py +100 -0
- keepfold/brainmap.py +1382 -0
- keepfold/browse/__init__.py +10 -0
- keepfold/browse/build.py +1320 -0
- keepfold/browse/forget.py +510 -0
- keepfold/browse/legacy.py +95 -0
- keepfold/browse/lists.py +285 -0
- keepfold/browse/privacy.py +391 -0
- keepfold/browse/selftest.py +166 -0
- keepfold/browse/sites.py +1068 -0
- keepfold/browse/sources.py +329 -0
- keepfold/browse/store.py +991 -0
- keepfold/browse/takeout.py +312 -0
- keepfold/browse/titles.py +127 -0
- keepfold/browse/vectors.py +326 -0
- keepfold/browse_serve.py +332 -0
- keepfold/catalog.py +564 -0
- keepfold/chat.py +1464 -0
- keepfold/chat_archive.py +165 -0
- keepfold/chat_eval.py +583 -0
- keepfold/chat_facts.py +721 -0
- keepfold/chat_import.py +1045 -0
- keepfold/chat_pages.py +291 -0
- keepfold/chat_study.py +371 -0
- keepfold/chats.py +669 -0
- keepfold/claims.py +650 -0
- keepfold/cli.py +3254 -0
- keepfold/clients.py +96 -0
- keepfold/cloudllm.py +135 -0
- keepfold/contract.py +43 -0
- keepfold/corrections.py +134 -0
- keepfold/dashboard.py +959 -0
- keepfold/dates.py +202 -0
- keepfold/delta.py +146 -0
- keepfold/digest.py +72 -0
- keepfold/doctor.py +565 -0
- keepfold/duplicates.py +145 -0
- keepfold/egress.py +68 -0
- keepfold/eval_history.py +109 -0
- keepfold/events.py +554 -0
- keepfold/export_context.py +109 -0
- keepfold/fact_harvest.py +578 -0
- keepfold/forget.py +720 -0
- keepfold/harvest.py +334 -0
- keepfold/home.py +714 -0
- keepfold/importers.py +627 -0
- keepfold/index.py +733 -0
- keepfold/know.py +40 -0
- keepfold/learning_eval.py +261 -0
- keepfold/levels.py +595 -0
- keepfold/life_sources.py +747 -0
- keepfold/lint.py +241 -0
- keepfold/localllm.py +699 -0
- keepfold/loops.py +316 -0
- keepfold/mcp_server.py +4464 -0
- keepfold/migrate.py +552 -0
- keepfold/more_sources.py +709 -0
- keepfold/packs.py +148 -0
- keepfold/people.py +99 -0
- keepfold/planner.py +819 -0
- keepfold/prime.py +630 -0
- keepfold/prime_hook.py +265 -0
- keepfold/profiles.py +118 -0
- keepfold/quarantine.py +123 -0
- keepfold/recall_log.py +93 -0
- keepfold/redteam.py +393 -0
- keepfold/reflect.py +164 -0
- keepfold/relink.py +477 -0
- keepfold/render.py +406 -0
- keepfold/review.py +1181 -0
- keepfold/rollups.py +412 -0
- keepfold/safety_net.py +571 -0
- keepfold/sample.py +103 -0
- keepfold/sample_vault/areas/programming.algorithms.md +11 -0
- keepfold/sample_vault/areas/programming.basics.md +11 -0
- keepfold/sample_vault/concepts/big-o-notation.md +13 -0
- keepfold/sample_vault/concepts/functions.md +13 -0
- keepfold/sample_vault/concepts/loops.md +14 -0
- keepfold/sample_vault/concepts/recursion.md +13 -0
- keepfold/sample_vault/domains/programming.md +10 -0
- keepfold/sample_vault/journal/2026-01-12.md +9 -0
- keepfold/sample_vault/me/goals.md +17 -0
- keepfold/sample_vault/me/profile.md +19 -0
- keepfold/sample_vault/mistakes/programming.off-by-one-loop.md +16 -0
- keepfold/sample_vault/notes/recursion-needs-a-base-case.md +18 -0
- keepfold/sample_vault/problems/fizzbuzz.md +12 -0
- keepfold/sample_vault/projects/text-adventure.md +15 -0
- keepfold/sample_vault/resources/python-tutorial.md +16 -0
- keepfold/semantic.py +1254 -0
- keepfold/session.py +764 -0
- keepfold/share.py +69 -0
- keepfold/sources.py +612 -0
- keepfold/sync_copies.py +83 -0
- keepfold/tags.py +230 -0
- keepfold/taint.py +301 -0
- keepfold/tonight.py +195 -0
- keepfold/topics.py +1072 -0
- keepfold/update.py +300 -0
- keepfold/vault.py +942 -0
- keepfold/vecstore.py +218 -0
- keepfold/voice.py +260 -0
- keepfold/voice_memos.py +280 -0
- keepfold/watch.py +303 -0
- keepfold/where.py +119 -0
- keepfold/xray.py +516 -0
- keepfold/zotero.py +303 -0
- keepfold-0.6.4.dist-info/METADATA +644 -0
- keepfold-0.6.4.dist-info/RECORD +148 -0
- keepfold-0.6.4.dist-info/WHEEL +4 -0
- keepfold-0.6.4.dist-info/entry_points.txt +6 -0
- keepfold-0.6.4.dist-info/licenses/LICENSE +21 -0
keepfold/know.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""`keepfold claims --summary` (v6 agenda 9): how well the user model knows the user, per page.
|
|
2
|
+
Live claims by authorship tier. A pure read: every number is folded from the
|
|
3
|
+
claim pages and the event log on the spot, nothing is stored or written. Private me/ pages
|
|
4
|
+
show only as `private`."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections import Counter
|
|
9
|
+
from collections.abc import Iterable
|
|
10
|
+
|
|
11
|
+
from keepfold import claims
|
|
12
|
+
from keepfold.vault import is_private
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def report(vault, events: Iterable[dict], today: str) -> dict:
|
|
16
|
+
"""{pages: [{page, private} | {page, live, tiers, clicked, reflected}], total: {live,
|
|
17
|
+
tiers, clicked, reflected}}. `clicked`: confirmed lines the user ticked in Keepfold's
|
|
18
|
+
own dialog (idea 11); `reflected`: a yes in a clean reflect. Texts are raw note text:
|
|
19
|
+
callers escape."""
|
|
20
|
+
events = list(events)
|
|
21
|
+
private = {n.id for n in vault.iter_notes("me") if is_private(n)}
|
|
22
|
+
rows = claims.tiers(vault, events, today=today) # no log: never records a baseline
|
|
23
|
+
pages, total_t, how = [], Counter(), Counter()
|
|
24
|
+
for page in claims.PAGES:
|
|
25
|
+
if page in private:
|
|
26
|
+
pages.append({"page": page, "private": True})
|
|
27
|
+
continue
|
|
28
|
+
mine = [r for r in rows if r["page"] == page]
|
|
29
|
+
tiers = Counter(r["tier"] for r in mine)
|
|
30
|
+
total_t += tiers
|
|
31
|
+
n = Counter(r["confirm"] for r in mine)
|
|
32
|
+
how += n
|
|
33
|
+
pages.append({
|
|
34
|
+
"page": page, "private": False, "live": len(mine),
|
|
35
|
+
"tiers": {t: tiers[t] for t in claims.TIERS}, "clicked": n["clicked"],
|
|
36
|
+
"reflected": n["reflected"]})
|
|
37
|
+
return {"pages": pages,
|
|
38
|
+
"total": {"live": sum(total_t.values()),
|
|
39
|
+
"tiers": {t: total_t[t] for t in claims.TIERS}, "clicked": how["clicked"],
|
|
40
|
+
"reflected": how["reflected"]}}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"""`keepfold eval learning`: how well the logged `predicted_p` forecasts graded items (v6 item 7).
|
|
2
|
+
|
|
3
|
+
Read-only. Each graded primary item the fold sees (`levels._items`: voids and remaps applied)
|
|
4
|
+
is paired with the `predicted_p` the server stamped on its own event, the FSRS retrievability
|
|
5
|
+
just before the answer. Outcome = the fold's pass rule: correct at hints ≤ 1. Items with no
|
|
6
|
+
stamp (CLI and imported grades, problem_status, old self_reports) are counted, never guessed.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import math
|
|
12
|
+
from collections.abc import Iterable
|
|
13
|
+
|
|
14
|
+
from keepfold import events as _events
|
|
15
|
+
from keepfold import levels
|
|
16
|
+
from keepfold.events import STUDY_MODES, norm_answer
|
|
17
|
+
|
|
18
|
+
BINS = 5
|
|
19
|
+
MIN_PAIRS = 30 # fewer pairs than this in a row: noise
|
|
20
|
+
EPS = 1e-6
|
|
21
|
+
SPLITS = ("mode", "grader", "source", "item_type", "confidence", "first", "prior")
|
|
22
|
+
SPOT_SHOWN = 3 # model-graded answers a reflect pack offers to keep or flip
|
|
23
|
+
# confidence mirror: 10 answers per band (each of the 4 bands is asked)
|
|
24
|
+
MIN_BAND = 10
|
|
25
|
+
CONFIDENCE_LABELS = {1: "1 (guessing)", 2: "2", 3: "3", 4: "4 (certain)"}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _mode(mode: str | None) -> str:
|
|
29
|
+
return "ambient" if mode == "ambient" else "study" if mode in STUDY_MODES else mode or "none"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _grader(it: levels._Item, keys: dict[str, str]) -> str:
|
|
33
|
+
"""Who decided the verdict. The server (`Keepfold._graded`) makes a normalised answer_key
|
|
34
|
+
match `correct`; on a mismatch the model's verdict stands. So for a tutor grade whose ask
|
|
35
|
+
had an answer_key: `key-agrees` = the answer matched (correct) or did not and the model said
|
|
36
|
+
wrong; `key-disagrees` = no match, yet the model said correct or partial (leniency or a
|
|
37
|
+
paraphrase). `model` = a tutor grade with no key; other sources by name (external, self)."""
|
|
38
|
+
ev = it.ev
|
|
39
|
+
if ev.get("source") != "tutor":
|
|
40
|
+
return ev.get("source") or "none"
|
|
41
|
+
key, answer = keys.get(ev.get("ref")), ev.get("learner_answer")
|
|
42
|
+
if not isinstance(key, str):
|
|
43
|
+
return "model"
|
|
44
|
+
match = isinstance(answer, str) and norm_answer(answer) == norm_answer(key)
|
|
45
|
+
return "key-agrees" if match or it.verdict == "wrong" else "key-disagrees"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _spot(e: dict) -> bool:
|
|
49
|
+
return e.get("kind") == "log" and isinstance(e.get("payload"), dict) \
|
|
50
|
+
and e["payload"].get("kind") == "spot_check"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def spot_checks(events: Iterable[dict], limit: int | None = SPOT_SHOWN,
|
|
54
|
+
hide: set[str] = frozenset()) -> list[dict]:
|
|
55
|
+
"""v6 idea 10: the `limit` (None: all) newest live tutor grades on a concept whose verdict
|
|
56
|
+
the model gave (no answer_key match) and no spot_check names yet, as {event_id, concept,
|
|
57
|
+
question, answer, verdict}; concepts in `hide` (planner.hidden) are left out. Question and
|
|
58
|
+
answer are untrusted text."""
|
|
59
|
+
live = _events.live(list(events))
|
|
60
|
+
asks = {e["id"]: e for e in live if e.get("kind") == "ask"}
|
|
61
|
+
done = {e["payload"].get("event") for e in live if _spot(e)}
|
|
62
|
+
rows = []
|
|
63
|
+
for e in sorted(live, key=lambda e: (e["ts"], e["id"]), reverse=True):
|
|
64
|
+
obj = str(e.get("object") or "")
|
|
65
|
+
if (e.get("kind") != "grade" or e.get("source") != "tutor" or e["id"] in done
|
|
66
|
+
or not obj.startswith("concept:") or obj.split(":", 1)[1] in hide):
|
|
67
|
+
continue
|
|
68
|
+
ask = asks.get(e.get("ref"), {})
|
|
69
|
+
key, answer = ask.get("answer_key"), e.get("learner_answer")
|
|
70
|
+
if isinstance(key, str) and isinstance(answer, str) \
|
|
71
|
+
and norm_answer(answer) == norm_answer(key):
|
|
72
|
+
continue # the server's key match decided it, not the model
|
|
73
|
+
rows.append({"event_id": e["id"], "concept": obj.split(":", 1)[1],
|
|
74
|
+
"question": str(e.get("question") or ask.get("question") or ""),
|
|
75
|
+
"answer": str(answer or ""), "verdict": e.get("verdict")})
|
|
76
|
+
if len(rows) == limit:
|
|
77
|
+
break
|
|
78
|
+
return rows
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def agreement(events: Iterable[dict]) -> dict:
|
|
82
|
+
"""How often the user's spot-check verdict matched the model's (`was`)."""
|
|
83
|
+
rows = [e["payload"] for e in _events.live(list(events)) if _spot(e)]
|
|
84
|
+
agree = sum(p.get("verdict") == p.get("was") for p in rows)
|
|
85
|
+
return {"n": len(rows), "agree": agree,
|
|
86
|
+
"rate": round(agree / len(rows), 4) if rows else None}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _headline(pairs: list[tuple[float, int, float]]) -> dict:
|
|
90
|
+
"""pairs of (forecast, pass 0/1, partial-credit score)."""
|
|
91
|
+
n = len(pairs)
|
|
92
|
+
if not n:
|
|
93
|
+
return {"n": 0}
|
|
94
|
+
base = sum(y for _, y, _ in pairs) / n
|
|
95
|
+
brier = sum((p - y) ** 2 for p, y, _ in pairs) / n
|
|
96
|
+
ref = base * (1 - base) # Brier of always forecasting the base rate
|
|
97
|
+
loss = -sum(y * math.log(max(p, EPS)) + (1 - y) * math.log(max(1 - p, EPS))
|
|
98
|
+
for p, y, _ in pairs) / n
|
|
99
|
+
bins = reliability(pairs)
|
|
100
|
+
return {"n": n, "base_rate": round(base, 4), "brier": round(brier, 4),
|
|
101
|
+
"brier_base": round(ref, 4), "skill": round(1 - brier / ref, 4) if ref else None,
|
|
102
|
+
"log_loss": round(loss, 4),
|
|
103
|
+
"gap": round(sum(b["n"] * abs(b["p"] - b["pass"]) for b in bins if b["n"]) / n, 4),
|
|
104
|
+
"brier_partial": round(sum((p - s) ** 2 for p, _, s in pairs) / n, 4),
|
|
105
|
+
"few": n < MIN_PAIRS}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def reliability(pairs: list[tuple[float, int, float]]) -> list[dict]:
|
|
109
|
+
"""5 equal-width bins: mean forecast, observed pass rate, n."""
|
|
110
|
+
rows = [{"lo": i / BINS, "hi": (i + 1) / BINS, "n": 0, "p": 0.0, "pass": 0.0}
|
|
111
|
+
for i in range(BINS)]
|
|
112
|
+
for p, y, _ in pairs:
|
|
113
|
+
row = rows[min(int(p * BINS), BINS - 1)]
|
|
114
|
+
row["n"], row["p"], row["pass"] = row["n"] + 1, row["p"] + p, row["pass"] + y
|
|
115
|
+
for row in rows:
|
|
116
|
+
if row["n"]:
|
|
117
|
+
row["p"], row["pass"] = round(row["p"] / row["n"], 4), round(row["pass"] / row["n"], 4)
|
|
118
|
+
return rows
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _stamped(p) -> bool:
|
|
122
|
+
return not isinstance(p, bool) and isinstance(p, (int, float)) and 0 <= p <= 1
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def cold_pairs(events: Iterable[dict], problem_concepts: dict | None = None,
|
|
126
|
+
) -> list[tuple[float, int, float]]:
|
|
127
|
+
"""The pairs that check the exam-day forecast (B5): stamped graded items on a concept
|
|
128
|
+
already graded or credited, cold (the first on the concept that local day; a warm re-test
|
|
129
|
+
after teaching passes almost surely, so it says nothing about recall across a gap)."""
|
|
130
|
+
pairs, seen = [], set()
|
|
131
|
+
for it in levels._items(events, problem_concepts):
|
|
132
|
+
if it.verdict is None or it.concept is None or it.ev.get("kind") == "ask":
|
|
133
|
+
continue
|
|
134
|
+
p = it.ev.get("predicted_p")
|
|
135
|
+
if it.concept in seen and not it.warm and _stamped(p):
|
|
136
|
+
pairs.append((float(p), int(it.verdict == "correct" and it.hints <= 1),
|
|
137
|
+
levels._score(it)))
|
|
138
|
+
seen.add(it.concept)
|
|
139
|
+
if it.verdict == "correct":
|
|
140
|
+
seen.update(it.also)
|
|
141
|
+
return pairs
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def calibrated(events: Iterable[dict], problem_concepts: dict | None = None,
|
|
145
|
+
) -> tuple[int, bool]:
|
|
146
|
+
"""The exam-day forecast gate: (cold pairs, open). Open needs MIN_PAIRS cold pairs whose
|
|
147
|
+
forecasts beat always forecasting the base rate (Brier skill > 0)."""
|
|
148
|
+
pairs = cold_pairs(events, problem_concepts)
|
|
149
|
+
skill = _headline(pairs).get("skill")
|
|
150
|
+
return len(pairs), len(pairs) >= MIN_PAIRS and skill is not None and skill > 0
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def report(events: Iterable[dict], problem_concepts: dict | None = None,
|
|
154
|
+
since: str | None = None) -> dict:
|
|
155
|
+
"""The calibration report over graded primary items on days ≥ `since`."""
|
|
156
|
+
events = list(events)
|
|
157
|
+
keys = {e["id"]: e.get("answer_key") for e in _events.live(events) if e.get("kind") == "ask"}
|
|
158
|
+
splits: dict[str, dict[str, list]] = {s: {} for s in SPLITS}
|
|
159
|
+
pairs, skipped, disagree = [], 0, {}
|
|
160
|
+
run: dict[tuple, bool] = {} # (concept, day) -> the cold block is still running
|
|
161
|
+
seen: set[str] = set() # concepts with a graded item (or `also` credit) so far
|
|
162
|
+
for it in levels._items(events, problem_concepts):
|
|
163
|
+
ev = it.ev
|
|
164
|
+
if it.verdict is None or it.concept is None or ev.get("kind") == "ask":
|
|
165
|
+
continue
|
|
166
|
+
# cold as the fold rates a day (`levels._cold_block`): the first graded item with
|
|
167
|
+
# nothing on the concept earlier that day, and every one after it until a teaching
|
|
168
|
+
k = (it.concept, ev.get("day"))
|
|
169
|
+
cold = run[k] = run.get(k, not it.warm) and not it.primed
|
|
170
|
+
prior = "history" if it.concept in seen else "first review" # first: the 0.5 default
|
|
171
|
+
seen.add(it.concept)
|
|
172
|
+
if it.verdict == "correct":
|
|
173
|
+
seen.update(it.also)
|
|
174
|
+
if since and (ev.get("day") or "") < since:
|
|
175
|
+
continue
|
|
176
|
+
if mv := ev.get("model_verdict"):
|
|
177
|
+
pair_name = f"{mv} -> {it.verdict}"
|
|
178
|
+
disagree[pair_name] = disagree.get(pair_name, 0) + 1
|
|
179
|
+
p = ev.get("predicted_p")
|
|
180
|
+
if not _stamped(p):
|
|
181
|
+
skipped += 1
|
|
182
|
+
continue
|
|
183
|
+
pair = (float(p), int(it.verdict == "correct" and it.hints <= 1), levels._score(it))
|
|
184
|
+
pairs.append(pair)
|
|
185
|
+
for split, value in (("mode", _mode(ev.get("mode"))), ("grader", _grader(it, keys)),
|
|
186
|
+
("source", ev.get("source") or "none"),
|
|
187
|
+
("item_type", it.item_type or "recall"),
|
|
188
|
+
("confidence", "given" if it.confidence is not None else "none"),
|
|
189
|
+
("first", "cold" if cold else "later same day"),
|
|
190
|
+
("prior", prior)):
|
|
191
|
+
splits[split].setdefault(value, []).append(pair)
|
|
192
|
+
return {**_headline(pairs), "skipped_no_p": skipped, "since": since,
|
|
193
|
+
"bins": reliability(pairs),
|
|
194
|
+
"splits": {s: {k: _headline(v) for k, v in sorted(rows.items())}
|
|
195
|
+
for s, rows in splits.items()},
|
|
196
|
+
"model_verdict": {"n": sum(disagree.values()), "by": dict(sorted(disagree.items()))},
|
|
197
|
+
"spot_check": agreement(events)}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def confidence_mirror(events: Iterable[dict], problem_concepts: dict | None = None,
|
|
201
|
+
hide: set[str] = frozenset()) -> list[dict]:
|
|
202
|
+
"""Council item 6, display-only (never scheduling): per confidence 1-4 the graded primary
|
|
203
|
+
answers that carried it, as [{confidence, label, n, right, share}]; right = the fold's pass
|
|
204
|
+
rule (correct at hints <= 1; partial is not right). `share` is None below MIN_BAND answers.
|
|
205
|
+
Concepts in `hide` (planner.hidden) are left out."""
|
|
206
|
+
rows = {c: [0, 0] for c in CONFIDENCE_LABELS}
|
|
207
|
+
for it in levels._items(events, problem_concepts):
|
|
208
|
+
if (it.verdict is None or it.ev.get("kind") == "ask" or it.concept in hide
|
|
209
|
+
or isinstance(it.confidence, bool) or it.confidence not in rows):
|
|
210
|
+
continue
|
|
211
|
+
rows[it.confidence][0] += 1
|
|
212
|
+
rows[it.confidence][1] += it.verdict == "correct" and it.hints <= 1
|
|
213
|
+
return [{"confidence": c, "label": CONFIDENCE_LABELS[c], "n": n, "right": right,
|
|
214
|
+
"share": round(right / n, 4) if n >= MIN_BAND else None}
|
|
215
|
+
for c, (n, right) in rows.items()]
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def mirror_lines(rows: list[dict]) -> list[str]:
|
|
219
|
+
"""The mirror as plain lines; [] when no answer carried a confidence."""
|
|
220
|
+
if not any(r["n"] for r in rows):
|
|
221
|
+
return []
|
|
222
|
+
return [f"When you said {r['label']}, you were right {r['right']} of {r['n']} times"
|
|
223
|
+
if r["share"] is not None else
|
|
224
|
+
f"When you said {r['label']}: not enough answers yet ({r['n']})" for r in rows]
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _row(name: str, h: dict) -> str:
|
|
228
|
+
if not h.get("n"):
|
|
229
|
+
return f"{name:<14} {0:>5}"
|
|
230
|
+
skill = "-" if h["skill"] is None else f"{h['skill']:+.3f}"
|
|
231
|
+
return (f"{name:<14} {h['n']:>5} {h['base_rate']:>6.3f} {h['brier']:>6.3f} "
|
|
232
|
+
f"{h['brier_base']:>6.3f} {skill:>7} {h['log_loss']:>7.3f} {h['gap']:>6.3f} "
|
|
233
|
+
f"{h['brier_partial']:>7.3f}" + (" (too few)" if h["few"] else ""))
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def text(r: dict) -> str:
|
|
237
|
+
"""The report as a compact plain-text table."""
|
|
238
|
+
out = [f"learning calibration{' since ' + r['since'] if r['since'] else ''}: "
|
|
239
|
+
f"{r['n']} graded item(s) paired with predicted_p, "
|
|
240
|
+
f"{r['skipped_no_p']} skipped (no predicted_p)",
|
|
241
|
+
"pass = correct at hints <= 1; skill = 1 - Brier/base Brier; gap = binned |forecast"
|
|
242
|
+
" - pass|; Bpart = Brier with partial = 0.5",
|
|
243
|
+
f"{'':<14} {'n':>5} {'pass':>6} {'Brier':>6} {'base':>6} {'skill':>7} "
|
|
244
|
+
f"{'logloss':>7} {'gap':>6} {'Bpart':>7}",
|
|
245
|
+
_row("all", r)]
|
|
246
|
+
if (sc := r.get("spot_check") or {}).get("n"):
|
|
247
|
+
out.append(f"grader spot-check: user agreed with {sc['agree']} of {sc['n']} "
|
|
248
|
+
f"model verdict(s) ({sc['rate']:.0%})")
|
|
249
|
+
if not r["n"]:
|
|
250
|
+
return "\n".join(out)
|
|
251
|
+
out.append(_row("cold only", r["splits"]["first"].get("cold", {"n": 0})))
|
|
252
|
+
out += ["", "reliability forecast pass n"]
|
|
253
|
+
out += [f"{b['lo']:.1f}-{b['hi']:.1f} {b['p']:>6.3f} {b['pass']:>6.3f} {b['n']:>6}"
|
|
254
|
+
for b in r["bins"] if b["n"]]
|
|
255
|
+
for split, rows in r["splits"].items():
|
|
256
|
+
out += ["", f"by {split}"] + [_row(k, h) for k, h in rows.items()]
|
|
257
|
+
mv = r["model_verdict"]
|
|
258
|
+
out += ["", f"model_verdict disagreements (model -> final): {mv['n']}"
|
|
259
|
+
+ (" (" + ", ".join(f"{k}: {n}" for k, n in mv["by"].items()) + ")"
|
|
260
|
+
if mv["n"] else "")]
|
|
261
|
+
return "\n".join(out)
|