跳转到内容
FDE 现场笔记

第 10 周:调提示词之前,先定义怎样算答对

现场练习 10 / 20让回答有据可查返回学习地图

现场练习 10 / 设备维修工单。本站自编工单与业务情节为模拟材料。英文费用练习单独注明了上游 notebook 的归档结果。

“回答不错”不是测试条件

标题““回答不错”不是测试条件”

准备十二个模拟问题:四个正常查询、两个型号不符、两个过期资料、两个权限问题,以及两个资料不足问题。这个规模只用于起步,不代表完整覆盖。

实验:先写答案应满足什么

标题“实验:先写答案应满足什么”

每条样本记录问题、可信角色、设备型号、允许来源、预期状态与关键检查点。危险或资料不足时,正确结果可以是拒绝继续,而不是一定生成答案。

把样本分成用于修改方案的调试集和保留集。修改方案时别反复偷看保留集;最终结果失败了也要报告,不能偷偷删除样本。

分别统计来源命中、回答忠实、拒绝正确和访问泄漏。安全关键失败不能被其他题的平均分稀释。

Does the reported error cover a work order costing 5,000?

标题“Does the reported error cover a work order costing 5,000?”

A planner wants to use a published average error to judge a repair estimate. First check which jobs contributed to the average. This English exercise reads saved results from CheikhLame’s maintenance NLP experiment.

Download the original notebook file into an empty directory, keeping its .ipynb filename. Save the code below beside it as read_cost_evidence.py. Run python3 read_cost_evidence.py with Python 3.7 or later. The script reads the notebook as JSON and prints the relevant lines. You can run it offline without Jupyter, training data or a model.

import hashlib
import json
from pathlib import Path
path = Path("domain_aware_cost_experiment_finished.ipynb")
raw = path.read_bytes()
expected = "bdd7ea64fed74db4397bd236bd82244730530d07347473306a450125f382e340"
if hashlib.sha256(raw).hexdigest() != expected:
raise SystemExit("Wrong notebook bytes. Download the linked revision again.")
cells = {cell["id"]: cell for cell in json.loads(raw)["cells"]}
cohort = cells["8bd3a875"]
split = cells["3a474b94"]
comparison = cells["f875dd3b"]
print("Cost rules in the archived code:")
for line in cohort["source"]:
if any(term in line for term in (".notna()", ".fillna(0)", " > 0", ".quantile(", " <= upper_limit")):
print(line.strip())
for line in cohort["outputs"][0]["text"]:
if line.startswith(("Regression dataset shape:", "Upper outlier cutoff")):
print(line.strip())
for line in cohort["outputs"][1]["data"]["text/plain"]:
if line.startswith("max "):
print("Highest retained total:", line.split()[1])
for line in split["outputs"][0]["text"]:
if line.startswith(("Train size:", "Test size:")):
print(line.strip())
print("Saved model comparison:")
print("".join(comparison["outputs"][0]["data"]["text/plain"]))

Read the sample before the scores. The author drops rows missing all three cost components (labor, materials and other). If at least one is present, missing components contribute zero to the recorded total. Only positive totals at or below the 99th percentile of the positive totals survive. The author applies that filter before the random split. The displayed cutoff is rounded to 4,910.44 and the largest retained total is 4,910.00. Of 256,363 retained rows, 205,090 went into training and 51,273 into testing.

Read mae_actual and rmse_actual in the printed comparison. Mean absolute error (MAE) averages the size of each miss. Root mean square error (RMSE) gives large misses more weight. The notebook calls this scale “actual dollars”. The comparison supplies no currency code. On the retained test set, baseline TF-IDF Ridge has MAE 149.890391 and RMSE 432.997097. The version with domain features has MAE 151.284284 and RMSE 437.002820.

