裁判官を人間に合わせる
審査員の調整では、体系的なフィードバックを通じて、LLM 審査員に人間の評価基準に合わせることを教えます。このプロセスにより、一般的な評価者が、お客様独自の品質基準を理解しているドメイン固有の専門家に変わり、基準となる審査員と比較して、人間による評価との一致率が 30 ~ 50 パーセント向上します。
審査員の調整は、次の 3 つのステップのワークフローに従います。
- 初期評価を生成する : 審査員を作成し、トレースを評価してベースラインを確立する
- 人間のフィードバックを収集する : ドメイン専門家が審査員の評価をレビューして修正する
- 調整と展開 : SIMBA オプティマイザーを使用して、人間のフィードバックに基づいて判定を改善します。
このシステムは、デフォルトの最適化戦略として Simplified Multi-Bootstrap Aggregation (SIMBA) を使用し、DSPy の実装を活用して判定指示を反復的に改良します。
要件
-
MLflow 3.4.0ジャッジアライメント機能を使用するには以上が必要です
Python%pip install --upgrade "mlflow[databricks]>=3.4.0"
dbutils.library.restartPython() -
make_judge()を使用して審査員を作成しました -
人間によるフィードバック評価の名前は、審査員の名前と完全に一致する必要があります。たとえば、審査員の名前が
product_qualityの場合、人間によるフィードバックにも同じ名前product_qualityを使用する必要があります。 -
アライメントは、テンプレートベースの評価で
make_judge()を使用して作成された審査員と連携して機能します。
ステップ 1: ジャッジを作成し、トレースを生成する
最初の審査員を作成し、評価を含むトレースを生成します。少なくとも 10 個のトレースが必要ですが、50 ~ 100 個のトレースでよりよいアライメント結果が得られます。
from mlflow.genai.judges import make_judge
import mlflow
# Create an MLflow experiment for alignment
experiment_id = mlflow.create_experiment("product-quality-alignment")
mlflow.set_experiment(experiment_id=experiment_id)
# Create initial judge with template-based evaluation
initial_judge = make_judge(
name="product_quality",
instructions=(
"Evaluate if the product description in {{ outputs }} "
"is accurate and helpful for the query in {{ inputs }}. "
"Rate as: excellent, good, fair, or poor"
),
model="databricks:/databricks-gpt-oss-120b",
)
トレースを生成し、ジャッジを実行します。
# Generate traces for alignment (minimum 10, recommended 50+)
traces = []
for i in range(50):
with mlflow.start_span(f"product_description_{i}") as span:
# Your application logic here
query = f"Tell me about product {i}"
description = generate_product_description(query) # Replace with your application logic
# Log inputs and outputs
span.set_inputs({"query": query})
span.set_outputs({"description": description})
traces.append(span.trace_id)
# Run initial judge on all traces
for trace_id in traces:
trace = mlflow.get_trace(trace_id)
inputs = trace.data.spans[0].inputs
outputs = trace.data.spans[0].outputs
# Generate judge assessment
judge_result = initial_judge(inputs=inputs, outputs=outputs)
# Log judge feedback to the trace
mlflow.log_feedback(
trace_id=trace_id,
name="product_quality",
value=judge_result.value,
rationale=judge_result.rationale,
)
ステップ 2: 人間のフィードバックを収集する
人間からのフィードバックを収集して、審査員に品質基準を伝えます。次のアプローチから選択してください。
- Databricks UI review
- Programmatic feedback
次の場合に人間からのフィードバックを収集します。
- 出力をレビューするにはドメイン専門家が必要です
- フィードバック基準を繰り返し改善したい
- より小さなデータセット(< 100 例)を扱っています
MLflow UI を使用して手動で確認し、フィードバックを提供します。
- DatabricksワークスペースのMLflowエクスペリメントに移動します
- 評価 タブをクリックしてトレースを表示します
- 各トレースとその審査員の評価を確認する
- UIのフィードバックインターフェースを使用して人間によるフィードバックを追加する
- フィードバック名が審査員名と完全に一致していることを確認してください(「product_quality」)。
次の場合にプログラムによるフィードバックを使用します。
- 既存のグラウンドトゥルースラベルがある
- 大規模なデータセット(100以上の例)を扱っている
- 再現可能なフィードバック収集が必要です
既存のグラウンドトゥルースラベルがある場合は、プログラムでログに記録します。
from mlflow.entities import AssessmentSource, AssessmentSourceType
# Your ground truth data
ground_truth_data = [
{"trace_id": traces[0], "label": "excellent", "rationale": "Comprehensive and accurate description"},
{"trace_id": traces[1], "label": "poor", "rationale": "Missing key product features"},
{"trace_id": traces[2], "label": "good", "rationale": "Accurate but could be more detailed"},
# ... more ground truth labels
]
# Log human feedback for each trace
for item in ground_truth_data:
mlflow.log_feedback(
trace_id=item["trace_id"],
name="product_quality", # Must match judge name
value=item["label"],
rationale=item.get("rationale", ""),
source=AssessmentSource(
source_type=AssessmentSourceType.HUMAN,
source_id="ground_truth_dataset"
),
)
フィードバック収集のベストプラクティス
- 多様なレビュー担当者 : 多様な視点を捉えるために複数の分野の専門家を含める
- バランスの取れた例 : 少なくとも 30% の否定的な例 (悪い/普通の評価) を含める
- 明確な根拠 : 評価の詳細な説明を提供する
- 代表的なサンプル : エッジケースと一般的なシナリオをカバー
ステップ 3: ジャッジを調整して登録する
十分な人間からのフィードバックが得られたら、審査員を調整します。
- Default optimizer (recommended)
- Explicit optimizer
MLflow は、DSPy の SIMBA (Simplified Multi-Bootstrap Aggregation) 実装を使用して、デフォルトのアライメント オプティマイザーを提供します。オプティマイザーを指定せずにalign()呼び出すと、SIMBA オプティマイザーが自動的に使用されます。
from mlflow.genai.judges.optimizers import SIMBAAlignmentOptimizer
# Retrieve traces with both judge and human assessments
traces_for_alignment = mlflow.search_traces(
experiment_ids=[experiment_id],
max_results=100,
return_type="list"
)
# Filter for traces with both judge and human feedback
# Only traces with both assessments can be used for alignment
valid_traces = []
for trace in traces_for_alignment:
feedbacks = trace.search_assessments(name="product_quality")
has_judge = any(f.source.source_type == "LLM_JUDGE" for f in feedbacks)
has_human = any(f.source.source_type == "HUMAN" for f in feedbacks)
if has_judge and has_human:
valid_traces.append(trace)
if len(valid_traces) >= 10:
# Create SIMBA optimizer with Databricks model
optimizer = SIMBAAlignmentOptimizer(
model="databricks:/databricks-gpt-oss-120b"
)
# Align the judge based on human feedback
aligned_judge = initial_judge.align(optimizer, valid_traces)
# Register the aligned judge for production use
aligned_judge.register(
experiment_id=experiment_id,
name="product_quality_aligned",
tags={"alignment_date": "2025-10-23", "num_traces": str(len(valid_traces))}
)
print(f"Successfully aligned judge using {len(valid_traces)} traces")
else:
print(f"Insufficient traces for alignment. Found {len(valid_traces)}, need at least 10")
from mlflow.genai.judges.optimizers import SIMBAAlignmentOptimizer
# Retrieve traces with both judge and human assessments
traces_for_alignment = mlflow.search_traces(
experiment_ids=[experiment_id], max_results=15, return_type="list"
)
# Align the judge using human corrections (minimum 10 traces recommended)
if len(traces_for_alignment) >= 10:
# Explicitly specify SIMBA with custom model configuration
optimizer = SIMBAAlignmentOptimizer(model="databricks:/databricks-gpt-oss-120b")
aligned_judge = initial_judge.align(optimizer, traces_for_alignment)
# Register the aligned judge
aligned_judge.register(experiment_id=experiment_id)
print("Judge aligned successfully with human feedback")
else:
print(f"Need at least 10 traces for alignment, have {len(traces_for_alignment)}")
詳細ログを有効にする
アライメント プロセスを監視するには、SIMBA オプティマイザーのデバッグ ログを有効にします。
import logging
# Enable detailed SIMBA logging
logging.getLogger("mlflow.genai.judges.optimizers.simba").setLevel(logging.DEBUG)
# Run alignment with verbose output
aligned_judge = initial_judge.align(optimizer, valid_traces)
アライメントを検証する
整合により判定が改善されたことを確認します。
def test_alignment_improvement(
original_judge, aligned_judge, test_traces: list
) -> dict:
"""Compare judge performance before and after alignment."""
original_correct = 0
aligned_correct = 0
for trace in test_traces:
# Get human ground truth from trace assessments
feedbacks = trace.search_assessments(type="feedback")
human_feedback = next(
(f for f in feedbacks if f.source.source_type == "HUMAN"), None
)
if not human_feedback:
continue
# Get judge evaluations
# Judges can evaluate entire traces instead of individual inputs/outputs
original_eval = original_judge(trace=trace)
aligned_eval = aligned_judge(trace=trace)
# Check agreement with human
if original_eval.value == human_feedback.value:
original_correct += 1
if aligned_eval.value == human_feedback.value:
aligned_correct += 1
total = len(test_traces)
return {
"original_accuracy": original_correct / total,
"aligned_accuracy": aligned_correct / total,
"improvement": (aligned_correct - original_correct) / total,
}
カスタムアライメントオプティマイザーを作成する
特殊なアライメント戦略の場合は、 AlignmentOptimizer基本クラスを拡張します。
from mlflow.genai.judges.base import AlignmentOptimizer, Judge
from mlflow.entities.trace import Trace
class MyCustomOptimizer(AlignmentOptimizer):
"""Custom optimizer implementation for judge alignment."""
def __init__(self, model: str = None, **kwargs):
"""Initialize your optimizer with custom parameters."""
self.model = model
# Add any custom initialization logic
def align(self, judge: Judge, traces: list[Trace]) -> Judge:
"""
Implement your alignment algorithm.
Args:
judge: The judge to be optimized
traces: List of traces containing human feedback
Returns:
A new Judge instance with improved alignment
"""
# Your custom alignment logic here
# 1. Extract feedback from traces
# 2. Analyze disagreements between judge and human
# 3. Generate improved instructions
# 4. Return new judge with better alignment
# Example: Return judge with modified instructions
from mlflow.genai.judges import make_judge
improved_instructions = self._optimize_instructions(judge.instructions, traces)
return make_judge(
name=judge.name,
instructions=improved_instructions,
model=judge.model,
)
def _optimize_instructions(self, instructions: str, traces: list[Trace]) -> str:
"""Your custom optimization logic."""
# Implement your optimization strategy
pass
# Create your custom optimizer
custom_optimizer = MyCustomOptimizer(model="your-model")
# Use it for alignment
aligned_judge = initial_judge.align(traces_with_feedback, custom_optimizer)
制限事項
- 審査員の配置は、エージェントベースまたは期待ベースの評価をサポートしていません。
次のステップ
- 本番運用モニタリングについて学び、調整された審査員を大規模に配置する
- 相補的決定論的メトリクスのコードベースのスコアラーを参照してください。