クラウド内のデータセットを評価する

スキーマを定義し、フィールドをエバリュエーターにマッピングし、クラウド評価実行を開始することで、JSONL または CSV データの事前計算済み応答を評価します。

前提条件

この例では、「SDK クライアントのセットアップ」で構成された SDK クライアントを使用します

入力データを準備する

ほとんどの評価シナリオでは、入力データが必要です。 データは、次の 2 つの方法で提供できます。

ヒント

人手で厳選したデータセットがない場合でも、そのようなデータセットを一から作り始められます。 事前起動中またはトラフィックが少ない場合は [合成評価データセットの生成 ] を使用するか、 エージェント トレースを評価データセットに変換 して実際の運用トラフィックからデータセットを作成します。

JSONL または CSV ファイルをアップロードして、Foundry プロジェクトにバージョン管理されたデータセットを作成します。 データセットでは、複数の評価実行でのバージョン管理と再利用がサポートされています。 このアプローチは、運用テストと CI/CD ワークフローに使用します。

エバリュエーターが必要とするフィールドを含む JSON オブジェクトを 1 行に 1 つ含む JSONL ファイルを準備します。

{"query": "What is machine learning?", "response": "Machine learning is a subset of AI.", "ground_truth": "Machine learning is a type of AI that learns from data."}
{"query": "Explain neural networks.", "response": "Neural networks are computing systems inspired by biological neural networks.", "ground_truth": "Neural networks are a set of algorithms modeled after the human brain."}

または、エバリュエーター フィールドに一致する列ヘッダーを含む CSV ファイルを準備します。

query,response,ground_truth
What is machine learning?,Machine learning is a subset of AI.,Machine learning is a type of AI that learns from data.
Explain neural networks.,Neural networks are computing systems inspired by biological neural networks.,Neural networks are a set of algorithms modeled after the human brain.
# Upload a local JSONL file. Skip this step if you already have a dataset registered.
data_id = project_client.datasets.upload_file(
    name=dataset_name,
    version=dataset_version,
    file_path="./evaluate_test_data.jsonl",
).id

データをインラインで提供する

小規模なテスト セットを使用した迅速な実験、またはエージェントの応答評価などのインライン データを必要とするシナリオでは、 file_contentを使用して評価要求に直接データを提供します。 エージェント応答の評価では、サポートされている唯一のソースの種類は file_content です。

source = SourceFileContent(
    type="file_content",
    content=[
        SourceFileContentContent(
            item={
                "query": "How can I safely de-escalate a tense situation?",
                "ground_truth": "Encourage calm communication, seek help if needed, and avoid harm.",
            }
        ),
        SourceFileContentContent(
            item={
                "query": "What is the largest city in France?",
                "ground_truth": "Paris",
            }
        ),
    ],
)

実行を作成する際に、source をデータ ソース構成の "source" フィールドとして渡してください。 次のシナリオセクションでは、既定で file_id を使用します。

シナリオ別のソースの種類対応

すべてのシナリオで両方のソースの種類がサポートされているわけではありません。 次のマトリックスは、各シナリオでサポートされるソースの種類を示しています。

Scenario file_id file_content
データセット (jsonl) はい はい
CSV (csv) はい はい
モデルまたはエージェントのターゲット はい はい
エージェントの応答 (azure_ai_responses) いいえ はい
トレース (azure_ai_traces) N/A N/A
合成データ (プレビュー) N/A N/A

JSONL データセットを評価する

jsonl データ ソース型を使用して、JSONL ファイル内の事前計算済み応答を評価します。 このシナリオは、モデルの出力が既にあり、その品質を評価する場合に便利です。

ヒント

開始する前に、 クライアントのセットアップ を完了し、 入力データを準備します

データ スキーマとエバリュエーターを定義する

JSONL フィールドに一致するスキーマを指定し、実行するエバリュエーター (テスト条件) を選択します。 data_mapping パラメーターを使用して、入力データのフィールドを、{{item.field}}構文を使用してエバリュエーター パラメーターに接続します。 各エバリュエーターに必要な入力フィールドを含む data_mapping を常に含めます。 フィールド名は、JSONL ファイル内のものと一致する必要があります。 たとえば、データに"question"ではなく"query"がある場合は、マッピングで"{{item.question}}"を使用します。 エバリュエーターごとに必要なパラメーターについては、 組み込みのエバリュエーターを参照してください。

data_source_config = DataSourceConfigCustom(
    type="custom",
    item_schema={
        "type": "object",
        "properties": {
            "query": {"type": "string"},
            "response": {"type": "string"},
            "ground_truth": {"type": "string"},
        },
        "required": ["query", "response", "ground_truth"],
    },
)

