精确匹配评估器的适用场景与比较规则

介绍精确匹配评估器用于校验逐字符一致的输出、分类标签和确定性结果,并说明其区分大小写与空白、按完整字符串比较、不做部分匹配的规则,适合低成本快速检查。

## 概览 那个... **exact_match** 评价员是一个简单的基于代码的评价员,负责检查产出是否完全等于预期值。它进行严格的字符串比较,而不是正常化。 该评价员只能作为内部人员使用。 **Python 键**关于TypeScript,请参见 [下面的用例](<https://arize.com/docs/phoenix/evaluation/pre-built-metrics/exact-match#usage-examples>) 显示如何使用该软件创建等效评价器 `createEvaluator`. ### 何时使用 需要时使用 exact_match 评价器 : - **核证准确产出** - 检查响应是否匹配预期值 character-for-character - **评估分类任务** - 校验与预期标签匹配的绝对输出 - **测试确定性产出** - 验证每次应相同的产出 - **快速疗养检查** - 没有LLM成本的快速评价 这是一个基于代码的评估者, 进行直接的字符串比较。 对于语义相似性或模糊的匹配, 请考虑使用基于 LLM 的评估者 。 ## 支持的级别 | 职等 | 获得支持 | 页:1 | | --- | --- | --- | | **宽度** | 对 | 对照预期值评价任何跨度输出 。 | ## 所需投入 exact_match评价员需要两项投入: | 外地 | 类型 | 说明 | | --- | --- | --- | | `output` | `string` | 评价的实际产出 | | `expected` | `string` | 匹配的预期值 | ### 重要说明 - **没有正常化**: 比较对大小写敏感和对白空间敏感 - **字符串比较**: 将两种输入都比作字符串 - **没有部分匹配**: 整个字符串必须完全匹配 ## 口译 评估员返回a `Score` 具有下列属性的对象: | 财产 | 数值 | 说明 | | --- | --- | --- | | `label` | `True` 或 时 间 `False` | 字符串是否匹配 | | `score` | `1.0` 或 时 间 `0.0` | 数字分数(1.0 = 匹配,0.0 = 无匹配). | | `kind` | `"code"` | 显示此为基于代码的评价器 | | `direction` | `"maximize"` | 分数较高比较好 | ## 用法实例 - Python 键 - TypeScript ``` from phoenix.evals.metrics import exact_match # Basic usage with matching field names eval_input = { "output": "Paris", "expected": "Paris" } scores = exact_match.evaluate(eval_input) print(scores[0]) # Score(name='exact_match', score=1.0, label=True, kind='code', ...) # Non-matching example eval_input = { "output": "paris", # lowercase "expected": "Paris" # uppercase } scores = exact_match.evaluate(eval_input) print(scores[0].score) # 0.0 (case-sensitive comparison) ``` exact_match 评价器不能作为 TypeScript 的内置设备。您可以使用 `createEvaluator`: ``` import { createEvaluator } from "@arizeai/phoenix-evals"; const exactMatchEvaluator = createEvaluator( (record: { output: string; expected: string }) => ({ score: record.output === record.expected ? 1 : 0, label: record.output === record.expected ? "match" : "no_match", }), { name: "exact_match", kind: "CODE" } ); const result = await exactMatchEvaluator.evaluate({ output: "Paris", expected: "Paris", }); console.log(result); // { score: 1, label: "match" } ``` ### 执行对大小写不敏感匹配 如果您需要不区分大小写匹配, 请首先将输入规范化 : ``` from phoenix.evals.metrics import exact_match eval_input = { "output": "PARIS".lower(), "expected": "paris" } scores = exact_match.evaluate(eval_input) print(scores[0].score) # 1.0 ``` 或建立符合常态的定制评价员: ``` from phoenix.evals.evaluators import Score, create_evaluator @create_evaluator(name="exact_match_normalized", kind="code") def exact_match_normalized(output: str, expected: str) -> Score: """Case-insensitive exact match with whitespace normalization.""" normalized_output = output.strip().lower() normalized_expected = expected.strip().lower() correct = normalized_output == normalized_expected return Score(score=float(correct)) ``` ## 与凤凰一起使用 ### 评估追踪 对凤凰城收集的痕迹进行评价,并将记录结果作为说明: - [评估凤凰网追踪](<https://arize.com/docs/phoenix/tracing/how-to-tracing/feedback-and-annotations/evaluating-phoenix-traces>) ### 运行中的实验 在凤凰城实验中使用exact_match评价器: - [在实验中使用评价员](<https://arize.com/docs/phoenix/datasets-and-experiments/how-to-experiments/using-evaluators>) ## API 参考文献 - **Python 键**: [exact_match](<https://arize-phoenix.readthedocs.io/projects/evals/api/evals.html#module-phoenix.evals.metrics>) ## 相关 - [匹配 Regex 评价器](<https://arize.com/docs/phoenix/evaluation/pre-built-metrics/matches-regex>) - 基于图案的匹配 这页有用吗? [建议编辑](<https://github.com/arize-ai/phoenix/edit/main/docs/phoenix/evaluation/pre-built-metrics/exact-match.mdx>)提出问题

查看原始来源