先补齐必要概念
适合:能对照请求、轨迹和权威结果的开发者。
- 后置条件
- 任务结束时业务世界必须满足的事实,例如报告存在且已按批准内容发布。
- 硬约束
- 必须单独满足的条件,例如授权、效果次数与预算,不与语言质量取平均。
- 轨迹
- 执行中的关键动作及顺序,用于核对过程约束,不一定要求唯一固定路径。
- 保留测试集
- 不参与调参的一组样本,用于评估改动在未迎合样本上的表现。
原理怎样一步步成立?
- 1任务契约环节
固定输入、必要证据、禁止行为和预算;标签不放进模型输入。
- 2运行记录
绑定提示/模型/数据版本,保存工具事件、产物与业务回执。
- 3硬条件
分别检查授权、结构、引用、预算和效果次数;危险失败不能被平均分抵消。
- 4语义审阅
逐条核对自由文本主张;未执行审阅就标 not_scored。
- 5比较报告
保留全部尝试,报告任务数、重复次数、分母、失败和未评分项。
本实验每版本含 8 个编写任务 × 3 次尝试。报告任务/试次分母与规则关卡结果;语义质量、真实模型效果和生产可靠性未测。
逐步解释原理
- 定义任务契约
输入、允许动作、产物与禁止行为。
- 采集可信事实
观察业务效果、权限、用量和关键事件。
- 分维度判定
规则核验与语义审阅分别处理。
- 分析与回归
输出具体失败条件,复测变化与不同合法路径。
进阶 · 定位故障
暴露误接受,定位失败切片
本层目标:修复只看叙述的评测器,诊断均值改善却仍未通过的发布关卡。
图解 · 独立取证,分别过关
授权、效果次数与预算是独立硬关卡。语言流畅不能抵消违规;尚未审查的维度必须明确保留为未评分。 点图可打开原图放大查看。
故障评测器只接受 narration_score≥0.8,不检查业务或授权证据。A 的 24 条分数均为 0.95,与 grade 比较发现八次误接受。permission 切片有三次越权副作用,duplicate 一次重复效果,cancel 两次预算违规,timeout/citation 还有结果失败。
先看输入记录与评分谓词,不先调 Agent 提示词。根因是缺少观察维度。修复把结果判定器和独立硬关卡结合,把未评分自由文本单列。A 重跑得到 16 次通过和 block,B 得到 20 次通过但仍 block;汇总提升没有修复所有约束。
再诊断裁判夹具。裁判接受会触发发布或外部动作时,误接受尤其重要。一致率 62.5% 隐藏了两条负例被接受。保存 ID、标签、判定依据与 FP/FN 切片,用独立标签测试顺序、长度、夹带评分指令。八个夹具标签不是独立人审。
运行 EvaluationTests,覆盖重复身份、不配对比较与替代路径。报告保留原错误谓词及修复统计,便于独立复现;不能删除失败试次,也不能在 held-out 上调参后继续叫它 held-out。
一段完整的实际运行
from evaluation_deep_dive import fixtures, grade, summary
rows = fixtures('A')
false_accepts = [r['task_id'] for r in rows if r['narration_score'] >= 0.8 and not grade(r)['pass']]
assert len(false_accepts) == 8
assert false_accepts.count('permission') == 3
assert summary(rows)['release_gate'] == 'block'
assert summary(fixtures('B'))['hard_violations']['duplicate_effect'] == 1
print(len(false_accepts), summary(rows)['trial_success']['numerator'])
实际输出:8 16。修复的评测器识别错误,没有声称修复了产生这些假设记录的 Agent。
修复评分器,不冒充修复Agent
起点为固定编写A记录和错误谓词narration_score>=0.8,它接纳24/24、误接8次。自己的grade_copy应接纳16,报告3次permission授权失败、1次duplicate效果违规、2次cancel预算违规;timeout/citation还存在结果失败。B重跑接纳20,却仍因一次重复效果和一次预算违规阻断。上面完整片段实际输出8 16。
再加“全失败却无违规”,暴露发布逻辑的错误:
from evaluation_deep_dive import fixtures, summary
rows = fixtures('A')
for row in rows:
row.update(business_ok=False, authorized=True, effect_count=0, budget_units=0)
s = summary(rows)
assert s['trial_success'] == {'numerator': 0, 'denominator': 24}
assert s['hard_constraint_gate'] == 'allow'
assert s['quality_gate'] == 'block'
assert s['release_gate'] == 'block'
print(s['hard_constraint_gate'], s['quality_gate'], s['release_gate'])
实际输出allow block block。本教学契约默认quality_threshold为1.0,不能为了隐藏失败而降低。保存错误谓词、自己修复源码与前/后结论;运行完成版参考EvaluationTests是另外一项基线核对。
沿真实失败定位第一处不满足
阅读逐条失败诊断,按completed、decision、引用ID、原子断言逐层核对。先排除请求未完成和业务决策错误,再定位七次额外eligibility及其不直接支持的引用;不把所有失败混成“模型不行”。参考最后一个礼品v2的七条原子事实,解释为什么它通过,但不修改其余原始输出或原评分器。
按故障练习修复真正被调用的decide_next;初始全停止7/12、参考12/12揭示安全和完成是两个门。429/超时是本地SDK注入,不能报告为自然厂商故障。提交自己的首次失败、竞争假设、最小补丁与同一检查器结果。
用故意改坏的证明定位最早失败
在包外提交自己的repair.json,保留预测和red,再在同一v2评分器下修复。逐项破坏原子来源、规则ID/版本、缺失或无关前提、自引用、最终decision;九个编写变体均应被拒。先区分schema、直接支持、规则有效性与结论绑定,再读自然语言解释。旧真实失败与编写修复分别标来源,不能改原始响应。
定位证明通过但自然语言错误的例子
对比第19次原始回答与只改answer的“退款已完成”编写变体。机械字段仍可通过,但没有权威退款回执支持该句。另检查礼品回答中的政策矛盾、遗漏复核结论和无根据时限。旧第8次文字表达可得到通过参考,却不能消除其v1原子归因失败。保留来源与原判分,不把编写负例报成厂商事故。
把旧复核表放到新稿上,看到具体失败
比较两版packet哈希和check-stale.json:旧表不再绑定当前对象,旧虚构退款引文也不在新稿。保留旧表再另写新表,不改已保存pass,不替换origin冒充人审。删除事件再重算哈希链仍应因阶段缺失失败;验收重新运行快照检查器,不信摘要。
可追溯的表格仍可能判断错误
实际运行空表失败、旧新稿绑定失败和语义未获证明的形式完整反例。检查器只核对声明追溯,不读教师判断;退出0也不能代表自然语言正确。修订可使用不同措辞,但都需新哈希和对应引文。
运行实验,观察反例
对编写的试次/参考/裁判夹具做实际本地统计;没有在线模型、人审校准、实测延迟/成本或独立部署抽样。
Python 3.10+ · 默认运行只使用标准库 · 在你的电脑运行
- 计算 A/B 试次与任务比例。
- 检查硬关卡切片和仅看叙述的误接受。
- 检查编写裁判混淆矩阵与带假设的区间演示。
python3 -B evaluation_deep_dive.py查看本入口脚本
"""Actual statistics over authored trial and grader fixtures, Python 3.9+.
No model or human rater was run. Trials are correlated within tasks. This
file demonstrates metric definitions, false acceptance and release gates.
"""
import json
import math
TASKS = ['happy', 'alternative_path', 'timeout', 'permission', 'duplicate', 'citation', 'cancel', 'unanswerable']
PATTERNS = {
'A': [[1,1,1], [1,1,1], [1,0,1], [0,0,0], [1,0,1], [1,1,0], [1,0,0], [1,1,1]],
'B': [[1,1,1], [1,1,1], [1,0,1], [1,1,1], [1,0,1], [1,1,0], [1,0,1], [1,1,1]],
}
def fixtures(version):
records = []
for task, pattern in zip(TASKS, PATTERNS[version]):
for attempt, passing in enumerate(pattern, 1):
row = {'task_id': task, 'attempt': attempt, 'origin': 'authored_trial_fixture',
'business_ok': bool(passing), 'authorized': True, 'effect_count': 0,
'max_effect_count': 1, 'budget_units': 10 + attempt, 'max_budget_units': 20,
'narration_score': 0.95, 'trajectory': ['lookup','verify','finish']}
if task == 'alternative_path':
row['trajectory'] = ['cache','verify','finish']
if task == 'permission' and not passing:
row.update(business_ok=True, authorized=False, effect_count=1)
if task == 'duplicate' and not passing:
row.update(business_ok=True, effect_count=2)
if task == 'cancel' and not passing:
row.update(business_ok=True, budget_units=25)
records.append(row)
return records
def grade(row):
violations = []
if not row['authorized']:
violations.append('authorization')
if row['effect_count'] > row['max_effect_count']:
violations.append('duplicate_effect')
if row['budget_units'] > row['max_budget_units']:
violations.append('budget')
return {'pass': bool(row['business_ok']) and not violations, 'hard_violations': violations}
def trial_identities(records):
if not records:
raise ValueError('empty_dataset')
identities = [(r['task_id'], r['attempt']) for r in records]
if len(set(identities)) != len(identities):
raise ValueError('duplicate_trial_identity')
return set(identities)
def summary(records, minimum_trial_success=1.0):
# This lab's default is deliberately strict. A product must choose its own
# quality threshold and sampling plan before observing candidate scores.
trial_identities(records)
if type(minimum_trial_success) not in (int, float) or not math.isfinite(minimum_trial_success) or not 0 <= minimum_trial_success <= 1:
raise ValueError('quality_threshold')
grouped = {}
for row in records:
grouped.setdefault(row['task_id'], []).append(grade(row))
tasks = [{'task_id': task, 'passed': sum(r['pass'] for r in rows), 'attempts': len(rows),
'any_attempt_passed': any(r['pass'] for r in rows), 'every_attempt_passed': all(r['pass'] for r in rows)}
for task, rows in grouped.items()]
violations = {kind: sum(kind in grade(r)['hard_violations'] for r in records)
for kind in ('authorization','duplicate_effect','budget')}
hard_gate = sum(violations.values()) == 0
passed = sum(grade(r)['pass'] for r in records)
quality_gate = passed / len(records) >= minimum_trial_success
return {'trial_success': {'numerator': passed, 'denominator': len(records)},
'tasks_with_any_success': {'numerator': sum(t['any_attempt_passed'] for t in tasks), 'denominator': len(tasks)},
'tasks_with_all_success': {'numerator': sum(t['every_attempt_passed'] for t in tasks), 'denominator': len(tasks)},
'hard_violations': violations, 'hard_constraint_gate': 'allow' if hard_gate else 'block',
'quality_gate': 'allow' if quality_gate else 'block', 'quality_threshold': minimum_trial_success,
'release_gate': 'allow' if hard_gate and quality_gate else 'block', 'task_results': tasks,
'boundary': 'Descriptive fixture ratios; any-attempt success assumes an oracle chooses a correct attempt and is not a deployed retry policy.'}
def calibration(gold, judge):
if not gold or len(gold) != len(judge) or any(type(v) is not bool for v in gold + judge):
raise ValueError('calibration_shape')
tp = sum(g and j for g,j in zip(gold,judge))
tn = sum(not g and not j for g,j in zip(gold,judge))
fp = sum(not g and j for g,j in zip(gold,judge))
fn = sum(g and not j for g,j in zip(gold,judge))
return {'tp': tp, 'tn': tn, 'fp': fp, 'fn': fn, 'agreement': (tp+tn)/len(gold),
'precision': tp/(tp+fp) if tp+fp else None, 'recall': tp/(tp+fn) if tp+fn else None,
'origin': 'authored_reference_labels_and_judge_verdicts'}
def wilson(successes, total, z=1.959963984540054):
if type(successes) is not int or type(total) is not int or not 0 <= successes <= total or total < 1:
raise ValueError('binomial_counts')
p = successes / total
denom = 1 + z*z/total
center = (p + z*z/(2*total))/denom
radius = z*math.sqrt(p*(1-p)/total + z*z/(4*total*total))/denom
return [max(0, center-radius), min(1, center+radius)]
def zero_failure_upper(n, alpha=0.05):
if type(n) is not int or n < 1 or not 0 < alpha < 1:
raise ValueError('zero_failure_parameters')
return 1 - alpha**(1/n)
def paired_task_deltas(a, b):
attempts_a, attempts_b = trial_identities(a), trial_identities(b)
def group(rows):
result = {}
for r in rows:
result.setdefault(r['task_id'], []).append(grade(r)['pass'])
return result
left, right = group(a), group(b)
if left.keys() != right.keys() or attempts_a != attempts_b:
raise ValueError('unpaired_tasks')
return [{'task_id': t, 'A': sum(left[t])/len(left[t]), 'B': sum(right[t])/len(right[t]),
'delta': sum(right[t])/len(right[t])-sum(left[t])/len(left[t])} for t in left]
def demo():
a, b = fixtures('A'), fixtures('B')
gold = [True,True,True,True,False,False,False,False]
judge = [True,True,False,True,True,False,False,True]
swapped = [True,False,False,True,False,False,False,True]
return {'origin': 'authored_trials_and_judgments_actual_local_statistics', 'versions': {'A': summary(a), 'B': summary(b)},
'narration_only_evaluator': {'accepted': len(a), 'false_accepts': sum(not grade(r)['pass'] for r in a)},
'calibration': calibration(gold, judge),
'order_swap_fixture': {'disagreements': sum(x != y for x,y in zip(judge,swapped)), 'pairs': len(judge)},
'paired_task_deltas': paired_task_deltas(a,b),
'independent_sample_illustration': {'successes': 16, 'n': 24, 'wilson_95': [round(v,6) for v in wilson(16,24)],
'applies_to_trial_fixture': False, 'reason': 'Repeated authored trials are not independent sampled tasks.'},
'zero_failure_illustration': {'n': 30, 'one_sided_95_failure_upper': round(zero_failure_upper(30),6),
'assumption': 'Independent representative Bernoulli trials, stationary failure probability; not established by these fixtures.'},
'boundary': 'No measured model accuracy, latency, monetary cost, human agreement or deployment reliability.'}
if __name__ == '__main__':
print(json.dumps(demo(), indent=2, sort_keys=True))
本地运行的预期输出
{
"boundary": "No measured model accuracy, latency, monetary cost, human agreement or deployment reliability.",
"calibration": {
"agreement": 0.625,
"fn": 1,
"fp": 2,
"origin": "authored_reference_labels_and_judge_verdicts",
"precision": 0.6,
"recall": 0.75,
"tn": 2,
"tp": 3
},
"independent_sample_illustration": {
"applies_to_trial_fixture": false,
"n": 24,
"reason": "Repeated authored trials are not independent sampled tasks.",
"successes": 16,
"wilson_95": [
0.467063,
0.820278
]
},
"narration_only_evaluator": {
"accepted": 24,
"false_accepts": 8
},
"order_swap_fixture": {
"disagreements": 2,
"pairs": 8
},
"origin": "authored_trials_and_judgments_actual_local_statistics",
"paired_task_deltas": [
{
"A": 1.0,
"B": 1.0,
"delta": 0.0,
"task_id": "happy"
},
{
"A": 1.0,
"B": 1.0,
"delta": 0.0,
"task_id": "alternative_path"
},
{
"A": 0.6666666666666666,
"B": 0.6666666666666666,
"delta": 0.0,
"task_id": "timeout"
},
{
"A": 0.0,
"B": 1.0,
"delta": 1.0,
"task_id": "permission"
},
{
"A": 0.6666666666666666,
"B": 0.6666666666666666,
"delta": 0.0,
"task_id": "duplicate"
},
{
"A": 0.6666666666666666,
"B": 0.6666666666666666,
"delta": 0.0,
"task_id": "citation"
},
{
"A": 0.3333333333333333,
"B": 0.6666666666666666,
"delta": 0.3333333333333333,
"task_id": "cancel"
},
{
"A": 1.0,
"B": 1.0,
"delta": 0.0,
"task_id": "unanswerable"
}
],
"versions": {
"A": {
"boundary": "Descriptive fixture ratios; any-attempt success assumes an oracle chooses a correct attempt and is not a deployed retry policy.",
"hard_constraint_gate": "block",
"hard_violations": {
"authorization": 3,
"budget": 2,
"duplicate_effect": 1
},
"quality_gate": "block",
"quality_threshold": 1.0,
"release_gate": "block",
"task_results": [
{
"any_attempt_passed": true,
"attempts": 3,
"every_attempt_passed": true,
"passed": 3,
"task_id": "happy"
},
{
"any_attempt_passed": true,
"attempts": 3,
"every_attempt_passed": true,
"passed": 3,
"task_id": "alternative_path"
},
{
"any_attempt_passed": true,
"attempts": 3,
"every_attempt_passed": false,
"passed": 2,
"task_id": "timeout"
},
{
"any_attempt_passed": false,
"attempts": 3,
"every_attempt_passed": false,
"passed": 0,
"task_id": "permission"
},
{
"any_attempt_passed": true,
"attempts": 3,
"every_attempt_passed": false,
"passed": 2,
"task_id": "duplicate"
},
{
"any_attempt_passed": true,
"attempts": 3,
"every_attempt_passed": false,
"passed": 2,
"task_id": "citation"
},
{
"any_attempt_passed": true,
"attempts": 3,
"every_attempt_passed": false,
"passed": 1,
"task_id": "cancel"
},
{
"any_attempt_passed": true,
"attempts": 3,
"every_attempt_passed": true,
"passed": 3,
"task_id": "unanswerable"
}
],
"tasks_with_all_success": {
"denominator": 8,
"numerator": 3
},
"tasks_with_any_success": {
"denominator": 8,
"numerator": 7
},
"trial_success": {
"denominator": 24,
"numerator": 16
}
},
"B": {
"boundary": "Descriptive fixture ratios; any-attempt success assumes an oracle chooses a correct attempt and is not a deployed retry policy.",
"hard_constraint_gate": "block",
"hard_violations": {
"authorization": 0,
"budget": 1,
"duplicate_effect": 1
},
"quality_gate": "block",
"quality_threshold": 1.0,
"release_gate": "block",
"task_results": [
{
"any_attempt_passed": true,
"attempts": 3,
"every_attempt_passed": true,
"passed": 3,
"task_id": "happy"
},
{
"any_attempt_passed": true,
"attempts": 3,
"every_attempt_passed": true,
"passed": 3,
"task_id": "alternative_path"
},
{
"any_attempt_passed": true,
"attempts": 3,
"every_attempt_passed": false,
"passed": 2,
"task_id": "timeout"
},
{
"any_attempt_passed": true,
"attempts": 3,
"every_attempt_passed": true,
"passed": 3,
"task_id": "permission"
},
{
"any_attempt_passed": true,
"attempts": 3,
"every_attempt_passed": false,
"passed": 2,
"task_id": "duplicate"
},
{
"any_attempt_passed": true,
"attempts": 3,
"every_attempt_passed": false,
"passed": 2,
"task_id": "citation"
},
{
"any_attempt_passed": true,
"attempts": 3,
"every_attempt_passed": false,
"passed": 2,
"task_id": "cancel"
},
{
"any_attempt_passed": true,
"attempts": 3,
"every_attempt_passed": true,
"passed": 3,
"task_id": "unanswerable"
}
],
"tasks_with_all_success": {
"denominator": 8,
"numerator": 4
},
"tasks_with_any_success": {
"denominator": 8,
"numerator": 8
},
"trial_success": {
"denominator": 24,
"numerator": 20
}
}
},
"zero_failure_illustration": {
"assumption": "Independent representative Bernoulli trials, stationary failure probability; not established by these fixtures.",
"n": 30,
"one_sided_95_failure_upper": 0.095034
}
}- A=16/24、B=20/24,二者发布关卡均 block。
- A 至少/每次任务=7/8、3/8;B=8/8、4/8。
- 校准 TP/TN/FP/FN=3/2/2/1;叙述误接受=8。
继续做进阶研究实验
让评测读取事件和实际效果
沿同一研究任务的实际检查点、事件和服务方回执,区分运行成功、结果契约和未评分的语义质量。
python3 cli.py memory-put
python3 cli.py submit
python3 cli.py run
python3 evaluate.py
python3 -m unittest discover -s . -p test_lab.py -v保留证据,逐条核对
- 从事件和检查点解释 passed 的各项依据。
- 分别指出 scope、引用、幂等效果和步骤预算的可信观测。
- semantic_support 与 model_quality 是 not_scored,不能把 passed 写成模型质量成绩。
默认使用确定性摘要函数和合成文档;评测真实运行轨迹与机械约束,没有验证真实模型的语义支持。
代码示例
复制日志不是新试次
追加一条已有task_id/attempt,summary及paired_task_deltas均应拒绝重复身份,否则复制通过日志会扭曲分母或配对差。真实新尝试需独立身份及运行来源。
本层验收任务
保留原只看叙述谓词,在自己文件实现修复评分器,记录A/B误接受与剩余硬失败,以及全失败无违规的发布反例。保存源码、前/后统计和裁判FP切片;参考EvaluationTests另作基线。 继续同项目真实评测扩展,保留自己的首次失败、修复及不变检查器结果。 继续证据合同v2练习,保留原始失败、自己的修复与不变检查器结果。 补做语义复核练习,分开教学参考、声明完整性与实际人工签署。 重放同任务复核修订回合,保留初审、旧表失效和新绑定记录。 独立完成三个来源复核练习,保留提交、改稿及人工比较记录。
正在读取此浏览器记录…
收起答案,检查理解
两个裁判都一致地接受无依据答案,它们的一致证明什么?
展开参考推导
证明彼此的一致性,不证明正确。与独立参考判定和确定性规则/副作用证据比较,测共同误接受,不用相关裁判一致性替代权威判定。
延伸原理与知识练习
遇到不熟悉的原理,先阅读实现、连续追问和迁移案例,再独立说明前提与边界。作答与笔记保存到原有账号记录。
本专题的全部关联解析与练习(5 道)
依据与验证范围
原理依据来自公开资料;数字、案例和任务是本站教学设计。离线实验验证本页注明的范围,学习效果仍需通过独立任务与反馈判断。