附录 B:评估指标速查
本章整理常用评估指标的定义、计算方法和适用场景。
文本生成指标
BLEU (Bilingual Evaluation Understudy)
用途:机器翻译、文本生成质量评估
公式:
其中:
- :n-gram精确率
- :短句惩罚因子
- :权重(通常均匀)
取值范围:0-1(越高越好)
适用:有参考答案的生成任务
from nltk.translate.bleu_score import sentence_bleu
reference = [['this', 'is', 'a', 'test']]
candidate = ['this', 'is', 'a', 'test']
score = sentence_bleu(reference, candidate)
ROUGE (Recall-Oriented Understudy for Gisting Evaluation)
用途:文本摘要评估
变体:
| 变体 | 说明 |
|---|---|
| ROUGE-N | N-gram召回率 |
| ROUGE-L | 最长公共子序列 |
| ROUGE-S | 跳元组 |
取值范围:0-1(越高越好)
from rouge import Rouge
rouge = Rouge()
scores = rouge.get_scores("this is a test", "this is test")
BERTScore
用途:语义相似度评估
原理:使用BERT embedding计算token级别的语义匹配
取值范围:0-1(越高越好)
from bert_score import score
P, R, F1 = score([candidate], [reference], lang="zh")
检索指标
Recall@K
用途:检索召回率
公式:
取值范围:0-1(越高越好)
MRR (Mean Reciprocal Rank)
用途:排序质量
公式:
取值范围:0-1(越高越好)
NDCG (Normalized Discounted Cumulative Gain)
用途:排序质量综合评估
公式:
取值范围:0-1(越高越好)
分类指标
Accuracy
用途:分类正确率
公式:
F1 Score
用途:精确率和召回率调和平均
公式:
Confusion Matrix
用途:分类错误分析
| Predicted Positive | Predicted Negative | |
|---|---|---|
| Actual Positive | TP | FN |
| Actual Negative | FP | TN |
LLM 特有指标
G-Eval
用途:使用GPT-4评估生成质量
维度:
- Relevance(相关性)
- Coherence(连贯性)
- Fluency(流畅性)
- Consistency(一致性)
取值范围:1-10(越高越好)
Faithfulness
用途:RAG答案忠实度
公式:
取值范围:0-1(越高越好)
Context Relevance
用途:检索内容相关性
公式:
取值范围:0-1(越高越好)
任务完成指标
Task Success Rate
用途:Agent任务完成率
公式:
Step Accuracy
用途:Agent步骤正确率
公式:
质量指标
Pass Rate
用途:通过率
公式:
Score Distribution
用途:分析得分分布
统计量:
- Mean(均值)
- Median(中位数)
- Std(标准差)
- P95/P99(百分位数)
指标选择指南
| 任务类型 | 推荐指标 |
|---|---|
| 文本生成 | BLEU + BERTScore + G-Eval |
| 翻译 | BLEU + COMET |
| 摘要 | ROUGE + BERTScore |
| QA | Exact Match + Semantic Sim + G-Eval |
| RAG检索 | Recall + MRR + NDCG |
| RAG生成 | Faithfulness + Context Relevance + Citation |
| Agent | Task Success Rate + Step Accuracy |
| 分类 | Accuracy + F1 + Confusion Matrix |
阈值参考
| 指标 | 建议阈值 | 说明 |
|---|---|---|
| Semantic Similarity | 0.75-0.85 | 根据任务严格程度调整 |
| G-Eval | 7/10 | 中等要求 |
| Faithfulness | 0.90 | RAG要求较高 |
| Task Success Rate | 0.80 | Agent任务 |
| Pass Rate | 0.85 | 综合质量 |