Flag repeated-text answers as not grounded in chat
Browse files- app/renderer/knowledge.js +3 -0
- training/build_chat.py +3 -0
app/renderer/knowledge.js
CHANGED
|
@@ -115,6 +115,9 @@ export function chatMessages(question, passages, audit = 'none', history = []) {
|
|
| 115 |
const NUMBER = /(?<![\w.])\d+(?:\.\d+)?(?!\w)/g;
|
| 116 |
export function chatProblems(userPrompt, answer) {
|
| 117 |
const problems = [];
|
|
|
|
|
|
|
|
|
|
| 118 |
const passages = (userPrompt.split('MY AUDIT:')[0].match(/^\[\d+\] /gm) || []).length;
|
| 119 |
for (const m of answer.matchAll(/\[(\d+)\]/g)) if (+m[1] < 1 || +m[1] > passages) problems.push(`citation [${m[1]}] out of range`);
|
| 120 |
const allowed = new Set(userPrompt.match(NUMBER) || []);
|
|
|
|
| 115 |
const NUMBER = /(?<![\w.])\d+(?:\.\d+)?(?!\w)/g;
|
| 116 |
export function chatProblems(userPrompt, answer) {
|
| 117 |
const problems = [];
|
| 118 |
+
// Degenerate output from a broken engine ("QUITQUITQUIT…", "warmth warmth warmth…") has no numbers or citations to catch.
|
| 119 |
+
const words = answer.match(/\S+/g) || [];
|
| 120 |
+
if (/(.{2,30}?)\1{9,}/s.test(answer) || (words.length >= 30 && new Set(words).size / words.length < 0.2)) problems.push('repeated text');
|
| 121 |
const passages = (userPrompt.split('MY AUDIT:')[0].match(/^\[\d+\] /gm) || []).length;
|
| 122 |
for (const m of answer.matchAll(/\[(\d+)\]/g)) if (+m[1] < 1 || +m[1] > passages) problems.push(`citation [${m[1]}] out of range`);
|
| 123 |
const allowed = new Set(userPrompt.match(NUMBER) || []);
|
training/build_chat.py
CHANGED
|
@@ -236,6 +236,9 @@ def check_chat(example):
|
|
| 236 |
"""Grounding rules for chat answers (also used at runtime in the app)."""
|
| 237 |
prompt, answer = example["messages"][-2]["content"], example["messages"][-1]["content"]
|
| 238 |
problems = []
|
|
|
|
|
|
|
|
|
|
| 239 |
n_passages = len(re.findall(r"^\[\d+\] ", prompt.split("MY AUDIT:")[0], re.M))
|
| 240 |
for c in re.findall(r"\[(\d+)\]", answer):
|
| 241 |
if not 1 <= int(c) <= n_passages:
|
|
|
|
| 236 |
"""Grounding rules for chat answers (also used at runtime in the app)."""
|
| 237 |
prompt, answer = example["messages"][-2]["content"], example["messages"][-1]["content"]
|
| 238 |
problems = []
|
| 239 |
+
words = answer.split()
|
| 240 |
+
if re.search(r"(.{2,30}?)\1{9,}", answer, re.S) or (len(words) >= 30 and len(set(words)) / len(words) < 0.2):
|
| 241 |
+
problems.append("repeated text")
|
| 242 |
n_passages = len(re.findall(r"^\[\d+\] ", prompt.split("MY AUDIT:")[0], re.M))
|
| 243 |
for c in re.findall(r"\[(\d+)\]", answer):
|
| 244 |
if not 1 <= int(c) <= n_passages:
|