关于 llm-evaluation
这项技能介绍如何通过自动指标、人工评估和 LLM 裁判方法系统评估 LLM 应用,帮助团队比较模型与提示词、跟踪性能回退并排查异常行为。
主要功能
- 01文本生成与分类的自动指标
- 02检索评估指标
- 03人工质量评估维度
- 04逐项与成对 LLM 裁判
- 05基于参考与无参考评估
适用场景
- 01比较不同模型或提示词
- 02部署前检查性能回退
- 03评估 RAG 中的检索质量
- 04排查异常模型输出
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ wshobson/ agents --skill llm-evaluation安装后在 Claude Code 中输入/llm-evaluation确认已加载。
附带文件references/details.md
详细介绍
大模型评估
掌握面向大模型应用的全面评估策略,从自动化指标到人工评估和 A/B 测试。
何时使用本技能
- 系统性地衡量大模型应用性能
- 比较不同的模型或提示词
- 在部署前检测性能回退
- 验证提示词变更带来的改进
- 建立对生产系统的信心
- 建立基线并跟踪长期进展
- 调试意外的模型行为
核心评估类型
1. 自动化指标
使用计算得出的分数进行快速、可重复、可扩展的评估。
文本生成:
- BLEU:N-gram 重叠度(翻译)
- ROUGE:面向召回率(摘要)
- METEOR:语义相似度
- BERTScore:基于嵌入的相似度
- Perplexity:语言模型置信度
分类:
- Accuracy:正确率
- Precision/Recall/F1:类别特定性能
- Confusion Matrix:错误模式
- AUC-ROC:排序质量
检索(RAG):
- MRR:平均倒数排名
- NDCG:归一化折损累计增益
- Precision@K:前 K 个中的相关项
- Recall@K:前 K 个中的覆盖率
2. 人工评估
对难以自动化的质量方面进行人工评估。
维度:
- Accuracy:事实正确性
- Coherence:逻辑连贯性
- Relevance:是否回答了问题
- Fluency:自然语言质量
- Safety:无有害内容
- Helpfulness:对用户是否有用
3. 大模型作为评判者
使用更强的大模型来评估较弱模型的输出。
方法:
- Pointwise:对单个回答评分
- Pairwise:比较两个回答
- Reference-based:与黄金标准比较
- Reference-free:在没有标准答案的情况下评判
快速开始
from dataclasses import dataclass
from typing import Callable
import numpy as np
@dataclass
class Metric:
name: str
fn: Callable
@staticmethod
def accuracy():
return Metric("accuracy", calculate_accuracy)
@staticmethod
def bleu():
return Metric("bleu", calculate_bleu)
@staticmethod
def bertscore():
return Metric("bertscore", calculate_bertscore)
@staticmethod
def custom(name: str, fn: Callable):
return Metric(name, fn)
class EvaluationSuite:
def __init__(self, metrics: list[Metric]):
self.metrics = metrics
async def evaluate(self, model, test_cases: list[dict]) -> dict:
results = {m.name: [] for m in self.metrics}
for test in test_cases:
prediction = await model.predict(test["input"])
for metric in self.metrics:
score = metric.fn(
prediction=prediction,
reference=test.get("expected"),
context=test.get("context")
)
results[metric.name].append(score)
return {
"metrics": {k: np.mean(v) for k, v in results.items()},
"raw_scores": results
}
# Usage
suite = EvaluationSuite([
Metric.accuracy(),
Metric.bleu(),
Metric.bertscore(),
Metric.custom("groundedness", check_groundedness)
])
test_cases = [
{
"input": "What is the capital of France?",
"expected": "Paris",
"context": "France is a country in Europe. Paris is its capital."
},
]
results = await suite.evaluate(model=your_model, test_cases=test_cases)
详细模式与完整示例
详细的模式文档位于 references/details.md。当上述导航层级不够用时,请阅读该文件。
评论
支持 Markdown