Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

附录 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-NN-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 PositivePredicted Negative
Actual PositiveTPFN
Actual NegativeFPTN

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
QAExact Match + Semantic Sim + G-Eval
RAG检索Recall + MRR + NDCG
RAG生成Faithfulness + Context Relevance + Citation
AgentTask Success Rate + Step Accuracy
分类Accuracy + F1 + Confusion Matrix

阈值参考

指标建议阈值说明
Semantic Similarity0.75-0.85根据任务严格程度调整
G-Eval7/10中等要求
Faithfulness0.90RAG要求较高
Task Success Rate0.80Agent任务
Pass Rate0.85综合质量

阈值设置原则

  1. 从行业基准开始,根据业务需求调整
  2. 太高:过度优化,成本增加
  3. 太低:质量问题频发
  4. 分场景设置不同阈值