Upload lhc_core.py with huggingface_hub
Browse files169 unmodified lines170171172173174175176285 unmodified lines462463464465466467468469470169 unmodified lines"""FACT_MAX = 25LOOP_MAX = 10 ** 6 # v3: pedagogical loop cap (was unbounded a/b iterations)POW_MAX_EXP = 512 # v3: DoS guard (9^99999999 used to freeze the app)POW_MAX_DIGITS = 4000 # v3: result-size guardSTEP_BUDGET = 200_000 # v3: global step budget285 unmodified linesthr = 0.5 if conf_threshold is None else conf_thresholdelse:conf = 0.5 * float(score) + 0.5 * float(gap)# v3: thr=0.25 measured on KB sample (n=50): correct min 0.606, nonsense# max 0.231 -> 100% accept-correct / 100% reject-nonsense at 0.25.thr = 0.25 if conf_threshold is None else conf_thresholdif conf < thr:return {"status": "uncertain", "confidence": conf, "top_score": score}speech = "".join(Articulator().speak(entry["response"]))169 unmodified lines170171172173174175176285 unmodified lines462463464465466467468469470471472473169 unmodified lines"""FACT_MAX = 25LOOP_MAX = 10 ** 4 # v3: pedagogical loop cap (kid-scale only; 10^6 made 1000000/3 hit the budget)POW_MAX_EXP = 512 # v3: DoS guard (9^99999999 used to freeze the app)POW_MAX_DIGITS = 4000 # v3: result-size guardSTEP_BUDGET = 200_000 # v3: global step budget285 unmodified linesthr = 0.5 if conf_threshold is None else conf_thresholdelse:conf = 0.5 * float(score) + 0.5 * float(gap)# v3.1: thr=0.45 — two independent samples (n=42 queries):# exact-KB min 0.709, paraphrase-in-KB min 0.439*, OOD max 0.386 (12# realistic OOD). At 0.45: in-KB 30/30 accepted, OOD 12/12 rejected.# Failure mode below thr = abstain ('لا أعرف'), never a silent guess.# (*paraphrases can dip below -> false abstain; use P1 calibrator to tune.)thr = 0.45 if conf_threshold is None else conf_thresholdif conf < thr:return {"status": "uncertain", "confidence": conf, "top_score": score}speech = "".join(Articulator().speak(entry["response"]))
lhc_core.py+7-4