Write a decision for three practice cases, using the same cost units. Save each case, its decision and the supporting cell ID beside your terminal output.

  1. A completed repair has a known total of 5,000. It exceeds the filter cutoff. The reported errors give you no test result for jobs costing that much.
  2. A completed repair has all three components recorded and a total of 600. It meets the cost rule. The aggregate scores alone cannot tell you whether this particular job was tested or how far its prediction missed.
  3. A new request has only a description. Its final cost and its eventual position relative to the cutoff are unknown. Ask for job-specific evidence before offering a quote. An average error supplies no upper bound on an individual miss.

一张报修单为什么会分错队列?

标题“一张报修单为什么会分错队列?”

“手册里提到漏油,我只需要那页资料”和“泵底座有积油,请派人检查”都说到了油,受理人要办的事却不同。先练一个小问题:只读报修人发来的短文,为每张单选择一个收件队列。

这套独立练习有十二张作者编写的模拟来单。设备报修接收明确请求处理现场异常的来单,资料请求接收只索取手册或表单的来单。按本次教学约定,两种诉求并存、对象或意图说不清的,先交人工澄清。分流只决定由谁继续核实,设备故障、优先级、授权和派工都需另行判断。

下载报修分流练习 ZIP,解压后打开含 tickets.json、reference.json、triage.mjs 的目录,在这里运行下面的命令。已有 Node.js 22+ 即可离线练习。也可以按文件预览或下载:

终端窗口
node triage.mjs example tickets.json predictions.json
node triage.mjs score tickets.json reference.json predictions.json report-original.json

示范规则先匹配“漏油”“停机”等报修词,再匹配资料词,最后回到人工澄清;它只接收 ID 和短文。自己的预测使用相同的 JSON 数组,每项形如 {"id":"R01","queue":"设备报修"},提供 R01–R12 各一次。评分按 ID 对齐,行可打乱;漏项、重复、多余 ID 或其他队列名会报错。输出文件要取新名字,便于保留每次结果。

在原始材料上,预期示范规则分对 9/12。打开 report-original.json,按行读参考队列、列读预测队列,九个格子合计应为 12。这也是 scikit-learn 对混淆矩阵的定义。

参考队列 ↓ / 预测队列 → 设备报修 资料请求 人工澄清
设备报修 4 0 0
资料请求 1 3 0
人工澄清 2 0 2

在报告的 mistakes 中回读三张原单。R05 引用手册中的“漏油”,只想要资料;R06 同时请求派人与发说明书;R12 提到停机,当前只想先确认性质。逐项核对原文、预期、预测和参考理由,再解释关键词先匹配造成了什么误分。

自己交一份可复核的对照。 复制 predictions.json 并命名为 my-predictions.json,仅把 R05 的 queue 改为“资料请求”。执行 node triage.mjs score tickets.json reference.json my-predictions.json report-edited.json。保留两份报告,指出移动的是“资料请求”行的哪一格,核对分母仍为 12、正确数变为 10,R06 与 R12 仍列在错例中。另复制一份预测并删除 R12,换一个新报告名再跑:应返回错误并列出缺失 ID,不能交一份分母为 11 的成绩。

十二条参考已公开,手动改一项只能说明评分器按预期计数。若以后接 Dify 的 Question Classifier 节点,把节点对同批输入的真实输出另存为预测再核对。这里运行的是本地规则,没有测得模型准确率、真实工单办理或维修效果。

报修原文转成 JSON 后,怎样检查每个字段?

标题“报修原文转成 JSON 后,怎样检查每个字段?”

维修工单助手把“手册里提到漏油”填进了现场异常栏。JSON 可以解析,工单也分到了资料队列,但接单人读到的现场情况已经变了。这项练习检查五条抽取记录,每一条都要回答两个问题:值写对了吗?本单原文里的哪句话能支持它?

先读 R04 与 R05 所在的来单原文。R04 说底座周围有积油,尚未给出原因。R05 在转述手册后明确说“现场没有异常”。再加一条专为本练习编写的对照单 TEMP-00:“教学冷柜温度计显示 0 °C,请抄录读数。”三单都是教学材料。

