diff options
| author | Pinapelz <yukais@pinapelz.com> | 2026-04-26 21:38:13 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2026-04-26 21:38:13 -0700 |
| commit | f1c5df1541823c4177b9c2efd8de56eb3e309dd3 (patch) | |
| tree | adb8161d08d74c59ba24c776534a1144be355c98 | |
| parent | c545916ac1bba20112a98c3a75b3280b3042186e (diff) | |
fix: for hallucination calculation switch to n-gram approach
| -rw-r--r-- | server.py | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -203,8 +203,10 @@ def is_hallucination(text: str) -> bool: ngrams = [" ".join(clean[i : i + n]) for i in range(len(clean) - n + 1)] top, count = Counter(ngrams).most_common(1)[0] if count >= 3: - print(f"🔴 Hallucination (\'{top}\' x{count}): {text[:60]!r}") - return True + tokens_covered = count * n + if tokens_covered / max(1, len(clean)) > 0.35: + print(f"🔴 Hallucination (\'{top}\' x{count}, covers {tokens_covered}/{len(clean)} tokens): {text[:60]!r}") + return True top, count = Counter(clean).most_common(1)[0] if count >= 4 and count / len(clean) > 0.40: print(f"🔴 Hallucination (\'{top}\' x{count}, {count/len(clean):.0%}): {text[:60]!r}") |
