"""Problem-row heuristics, shared by the dashboard and the final dataset build. Rows are flagged, never deleted. Thresholds were tuned by hand-reviewing the full run's candidates; the final values and hit counts are recorded in the dataset card. """ import re # --- thinking_leak: reasoning-channel / chat-template markup in the reply, or a non-empty # reasoning field from vLLM's gemma4 reasoning parser. THINKING_MARKERS = ("<|channel>", "", "<|think|>", "", "", "<|turn>", "") _THOUGHT_PREFIX = re.compile(r"^\s*thought\s*\n", re.I) # --- refusal: decline phrases in the first 300 chars. Disclaimers that precede a full # answer ("While I cannot provide a diagnosis, ...") are excluded. REFUSAL_PATTERNS = [ r"\bI(?:'m| am) (?:sorry|afraid),? but I (?:can(?:'|no)t|won't|am unable|'m unable|must decline)", r"(?= REPEAT_MIN_WORDS and repeated_ngram_ratio(text) > REPEAT_THRESHOLD, thinking_leak=bool(reasoning) or any(m in text for m in THINKING_MARKERS) or bool(_THOUGHT_PREFIX.match(text)), self_correction=bool(_SELF_CORRECTION.search(text)), ) FLAG_NAMES = ["truncated", "empty", "refusal", "repetitive", "thinking_leak", "self_correction"]