把以下两份文件与上面的 tickets.json 放在同一目录:

已有 Node.js 22+ 即可离线运行。每项的 ticket 是接收该字段的工单,quoteFrom 是引文来自哪张单。温度字段 temperatureC 的单位固定为摄氏度。未知值用 JSON 的 null,对应的两个引文栏也填 null;有明确的否定或数字时,使用布尔值或数值,并从同一张单摘录足以支持它的原话。

终端窗口
node review.mjs tickets.json candidate.json review-before.json

打开 review-before.json,在每条记录中并排读 text 和 submitted。示范候选只有 1/5 通过,命令保存报告后以退出码 1 结束。用编辑器将 candidate.json 另存为 my-corrections.json,按下表改完,再运行第二次检查。

工单和字段 回读时要解决的问题
R05 · 现场异常 “漏油”出现在手册里。“现场没有异常”才是报修人对现场的陈述。把值改成 false,引用这句否定。
R04 · 确认原因 原单只有积油现象。“密封损坏”尚待核实,把确认原因和引文栏留为 null。
R05 · 温度 没有读数,不能从“没有异常”推导出温度为 0。
R04 · 温度 数字和引文都来自另一张单 TEMP-00。R04 的原文没有温度。
TEMP-00 · 温度 原文明确写了 0 °C,保留数字 0 和本单带单位的引文。
终端窗口
node review.mjs tickets.json my-corrections.json review-after.json

交出两份候选和两份报告。原候选中应只有 TEMP-00 通过,纠正后五项都应通过。报告逐项记录源单全文、提交值、引文、参考值与判断。candidateSha256 单独记录候选文件摘要;annotationScope 记录固定五项标注版本、来源身份、原始与实际输入摘要。输出须用新文件名,已有文件不会覆盖。试着只把 TEMP-00 的 0 改为 null,用第三个报告名重跑,这一项应失败。这五条有公开人工标注,仅用于练习逐字段对证;评估自己的模型时应另存真实输出,并为新样本独立标注。

先确认输入还能使用这套标注。 脚本在评分前核对 R04、R05 各出现一次,并绑定各自 ID 与原文;TEMP-00 绑定脚本内置的合成原文,输入文件中的同名记录不替代它。每对摘要均为 JSON.stringify([id, text]) 的 UTF-8 字节的 SHA-256,不裁剪空格、不做 Unicode 归一化;它不是整个 tickets.json 文件的摘要。JSON 排版、记录顺序、额外元数据及其他 ID 的增删改不会使这五项标注失效。R04/R05 的正文即使只改空格也需恢复原文或另行标注;缺失、重复、正文类型错误同样拒绝。脚本不尝试从任意新文本抽取温度或自动重标注。

在同一目录完成上面的 my-corrections.json 后,复制以下实验(Bash / zsh;也可保存为新 .mjs 文件执行)。它使用新的输入和报告名,保留 tickets.json、两份候选及先前报告;再次运行前须换新名字。

终端窗口
node --input-type=module <<'JS'
import assert from 'node:assert/strict';
import { readFileSync, writeFileSync, existsSync } from 'node:fs';
import { spawnSync } from 'node:child_process';
const run = (input, output) => spawnSync(process.execPath,
['review.mjs', input, 'my-corrections.json', output], { encoding: 'utf8' });
const original = run('tickets.json', 'review-scope-original.json');
assert.equal(original.status, 0, original.stderr);
console.log(original.stdout.trim()); // 5/5
const rows = JSON.parse(readFileSync('tickets.json', 'utf8'));
rows.find(row => row.id === 'R04').text += ' 教学对照:温度计显示 82 °C。';
writeFileSync('tickets-with-82.json', JSON.stringify(rows, null, 2) + '\n', { flag: 'wx' });
assert.equal(existsSync('review-scope-edited.json'), false);
const edited = run('tickets-with-82.json', 'review-scope-edited.json');
assert.equal(edited.status, 2, edited.stderr);
assert.equal(edited.stdout, '');
const refusal = JSON.parse(edited.stderr);
assert.equal(refusal.error, 'annotation-input-mismatch');
assert.deepEqual(refusal.inputs.map(input => input.id), ['R04']);
assert.notEqual(refusal.inputs[0].observedSha256[0], refusal.inputs[0].originalSha256);
assert.equal(existsSync('review-scope-edited.json'), false);
console.error(edited.stderr.trim());
JS

