得分者

评分器通过分析输出并生成结构化反馈来评估 GenAI 应用质量。 相同的记分器可用于开发中的评估,并可以重复用于在生产中监测。 评分者包括:

下面的 MLflow UI 屏幕截图演示了内置评分器和自定义评分器的Safetyexact_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
]

后续步骤