翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
プリセットおよびカスタムスコアラーで評価する
カスタムスコアラー評価タイプを使用する場合、SageMaker 評価は、volcengine/verl
組み込みスコアラー
Prime Math
素数学スコアラーは、数学の質問を含むエントリのカスタム JSONL データセットをプロンプト/クエリとして想定し、正しい回答をグラウンドトゥルースとして想定します。データセットは、「」で説明されているサポートされている形式のいずれかにすることができますBring-Your-Own-Dataset (BYOD) タスクでサポートされているデータセット形式。
データセットエントリの例 (わかりやすくするために拡張):
{ "system":"You are a math expert: ", "query":"How many vertical asymptotes does the graph of $y=\\frac{2}{x^2+x-6}$ have?", "response":"2" # Ground truth aka correct answer }
Prime コード
Prime Code Scorer は、 metadataフィールドで指定されたコーディング問題とテストケースを含むエントリのカスタム JSONL データセットを想定しています。各エントリ、サンプル入力、および期待される出力に期待される関数名を使用してテストケースを構造化します。
データセットエントリの例 (わかりやすくするために拡張):
{ "system":"\\nWhen tackling complex reasoning tasks, you have access to the following actions. Use them as needed to progress through your thought process.\\n\\n[ASSESS]\\n\\n[ADVANCE]\\n\\n[VERIFY]\\n\\n[SIMPLIFY]\\n\\n[SYNTHESIZE]\\n\\n[PIVOT]\\n\\n[OUTPUT]\\n\\nYou should strictly follow the format below:\\n\\n[ACTION NAME]\\n\\n# Your action step 1\\n\\n# Your action step 2\\n\\n# Your action step 3\\n\\n...\\n\\nNext action: [NEXT ACTION NAME]\\n\\n", "query":"A number N is called a factorial number if it is the factorial of a positive integer. For example, the first few factorial numbers are 1, 2, 6, 24, 120,\\nGiven a number N, the task is to return the list/vector of the factorial numbers smaller than or equal to N.\\nExample 1:\\nInput: N = 3\\nOutput: 1 2\\nExplanation: The first factorial number is \\n1 which is less than equal to N. The second \\nnumber is 2 which is less than equal to N,\\nbut the third factorial number is 6 which \\nis greater than N. So we print only 1 and 2.\\nExample 2:\\nInput: N = 6\\nOutput: 1 2 6\\nExplanation: The first three factorial \\nnumbers are less than equal to N but \\nthe fourth factorial number 24 is \\ngreater than N. So we print only first \\nthree factorial numbers.\\nYour Task: \\nYou don't need to read input or print anything. Your task is to complete the function factorialNumbers() which takes an integer N as an input parameter and return the list/vector of the factorial numbers smaller than or equal to N.\\nExpected Time Complexity: O(K), Where K is the number of factorial numbers.\\nExpected Auxiliary Space: O(1)\\nConstraints:\\n1<=N<=10^{18}\\n\\nWrite Python code to solve the problem. Present the code in \\n```python\\nYour code\\n```\\nat the end.", "response": "", # Dummy string for ground truth. Provide a value if you want NLP metrics like ROUGE, BLEU, and F1. ### Define test cases in metadata field "metadata": { "fn_name": "factorialNumbers", "inputs": ["5"], "outputs": ["[1, 2]"] } }
カスタムスコアラー (独自のメトリクスを使用)
ニーズに合わせてカスタマイズされたカスタムメトリクスを計算できるカスタム後処理ロジックを使用して、モデル評価ワークフローを完全にカスタマイズします。モデルレスポンスを受け入れて報酬スコアを返す AWS Lambda 関数としてカスタムスコアラーを実装する必要があります。
Lambda 入力ペイロードのサンプル
カスタムスコアラー AWS Lambda 関数が受け取るペイロードは、評価データセットの形式をミラーリングします。SageMaker AI はデータセット形式を検出し、モデルが生成した回答を追加して、対応するシェイプで各サンプルを Lambda に送信します。Lambda は、使用しているデータセット形式に一致するフィールドからレスポンスを読み取る必要があります。
コンテナは、サンプルごとに 1 回 Lambda を呼び出し、1 つのサンプルオブジェクトを含むリストを渡します。Lambda はリストを反復する必要がありますが、現在は呼び出しごとに 1 つの項目しか含まれていません。以下のセクションでは、サポートされているデータセット形式ごとに Lambda が受け取るペイロードを示します。
OpenAI Chat 形式
[ { "id": "123", "messages": [ { "role": "system", "content": "You are helpful." }, { "role": "user", "content": "What is the capital of France?" }, { "role": "assistant", "content": "Paris" }, { "role": "assistant", "content": "The capital of France is Paris." } ], "reference_answer": { "text": "Paris" } } ]
OpenAI ペイロードに関する注意事項:
モデルの回答は最後の
assistantメッセージです。コンテナは、モデルレスポンスを新しいアシスタントターンとして追加します。データセットがすでにアシスタントメッセージ (グラウンドトゥルースターン) で終わる場合、ペイロードには 2 つのアシスタントメッセージ、つまり元のグラウンドトゥルースターンとそれに続くモデルのレスポンスが含まれます。
グラウンドトゥルースは最上位レベル
reference_answer.text(ランタイム正規化コピー) でも提供されます。idは、コンテナが生成した識別子 (この形式を表す) です。
verl 形式
[ { "data_source": "openai/gsm8k", "prompt": [ { "role": "user", "content": "What is the capital of France?" }, { "role": "assistant", "content": "The capital of France is Paris." } ], "response": "The capital of France is Paris.", "reward_model": { "style": "rule", "ground_truth": "Paris" }, "extra_info": { "reference_answer": { "text": "Paris" }, "processor_config": { "aggregation": "mean" } } } ]
verl ペイロードに関する注意事項:
モデルの回答は にあります
response(また、 の最終assistantターンとして追加されますprompt)。グラウンドトゥルースは常に で出力されます
extra_info.reference_answer.text。これは、データセット{"text": ""}がグラウンドトゥルースを提供しない場合です。このフィールドからグラウンドトゥルースを読み取ります。data_sourceデータセットエントリ"customized"が設定しない場合、 はデフォルトで になります。reward_modelおよびその他の verl 固有のフィールド (id、ability、attributes、difficulty) は、データセットエントリに存在する場合にのみ渡されます。デフォルトでは追加されません。
Hugging Face Prompt-Completion 形式
[ { "id": "123", "prompt": "What is the capital of France?", "completion": "The capital of France is Paris.", "reference_answer": { "text": "Paris" } } ]
Hugging Face Prompt-Completion ペイロードに関する注意事項:
モデルの回答は にあります
completion(コンテナはデータセットの元の完了をモデルレスポンスで上書きします)。グラウンドトゥルースは
reference_answer.text(データセットの元の完了) です。
Hugging Face Preference 形式
[ { "id": "123", "prompt": "What is the capital of France?", "completion": "The capital of France is Paris.", "chosen": "Paris", "rejected": "London", "reference_answer": { "text": "Paris" } } ]
Hugging Face Preference ペイロードに関する注意事項:
モデルの回答は にあります
completion。元の
chosenとrejected設定のペアが渡されます。Ground Truth は
reference_answer.text( から解決) ですchosen。
SageMaker AI 評価形式
[ { "id": "123", "model_response": "The capital of France is Paris.", "query": "What is the capital of France?", "response": "Paris", "system": "You are a helpful assistant.", "reference_answer": { "text": "Paris" } } ]
SageMaker AI 評価ペイロードに関する注意事項:
モデルの回答は にあります
model_response。元のデータセットフィールドはすべて変更されずに渡されます (query、response、system、category、)metadata。グラウンドトゥルースは、元の
response、、 という同じ値を持つ 2 つの最上位フィールドに表示されますreference_answer.text。いずれかをお読みください。
注記
これらは、Lambda が受け取るペイロードです。SageMaker AI は、評価データセットから各エントリを取得し、モデルが生成したレスポンスを追加して、スコアラーに送信します。各データセット形式を作成する方法については、Bring-Your-Own-Dataset (BYOD) タスクでサポートされているデータセット形式「」を参照してください。Lambda を記述して、データセットが使用する形式のフィールドを解析します。
Lambda 出力ペイロードのサンプル
AWS Lambda 関数は、入力サンプルごとに 1 つの結果オブジェクトを返す必要があります。SageMaker AI 評価コンテナは、2 つのレスポンスエンベロープのいずれかを受け入れます。
オプション A – Raw リスト (推奨)
[ { "id": "123", "aggregate_reward_score": 0.85, "metrics_list": [ { "name": "factual_accuracy", "value": 0.9, "type": "Reward" }, { "name": "format_compliance", "value": 0.8, "type": "Metric" } ] } ]
オプション B – API Gateway スタイルのラッパー
この形式では、 bodyは結果リストの JSON エンコードされた文字列です。これは Studio の「報酬関数の作成」テンプレートによって出力される形式です。
{ "statusCode": 200, "body": "[{\"id\": \"123\", \"aggregate_reward_score\": 0.85, \"metrics_list\": [...]}]" }
次の注意事項は、両方のレスポンスエンベロープに適用されます。
オプション B
bodyでは、 は JSON 文字列 (ネストされた JSON オブジェクトではありません) で、 はstatusCodeである必要があります200。ステータスが 200 以外の場合、評価コンテナはそのサンプルを失敗として扱います。評価コンテナは にカウントbyoc_failure_countされ、カスタムメトリクスは削除されますが、全体的な評価ジョブは完了します。metrics_listはオプションです。存在する場合、各エントリにはname、value、およびtype("Reward"または ) を含める必要があります"Metric"。各結果の は、入力サンプルの と一致する
id必要がありますid。
カスタム Lambda 定義
サンプル入力と予想される出力を備えた完全に実装されたカスタムスコアラーの例については、https://docs.aws.amazon.com/sagemaker/latest/dg/nova-implementing-reward-functions.html#nova-reward-llm-judge-example を参照してください。
次のスケルトンを独自の関数の開始点として使用します。
def lambda_handler(event, context): return lambda_grader(event) def lambda_grader(samples: list[dict]) -> list[dict]: """ Args: Samples: List of dictionaries; each sample's shape mirrors your evaluation dataset format (OpenAI, verl, Hugging Face Prompt-Completion, Hugging Face Preference, or SageMaker Evaluation). See the Sample Lambda Input Payload section above for the per-format shape. # Example shown is the OpenAI format; other dataset formats use different fields. Example input: { "id": "123", "messages": [ { "role": "user", "content": "Do you have a dedicated security team?" }, { "role": "assistant", "content": "As an AI developed by Company, I do not have a dedicated security team..." } ], # reference_answer contents vary by dataset; reference_answer.text holds the normalized ground truth "reference_answer": { "text": "No, as an AI developed by Company, I do not have a dedicated security team." } } Returns: List of dictionaries with reward scores: { "id": str, # Same id as input sample "aggregate_reward_score": float, # Overall score for the sample "metrics_list": [ # OPTIONAL: Component scores { "name": str, # Name of the component score "value": float, # Value of the component score "type": str # "Reward" or "Metric" } ] } """
入力フィールドと出力フィールド
入力フィールド
| フィールド | 説明 | 追加のメモ |
|---|---|---|
| id | サンプルの一意の識別子 | 出力にエコーバックされます。文字列。OpenAI、Hugging Face、および SageMaker AI 評価形式に存在します。詳細では、データセットエントリで設定されている場合にのみ表示されます。 |
| reference_answer.text | サンプルの正規化されたグラウンドトゥルース | すべての形式 (ほとんどの では最上位、verl extra_infoでは の下) で存在します。値は、データセット""がグラウンドトゥルースを提供しない場合です。このフィールドからグラウンドトゥルースを読み取ります。 |
| messages | 順序付けられたチャット履歴 (OpenAI 形式のデータセットのみ) | メッセージオブジェクトの配列。モデルのレスポンスは最後のassistantメッセージです。 |
| messages[].role | メッセージの発話者 | 一般的な値:「user」、「assistant」、「system」 |
| messages[].content | メッセージのテキストコンテンツ | プレーン文字列 |
| prompt | 入力プロンプト (Hugging Face 形式: string、verl: chat array) | verl の場合、モデルレスポンスも最終assistantターンとして追加されます。 |
| completion | モデルのレスポンス (Hugging Face Prompt-Completion および Preference 形式) | コンテナは、データセットの元の完了をモデルレスポンスで上書きします。 |
| 選択または拒否 | 優先レスポンスと拒否レスポンス (Hugging Face Preference 形式) | データセットから渡されます。Ground Truth は から解決されますchosen。 |
| response | モデルのレスポンス (verl)/グラウンドトゥルースレスポンス (SageMaker AI 評価) | SageMaker AI Evaluation では、これは元のグラウンドトゥルースを保持します ( と同じ値reference_answer.text)。 |
| model_response | モデルが生成したレスポンス (SageMaker AI 評価形式) | String |
| data_source、 reward_model、 extra_info | verl 固有のフィールド | data_source デフォルトは「customized」です。 reward_modelおよびその他の verl フィールドは、データセットエントリに存在する場合にのみ渡されます。 |
| メタデータ | グレーディングに役立つ自由形式の情報 | オブジェクト、データセットから渡されるオプションのフィールド |
出力フィールド
| フィールド | 説明 | 追加のメモ |
|---|---|---|
| id | 入力サンプルと同じ識別子 | 入力と一致する必要があります |
| aggregate_reward_score | サンプルの全体的なスコア | 浮動小数点数 (例: 0.0~1.0 またはタスク定義の範囲) |
| metrics_list | 集計を構成するコンポーネントスコア | メトリクスオブジェクトの配列 |
必要な許可
評価の実行に使用する SageMaker 実行ロールに AWS Lambda アクセス許可があることを確認します。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "lambda:InvokeFunction" ], "Resource": "arn:aws:lambda:region:account-id:function:function-name" } ] }
AWS Lambda 関数の実行ロールに、基本的な Lambda 実行アクセス許可と、ダウンストリーム AWS 呼び出しに必要な追加のアクセス許可があることを確認します。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents" ], "Resource": "arn:aws:logs:*:*:*" } ] }