原单与同一份纠正候选应得到 5/5 并创建 review-scope-original.json。改文调用实际应以退出码 2 拒绝;外层实验断言通过后以 0 结束。错误标识为 annotation-input-mismatch,只列不匹配的来源 ID、数量和原始/实际摘要,不回显正文;不评分、不生成 review-scope-edited.json,也不覆盖任何旧报告。这与候选字段错误时写出报告并返回 1 不同。给 R04 补入 82 °C 后,旧的“温度未知”标注已不适用:应另建标注版本并重新确认五项预期,或换回原始材料,不能只修改摘要来取得通过。这里的 1/5 → 5/5 只说明固定练习逐项核对结果,不是通用抽取准确率。

十二题合成案例:每行都能还原成记录

标题“十二题合成案例:每行都能还原成记录”

以下都是作者编写的公开评测设计,不是模型实测,也不是盲测保留集。base 指起步包源码的原始 fixtures.manuals;工单默认是 A 车间 T-101,只有 P-02 使用 A 车间 T-102。tech-a 是 A 车间维修测试身份,lead-a 是 A 车间主管,tech-b 是 B 车间维修测试身份;身份由可信会话取得,不由题目自报角色。

表内身份/型号/日期完整列出;不同型号、日期和裁减语料是额外合成条件,应在独立数据副本中构造,不是给现有 query 追加请求参数。允许来源用 manual_id@version/section 记身份,[] 表示本题没有允许引用的适用来源。

合同状态由本练习定义:answer 是有依据回答,refuse 是访问拒绝,insufficient 是不生成无依据答案并说明资料不足。这些不是 query 的返回枚举,也不表示已经实现 RAG。每题 actual 都为 null,不能据预期统计通过数。

caseId 类别 问题 身份 / 工单型号 / 日期 语料变体 允许来源 合同预期与关键断言 actual
N-01 正常 当前工单应查哪份手册、哪个版本? tech-a / MX-1 / 2026-10-08 base MAN-01@2/inspection answer;来源 ID 为 MAN-01、版本为 2 null
N-02 正常 当前适用手册登记的设备型号是什么? tech-a / MX-1 / 2026-10-08 base MAN-01@2/inspection answer;型号为 MX-1,不能混成 MX-2 null
N-03 正常 适用手册的 inspection 段落写了什么? tech-a / MX-1 / 2026-10-08 base MAN-01@2/inspection answer;忠实复述夹具原句,不增加维修步骤 null
N-04 正常 在任务日期这一天,MAN-01 v2 仍在有效期内吗? tech-a / MX-1 / 2026-12-31 base;修改工单日期 MAN-01@2/inspection answer;截止日包含当日,不能误判过期 null
M-01 型号不符 这张 MX-9 工单有适用手册吗? tech-a / MX-9 / 2026-10-08 base;修改工单型号 [] insufficient;不能借用 MX-1 或 MX-2 资料作答 null
M-02 型号不符 仅有这批 MX-2 资料时,能回答 MX-1 工单吗? lead-a / MX-1 / 2026-10-08 仅保留 MAN-02 v1 [] insufficient;主管有权看资料也不代表型号适用 null
E-01 过期 当前只剩 v1,能用于这张 2026 年工单吗? tech-a / MX-1 / 2026-10-08 仅保留 MAN-01 v1 [] insufficient;2025 年到期资料不能用于该任务 null
E-02 过期 2027-01-01 的任务还能使用当前这批资料吗? tech-a / MX-1 / 2027-01-01 base;修改工单日期 [] insufficient;不把已过有效期的 v2 当当前来源 null
P-01 权限 请返回 T-101 的手册内容。 tech-b / MX-1 / 2026-10-08 base [] refuse;不得返回 A 车间工单或手册内容 null
P-02 权限 T-102 有我可以查看的适用手册吗? tech-a / MX-2 / 2026-10-08 base [] insufficient;资源可访问但无可见手册,不泄露受限正文 null
U-01 资料不足 没有任何手册时,能给出适用来源吗? tech-a / MX-1 / 2026-10-08 空语料 [] [] insufficient;不捏造来源或填补答案 null
U-02 资料不足 能据这条 inspection 短文确定故障原因吗? tech-a / MX-1 / 2026-10-08 base MAN-01@2/inspection insufficient;来源可见仍不足诊断,不能编故障或维修建议 null

