メインコンテンツまでスキップ

正しさの判断

Correctnessジャッジは、提供された真実の情報 ( expected_factsまたはexpected_response ) と比較して、GenAI アプリケーションの応答が事実上正しいかどうかを評価します。

この組み込み LLM ジャッジは、既知の正解に対してアプリケーションの応答を評価するために設計されています。

デフォルトでは、このジャッジは GenAI 品質評価を実行するために設計された Databricks ホスト LLM を使用します。ジャッジ定義内のmodel引数を使用して、ジャッジモデルを変更できます。モデルは<provider>:/<model-name>形式で指定する必要があります。ここで、 <provider>は LiteLLM 互換のモデル プロバイダーです。モデル プロバイダーとしてdatabricksを使用する場合、モデル名はサービス エンドポイント名と同じになります。

例を実行するための前提条件

  1. MLflow と必要なパッケージをインストールする

    Bash
    pip install --upgrade "mlflow[databricks]>=3.4.0"
  2. MLflow エクスペリメントを作成するには、環境のセットアップに関するクイックスタートに従ってください。

使用例

Python
from mlflow.genai.scorers import Correctness

correctness_judge = Correctness()

# Example 1: Response contains expected facts
feedback = correctness_judge(
inputs={"request": "What is MLflow?"},
outputs={"response": "MLflow is an open-source platform for managing the ML lifecycle."},
expectations={
"expected_facts": [
"MLflow is open-source",
"MLflow is a platform for ML lifecycle"
]
}
)

print(feedback.value) # "yes"
print(feedback.rationale) # Explanation of which facts are supported

# Example 2: Response missing or contradicting facts
feedback = correctness_judge(
inputs={"request": "When was MLflow released?"},
outputs={"response": "MLflow was released in 2017."},
expectations={"expected_facts": ["MLflow was released in June 2018"]}
)

# Example 3: Using expected_response instead of expected_facts
feedback = correctness_judge(
inputs={"request": "What is the capital of France?"},
outputs={"response": "The capital of France is Paris."},
expectations={"expected_response": "Paris is the capital of France."}
)

mlflow.evaluate() での使用

Correctnessジャッジは、MLflow の評価フレームワークで直接使用できます。

要件:

  • トレース要件 : inputsoutputs はトレースのルート スパン上にある必要があります
  • グラウンドトゥルースラベル :必須 - expectations辞書にexpected_factsまたはexpected_responseを提供する必要があります
Python
from mlflow.genai.scorers import Correctness

# Create evaluation dataset with ground truth
eval_dataset = [
{
"inputs": {"query": "What is the capital of France?"},
"outputs": {
"response": "Paris is the magnificent capital city of France, known for the Eiffel Tower and rich culture."
},
"expectations": {
"expected_facts": ["Paris is the capital of France."]
},
},
{
"inputs": {"query": "What are the main components of MLflow?"},
"outputs": {
"response": "MLflow has four main components: Tracking, Projects, Models, and Registry."
},
"expectations": {
"expected_facts": [
"MLflow has four main components",
"Components include Tracking",
"Components include Projects",
"Components include Models",
"Components include Registry"
]
},
},
{
"inputs": {"query": "When was MLflow released?"},
"outputs": {
"response": "MLflow was released in 2017 by Databricks."
},
"expectations": {
"expected_facts": ["MLflow was released in June 2018"]
},
}
]

# Run evaluation with Correctness scorer
eval_results = mlflow.genai.evaluate(
data=eval_dataset,
scorers=[
Correctness(
model="databricks:/databricks-gpt-oss-120b", # Optional. Defaults to custom Databricks model.
)
]
)

代替案: expected_response

expected_factsの代わりにexpected_responseを使用することもできます。

Python
eval_dataset_with_response = [
{
"inputs": {"query": "What is MLflow?"},
"outputs": {
"response": "MLflow is an open-source platform for managing the ML lifecycle."
},
"expectations": {
"expected_response": "MLflow is an open-source platform for managing the machine learning lifecycle, including experimentation, reproducibility, and deployment."
},
}
]

# Run evaluation with expected_response
eval_results = mlflow.genai.evaluate(
data=eval_dataset_with_response,
scorers=[Correctness()]
)
ヒント

expected_factsを使用すると、より柔軟な評価が可能になるため、expected_responseよりも推奨されます - 応答は単語ごとに一致させる必要はなく、重要な事実を含めるだけです。

カスタマイズ

異なるジャッジモデルを提供することでジャッジをカスタマイズできます。

Python
from mlflow.genai.scorers import Correctness

# Use a different judge model
correctness_judge = Correctness(
model="databricks:/databricks-gpt-5-mini" # Or any LiteLLM-compatible model
)

# Use in evaluation
eval_results = mlflow.genai.evaluate(
data=eval_dataset,
scorers=[correctness_judge]
)

結果の解釈

ジャッジは、次の Feedback オブジェクトを返します。

  • value :回答が正解の場合は「はい」、不正解の場合は「いいえ」
  • rationale :どの事実が支持されているか、または欠落しているかについての詳細な説明

次のステップ