评分器通过分析输出并生成结构化反馈来评估 GenAI 应用质量。 相同的记分器可用于开发中的评估,并可以重复用于在生产中监测。 评分者包括:
下面的 MLflow UI 屏幕截图演示了内置评分器和自定义评分器的Safety
exact_match
输出:
下面的代码片段使用 mlflow.genai.evaluate()
计算这些指标,然后为生产监控注册相同的记分器。
import mlflow
from mlflow.genai.scorers import Safety, ScorerSamplingConfig, scorer
from typing import Any
@scorer
def exact_match(outputs: str, expectations: dict[str, Any]) -> bool:
# Example of a custom code-based scorer
return outputs == expectations["expected_response"]
# Evaluation during development
eval_results = mlflow.genai.evaluate(
data=eval_dataset,
predict_fn=my_app,
scorers=[Safety(), exact_match]
)
# Production monitoring - same scorers!
registered_scorers = [
Safety().register(),
exact_match.register(),
]
registered_scorers = [
reg_scorer.start(
sampling_config=ScorerSamplingConfig(sample_rate=0.1)
)
for reg_scorer in registered_scorers
]
后续步骤
- 使用内置的 LLM 评分器 - 快速使用内置的 LLM 作为判定工具来评估应用
- 创建自定义 LLM 评分器 - 为特定应用程序自定义 LLM 即判断评分器
- 创建自定义基于代码的评分器 - 生成基于代码的评分器,包括可能的输入、输出和错误处理
-
评估框架 - 了解
mlflow.genai.evaluate()
如何使用评分器 - GenAI 的生产监视 - 部署记分器进行持续监视