評価の概念の概要
MLflow の 生成AI の評価概念 ( スコアラー、 ジャッジ、 評価データセット、およびそれらを使用するシステム)。
クイックリファレンス
概念 | 目的 | 使用量 |
---|---|---|
微量品質の評価 |
| |
LLMベースの評価 | 使用するためのスコアラーで包まれています | |
オフライン評価を実行する |
| |
Test データマネジメント |
| |
ストア評価結果 | 作成者:harness | |
ライブ品質の追跡 |
|
一般的なパターン
複数のスコアラーを一緒に使用する
Python
import mlflow
from mlflow.genai.scorers import scorer, Safety, RelevanceToQuery
from mlflow.entities import Feedback
# Combine predefined and custom scorers
@scorer
def custom_business_scorer(outputs):
response = outputs.get("response", "")
# Your business logic
if "company_name" not in response:
return Feedback(value=False, rationale="Missing company branding")
return Feedback(value=True, rationale="Meets business criteria")
# Use same scorers everywhere
scorers = [Safety(), RelevanceToQuery(), custom_business_scorer]
# Offline evaluation
results = mlflow.genai.evaluate(
data=eval_dataset,
predict_fn=my_app,
scorers=scorers
)
# Production monitoring - same scorers!
monitor = mlflow.genai.create_monitor(
endpoint="my-production-endpoint",
scorers=scorers,
sampling_rate=0.1
)
チェイニング評価結果
Python
import mlflow
import pandas as pd
from mlflow.genai.scorers import Safety, Correctness
# Run initial evaluation
results1 = mlflow.genai.evaluate(
data=test_dataset,
predict_fn=my_app,
scorers=[Safety(), Correctness()]
)
# Use results to create refined dataset
traces = mlflow.search_traces(run_id=results1.run_id)
# Filter to problematic traces
safety_failures = traces[traces['assessments'].apply(
lambda x: any(a.name == 'Safety' and a.value == 'no' for a in x)
)]
# Re-evaluate with different scorers or updated app
from mlflow.genai.scorers import Guidelines
results2 = mlflow.genai.evaluate(
data=safety_failures,
predict_fn=updated_app,
scorers=[
Safety(),
Guidelines(
name="content_policy",
guidelines="Response must follow our content policy"
)
]
)
評価でのエラー処理
Python
import mlflow
from mlflow.genai.scorers import scorer
from mlflow.entities import Feedback, AssessmentError
@scorer
def resilient_scorer(outputs, trace=None):
try:
response = outputs.get("response")
if not response:
return Feedback(
value=None,
error=AssessmentError(
error_code="MISSING_RESPONSE",
error_message="No response field in outputs"
)
)
# Your evaluation logic
return Feedback(value=True, rationale="Valid response")
except Exception as e:
# Let MLflow handle the error gracefully
raise
# Use in evaluation - continues even if some scorers fail
results = mlflow.genai.evaluate(
data=dataset,
predict_fn=my_app,
scorers=[resilient_scorer, Safety()]
)
概念
得点: mlflow.genai.scorers
Python
from mlflow.genai.scorers import scorer
from mlflow.entities import Feedback
from typing import Optional, Dict, Any, List
@scorer
def my_custom_scorer(
*, # MLflow calls your scorer with named arguments
inputs: Optional[Dict[Any, Any]], # App's input from trace
outputs: Optional[Dict[Any, Any]], # App's output from trace
expectations: Optional[Dict[str, Any]], # Ground truth (offline only)
trace: Optional[mlflow.entities.Trace] # Complete trace
) -> int | float | bool | str | Feedback | List[Feedback]:
# Your evaluation logic
return Feedback(value=True, rationale="Explanation")
裁判官: mlflow.genai.judges
スコアラーで包まれなければならないLLMベースの品質評価者。
Python
from mlflow.genai.judges import is_safe, is_relevant
from mlflow.genai.scorers import scorer
# Direct usage
feedback = is_safe(content="Hello world")
# Wrapped in scorer
@scorer
def safety_scorer(outputs):
return is_safe(content=outputs["response"])
評価ハーネス: mlflow.genai.evaluate(...)
開発中のオフライン評価を調整します。
Python
import mlflow
from mlflow.genai.scorers import Safety, RelevanceToQuery
results = mlflow.genai.evaluate(
data=eval_dataset, # Test data
predict_fn=my_app, # Your app
scorers=[Safety(), RelevanceToQuery()], # Quality metrics
model_id="models:/my-app/1" # Optional version tracking
)
評価データセット: mlflow.genai.datasets.EvaluationDataset
バージョン管理されたテストデータとオプションのグラウンドトゥルース。
Python
import mlflow.genai.datasets
# Create from production traces
dataset = mlflow.genai.datasets.create_dataset(
uc_table_name="catalog.schema.eval_data"
)
# Add traces
traces = mlflow.search_traces(filter_string="trace.status = 'OK'")
dataset.insert(traces)
# Use in evaluation
results = mlflow.genai.evaluate(data=dataset, ...)
評価の実行: mlflow.entities.Run
フィードバック付きのトレースを含む評価の結果。
Python
# Access evaluation results
traces = mlflow.search_traces(run_id=results.run_id)
# Filter by feedback
good_traces = traces[traces['assessments'].apply(
lambda x: all(a.value for a in x if a.name == 'Safety')
)]
本番運用 モニタリング: mlflow.genai.create_monitor(...)
デプロイされたアプリケーションの継続的な評価。
Python
import mlflow
from mlflow.genai.scorers import Safety, custom_scorer
monitor = mlflow.genai.create_monitor(
name="chatbot_monitor",
endpoint="endpoints:/my-chatbot-prod",
scorers=[Safety(), custom_scorer],
sampling_rate=0.1 # 10% of traffic
)
ワークフロー
Online モニタリング (本番運用)
Python
# Production app with tracing → Monitor applies scorers → Feedback on traces → Dashboards
オフライン評価(開発)
Python
# Test data → Evaluation harness runs app → Scorers evaluate traces → Results stored
次のステップ
これらの推奨アクションとチュートリアルで旅を続けてください。
- アプリを評価する - ハンズオン チュートリアルに従って、これらの概念を適用します
- Use predefined LLM scorers - Start with 組み込み quality メトリクス
- カスタムスコアラーの作成 - 特定のニーズに合わせてスコアラーを構築します
リファレンスガイド
関連する概念に関する詳細なドキュメントをご覧ください。