View a markdown version of this page

프리셋 및 사용자 지정 득점자를 사용하여 평가 - Amazon SageMaker AI

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

프리셋 및 사용자 지정 득점자를 사용하여 평가

사용자 지정 득점자 평가 유형을 사용하는 경우 SageMaker Evaluation은 volcengine/verl RL 훈련 라이브러리에서 가져온 두 개의 기본 제공 득점자('보상 함수'라고도 함) 프라임 수학 및 프라임 코드 또는 Lambda 함수로 구현된 사용자 지정 득점자를 지원합니다.

기본 제공 Scorer

프라임 수학

프라임 수학 득점자는 수학 질문을 프롬프트/쿼리로 포함하고 올바른 답변을 실측 정보로 포함하는 사용자 지정 JSONL 항목 데이터 세트를 기대합니다. 데이터 세트는에 언급된 지원되는 형식 중 하나일 수 있습니다BYOD(Bring-Your-Own-Dataset) 작업에 지원되는 데이터 세트 형식.

예제 데이터 세트 항목(명확성을 위해 확장됨):

{ "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 }

프라임 코드

프라임 코드 득점자는 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는 사용 중인 데이터 세트 형식과 일치하는 필드의 응답을 읽어야 합니다.

컨테이너는 샘플당 Lambda를 한 번 호출하여 단일 샘플 객체가 포함된 목록을 전달합니다. Lambda는 목록을 반복해야 하지만 현재 호출당 정확히 하나의 항목이 포함되어 있습니다. 다음 섹션에서는 지원되는 각 데이터 세트 형식에 대해 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 메시지입니다. 컨테이너는 모델 응답을 새 어시스턴트 턴으로 추가합니다.

  • 데이터 세트가 이미 어시스턴트 메시지(그라운드-트루스 턴)로 끝나는 경우 페이로드에는 두 개의 후행 어시스턴트 메시지, 즉 원래의 지면-트루스 턴과 모델의 응답이 포함됩니다.

  • 실측 정보도 최상위 수준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 및 기타 버전별 필드(id, ability, attributes, difficulty)는 데이터 세트 항목에 있는 경우에만 전달됩니다. 기본적으로 추가되지 않습니다.

Hugging Face 프롬프트-완료 형식

[ { "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.

  • 원본 chosenrejected 기본 설정 페어가 전달됩니다.

  • 실측 정보는에 있습니다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, categorymetadata)으로 전달됩니다.

  • 실측 정보는 원래 response, 및 값이 동일한 두 최상위 필드에 나타납니다reference_answer.text. 둘 중 하나를 읽습니다.

참고

다음은 Lambda가 수신하는 페이로드입니다. SageMaker AI는 평가 데이터 세트에서 각 항목을 가져와서 모델의 생성된 응답을 추가하고 이를 득점자에게 전송합니다. 각 데이터 세트 형식을 작성하는 BYOD(Bring-Your-Own-Dataset) 작업에 지원되는 데이터 세트 형식 방법은 섹션을 참조하세요. Lambda를 작성하여 데이터 세트가 사용하는 형식의 필드를 구문 분석합니다.

샘플 Lambda 출력 페이로드

AWS Lambda 함수는 입력 샘플당 하나의 결과 객체를 반환해야 합니다. SageMaker AI 평가 컨테이너는 두 개의 응답 봉투 중 하나를 허용합니다.

옵션 A - 원시 목록(권장)

[ { "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 valuetype ("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 평가 형식에 대해 제공되며, verl의 경우 데이터 세트 항목에 설정된 경우에만 나타납니다.
reference_answer.text 샘플에 대해 정규화된 실측 정보 모든 형식(대부분의 경우 최상위, verlextra_info의 경우 아래)으로 표시됩니다. 값은 데이터 세트가 실측 정보를 제공하지 않는 "" 경우입니다. 이 필드에서 실측 정보를 읽습니다.
messages 정렬된 채팅 기록(OpenAI 형식 데이터 세트만 해당) 메시지 객체 배열입니다. 모델의 응답은 마지막 assistant 메시지입니다.
messages[].role 메시지의 화자 일반적인 값: "user", "assistant", "system"
messages[].content 메시지의 텍스트 콘텐츠 일반 문자열
prompt 입력 프롬프트(Hugging Face 형식: 문자열, verl: 채팅 배열) verl의 경우 모델 응답도 최종 assistant턴으로 추가됩니다.
completion 모델의 응답(Hugging Face Prompt-Completion 및 Preference 형식) 컨테이너는 데이터 세트의 원래 완료를 모델 응답으로 덮어씁니다.
선택 또는 거부됨 기본 응답 및 거부된 응답(허깅 얼굴 기본 설정 형식) 데이터 세트에서 전달됩니다. 실측 정보는에서 확인됩니다chosen.
response 모델의 응답(verl) / 실측 응답(SageMaker AI 평가) SageMaker AI 평가에서는 원본 실측 정보(와 동일한 값)를 보유합니다reference_answer.text.
model_response 모델의 생성된 응답(SageMaker AI 평가 형식) 문자열
data_source, reward_model, extra_info verl 전용 필드 data_source는 기본적으로 "사용자 지정"으로 설정됩니다. reward_model 및 기타 언어 필드는 데이터 세트 항목에 있는 경우에만 전달됩니다.
metadata 등급 지정에 도움이 되는 자유 양식 정보 객체, 데이터 세트에서 전달되는 선택적 필드

출력 필드

출력 필드
필드 설명 추가 참고 사항
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:*:*:*" } ] }