testing_criteria = [
    TestingCriterionAzureAIEvaluator(
        type="azure_ai_evaluator",
        name="coherence",
        evaluator_name="builtin.coherence",
        initialization_parameters={"model": model_deployment_name},
        data_mapping={
            "query": "{{item.query}}",
            "response": "{{item.response}}",
        },
    ),
    TestingCriterionAzureAIEvaluator(
        type="azure_ai_evaluator",
        name="violence",
        evaluator_name="builtin.violence",
        initialization_parameters={"model": model_deployment_name},
        data_mapping={
            "query": "{{item.query}}",
            "response": "{{item.response}}",
        },
    ),
    TestingCriterionAzureAIEvaluator(
        type="azure_ai_evaluator",
        name="f1",
        evaluator_name="builtin.f1_score",
        data_mapping={
            "response": "{{item.response}}",
            "ground_truth": "{{item.ground_truth}}",
        },
    ),
]

評価を作成して実行する

評価を作成し、アップロードしたデータセットに対して実行を開始します。 この実行では、データセット内のすべての行に対して各エバリュエーターが実行されます。

# Create the evaluation
eval_object = openai_client.evals.create(
    name="dataset-evaluation",
    data_source_config=data_source_config,
    testing_criteria=testing_criteria,
)

# Create a run using the uploaded dataset
eval_run = openai_client.evals.runs.create(
    eval_id=eval_object.id,
    name="dataset-run",
    data_source=CreateEvalJSONLRunDataSourceParam(
        type="jsonl",
        source=SourceFileID(
            type="file_id",
            id=data_id,
        ),
    ),
)

実行可能な完全な例については、GitHub のsample_evaluations_builtin_with_dataset_id.py を参照してください。 完了するまでポーリングして結果を解釈するには、「クラウド評価結果を取得する」を参照してください。

CSV データセットを評価する

csv データ ソースの種類を使用して、CSV ファイル内の事前計算済み応答を評価します。 このシナリオは データセットの評価 と同じように動作しますが、JSONL ではなく CSV ファイルを受け入れます。 データが既にスプレッドシートまたは表形式である場合は、CSV を使用します。

ヒント

開始する前に、 クライアントのセットアップ を完了し、 入力データを準備します

CSV ファイルを準備する

エバリュエーターが必要とするフィールドに一致する列ヘッダーを含む CSV ファイルを作成します。 各行は 1 つのテスト ケースを表します。

query,response,context,ground_truth
What is cloud computing?,Cloud computing delivers computing services over the internet.,Cloud computing is a technology for on-demand resource delivery.,Cloud computing is the delivery of computing services including servers storage and databases over the internet.
What is machine learning?,Machine learning is a subset of AI that learns from data.,Machine learning is a branch of artificial intelligence.,Machine learning is a type of AI that enables computers to learn from data without being explicitly programmed.
Explain neural networks.,Neural networks are computing systems inspired by biological neural networks.,Neural networks are used in deep learning.,Neural networks are a set of algorithms modeled after the human brain designed to recognize patterns.

アップロードして実行する

CSV ファイルをデータセットとしてアップロードします。 次に、 csv データ ソース型を使用して評価を作成します。 スキーマ定義とエバリュエーターの構成は、JSONL 評価の場合と同じです。 唯一の違いは、データ ソースの "type": "csv" です。

# Upload the CSV file
data_id = project_client.datasets.upload_file(
    name="eval-csv-data",
    version="1",
    file_path="./evaluation_data.csv",
).id

# Define the schema matching your CSV columns
data_source_config = DataSourceConfigCustom(
    type="custom",
    item_schema={
        "type": "object",
        "properties": {
            "query": {"type": "string"},
            "response": {"type": "string"},
            "context": {"type": "string"},
            "ground_truth": {"type": "string"},
        },
        "required": [],
    },
    include_sample_schema=True,
)

# Define evaluators with data mappings to CSV columns
testing_criteria = [
    TestingCriterionAzureAIEvaluator(
        type="azure_ai_evaluator",
        name="coherence",
        evaluator_name="builtin.coherence",
        data_mapping={
            "query": "{{item.query}}",
            "response": "{{item.response}}",
        },
        initialization_parameters={"model": model_deployment_name},
    ),
    TestingCriterionAzureAIEvaluator(
        type="azure_ai_evaluator",
        name="violence",
        evaluator_name="builtin.violence",
        data_mapping={
            "query": "{{item.query}}",
            "response": "{{item.response}}",
        },
        initialization_parameters={"model": model_deployment_name},
    ),
    TestingCriterionAzureAIEvaluator(
        type="azure_ai_evaluator",
        name="f1",
        evaluator_name="builtin.f1_score",
    ),
]

# Create the evaluation
eval_object = openai_client.evals.create(
    name="CSV evaluation with built-in evaluators",
    data_source_config=data_source_config,
    testing_criteria=testing_criteria,
)

# Create a run using the CSV data source type
eval_run = openai_client.evals.runs.create(
    eval_id=eval_object.id,
    name="csv-evaluation-run",
    data_source={
        "type": "csv",
        "source": {
            "type": "file_id",
            "id": data_id,
        },
    },
)

次のステップ