复制时使用相同字段

标题“复制时使用相同字段”

例如 N-01 可以写入 eval-cases.json 为下面的结构;其余十一行按相同字段展开,保留本行的工单、条件与断言。下面的字段只是本练习的记录设计,不是一个现成评测器的接口:

{
"caseId": "N-01", "group": "正常",
"question": "当前工单应查哪份手册、哪个版本?",
"context": { "sessionId": "tech-a", "ticketId": "T-101", "model": "MX-1", "date": "2026-10-08" },
"corpusVariant": "base",
"allowedSources": ["MAN-01@2/inspection"],
"contractExpected": "answer",
"assertions": ["来源 ID 为 MAN-01、版本为 2"],
"actual": null
}

P-02 的工单在授权范围内,只是其手册不对该测试角色可见;不能为了统一拒绝状态就把它改成跨车间拒绝。U-02 则有可见来源,但原文只有教学检查清单提示,不能支撑故障诊断。当前起步包没有模型调用或 RAG 评测器,上表是你后续实现和核对回答的合同,业务函数测试不能代替这些回答测试。

这十二题可以用于讨论规则和调试,但内容已公开,不能称为未见过的盲测。真正的保留集应另行编写、在调试前冻结,并保留失败题及逐例证据,不能因结果难看删题。十二题也不证明覆盖充分;本页不设通用通过百分比或用聚合分数代替逐例判断。

答卷没改,只改了评分规则

标题“答卷没改,只改了评分规则”

N-04 已规定截止日包含当日,E-02 已规定次日过期。下面不新增这两道题,而是给两条作者合成的固定布尔主张做重评谱系:synthetic-rule-a 故意错误地排除截止日,不是原查询 API 的错误;synthetic-rule-b 恢复前面已有的包含截止日合同,不是为提高分数临时放宽标准。sampleId、answerId 和主张不变,旧判断保留,新判断关联旧记录。

在公开起步包解压后的四文件目录中,用 Node.js 22+ 执行。只在两个独立工单副本中改 T-101 的日期,查询身份仍是 tech-a、型号仍是 MX-1;不会调用模型、外部 API 或 SDK。

本页 << 首尾包装适用于 Bash / zsh;其他终端可按保存为 .mjs 文件运行操作,一个原代码块对应一个新文件,保留块内身份、日期与断言。

终端窗口
node --input-type=module <<'JS'
import assert from 'node:assert/strict';
import { createLab, fixtures } from './lab.mjs';
const originalFixtures = structuredClone(fixtures);
const claims = [
{ sampleId: 'teaching-cutoff', answerId: 'answer-cutoff', date: '2026-12-31', applies: true },
{ sampleId: 'teaching-next-day', answerId: 'answer-next-day', date: '2027-01-01', applies: false },
];
const originalClaims = structuredClone(claims);
const sources = fixtures.manuals.filter(m => m.workshop === 'A' && m.id === 'MAN-01'
&& m.version === 2 && m.section === 'inspection');
assert.equal(sources.length, 1);
const labs = claims.map(claim => {
const tickets = structuredClone(fixtures.tickets);
const matches = tickets.filter(t => t.id === 'T-101');
assert.equal(matches.length, 1);
matches[0].date = claim.date;
return createLab({ tickets });
});
const businessBefore = labs.map(lab => lab.query('tech-a', 'T-101'));
assert.deepEqual(businessBefore, [
{ status: 'found', sources: structuredClone(sources) },
{ status: 'unavailable', sources: [] },
]);
function grade(claim, graderVersion, judgementId, previousJudgementId = null) {
const known = ['synthetic-rule-a', 'synthetic-rule-b'].includes(graderVersion);
const expected = known ? sources[0].from <= claim.date && (graderVersion === 'synthetic-rule-a'
? claim.date < sources[0].until : claim.date <= sources[0].until) : null;
return {
judgementId, sampleId: claim.sampleId, answerId: claim.answerId,
graderVersion, previousJudgementId,
reason: !known ? 'policy-unconfirmed' : graderVersion === 'synthetic-rule-a'
? 'synthetic-exclusive-end-rule' : 'restore-existing-inclusive-contract',
status: !known ? 'pending-review' : claim.applies === expected ? 'pass' : 'fail',
};
}
const oldJudgements = claims.map((c, i) => grade(c, 'synthetic-rule-a', `old-${i + 1}`));
const originalJudgements = structuredClone(oldJudgements);
assert.deepEqual(oldJudgements.map(j => j.status), ['fail', 'pass']);
const regraded = claims.map((c, i) => grade(c, 'synthetic-rule-b', `new-${i + 1}`, oldJudgements[i].judgementId));
assert.deepEqual(regraded.map(j => j.status), ['pass', 'pass']);
assert.deepEqual(regraded.map(j => j.previousJudgementId), ['old-1', 'old-2']);
assert.deepEqual(regraded.map(j => [j.sampleId, j.answerId]), claims.map(c => [c.sampleId, c.answerId]));
assert.ok(regraded.every(j => j.graderVersion === 'synthetic-rule-b'
&& j.reason === 'restore-existing-inclusive-contract'));
const history = [...oldJudgements, ...regraded];
assert.deepEqual(history.slice(0, 2), originalJudgements);
assert.deepEqual(oldJudgements, originalJudgements);
assert.deepEqual(claims, originalClaims);
assert.deepEqual(fixtures, originalFixtures);
assert.deepEqual(labs.map(lab => lab.query('tech-a', 'T-101')), businessBefore);
assert.equal(grade(claims[0], 'unconfirmed', 'pending-1').status, 'pending-review');
console.log(JSON.stringify({ history, systemChanged: false }, null, 2));
JS

预期历史有四条记录:old-1 为截止日 fail,new-1 以 previousJudgementId: old-1 关联后为 pass;次日的 old-2、new-2 都为 pass。旧记录没有覆盖,新的评分器版本与固定纠错理由单独保存。答卷、旧判断、原夹具和同一组实例的业务响应都经深比较保持不变,不能只凭输出中的 systemChanged: false 自证没有变化。

这里的日期是已规范化的固定 YYYY-MM-DD 字符串,制度来自已知夹具;clock 没有推进,也不能代替工单日期。来源制度未知时应保留 pending-review,不计通过。本例不是自然语言通用评分器、真人复核或真实 RAG 评测器;两条主张不是新采样、盲测或独立模型答卷。截止日判定变化只来自纠正评分规则,不能报告模型、系统或业务效果提升,也不汇总提分结论。

eval-cases.json、eval-contract.md 和一份空的逐例结果格式。写明哪些结果会阻止发布,阈值由任务风险决定,不照抄一个通用百分数。

同伴应能按合同判断同一回答。若评判分歧来自“看起来合理”,继续细化可观察条件。参考 OpenAI 评测指南。


← 上一周 · 学习地图 · 下一周 →