Skip to main content
일부 메트릭은 실험의 개별 실행이 아닌 전체 실험 수준에서만 정의할 수 있습니다. 예를 들어, 데이터셋의 모든 예제에 대해 평가 대상의 전체 통과율이나 f1 점수를 계산하고자 할 수 있습니다. 이러한 메트릭을 요약 평가자라고 합니다.

기본 예제

여기서는 정밀도와 재현율을 결합한 f1-score를 계산합니다. 이러한 종류의 메트릭은 실험의 모든 예제에 대해서만 계산할 수 있으므로, 평가자는 출력 목록과 참조 출력 목록을 입력으로 받습니다.
def f1_score_summary_evaluator(outputs: list[dict], reference_outputs: list[dict]) -> dict:
    true_positives = 0
    false_positives = 0
    false_negatives = 0

    for output_dict, reference_output_dict in zip(outputs, reference_outputs):
        output = output_dict["class"]
        reference_output = reference_output_dict["class"]

        if output == "Toxic" and reference_output == "Toxic":
            true_positives += 1
        elif output == "Toxic" and reference_output == "Not toxic":
            false_positives += 1
        elif output == "Not toxic" and reference_output == "Toxic":
            false_negatives += 1

    if true_positives == 0:
        return {"key": "f1_score", "score": 0.0}

    precision = true_positives / (true_positives + false_positives)
    recall = true_positives / (true_positives + false_negatives)
    f1_score = 2 * (precision * recall) / (precision + recall)

    return {"key": "f1_score", "score": f1_score}
그런 다음 이 평가자를 다음과 같이 evaluate 메서드에 전달할 수 있습니다:
from langsmith import Client

ls_client = Client()
dataset = ls_client.clone_public_dataset(
    "https://smith.langchain.com/public/3d6831e6-1680-4c88-94df-618c8e01fc55/d"
)

def bad_classifier(inputs: dict) -> dict:
    return {"class": "Not toxic"}

def correct(outputs: dict, reference_outputs: dict) -> bool:
    """Row-level correctness evaluator."""
    return outputs["class"] == reference_outputs["label"]

results = ls_client.evaluate(
    bad_classified,
    data=dataset,
    evaluators=[correct],
    summary_evaluators=[pass_50],
)
LangSmith UI에서 해당 키와 함께 표시된 요약 평가자의 점수를 확인할 수 있습니다. summary_eval.png

요약 평가자 인수

요약 평가자 함수는 특정 인수 이름을 가져야 합니다. 다음 인수 중 일부를 사용할 수 있습니다:
  • inputs: list[dict]: 데이터셋의 단일 예제에 해당하는 입력 목록입니다.
  • outputs: list[dict]: 주어진 입력에 대해 각 실험이 생성한 dict 출력 목록입니다.
  • reference_outputs/referenceOutputs: list[dict]: 사용 가능한 경우, 예제와 연결된 참조 출력 목록입니다.
  • runs: list[Run]: 주어진 예제에 대해 두 실험이 생성한 전체 Run 객체 목록입니다. 각 실행의 중간 단계나 메타데이터에 접근해야 하는 경우 사용하세요.
  • examples: list[Example]: 예제 입력, 출력(사용 가능한 경우), 메타데이터(사용 가능한 경우)를 포함한 모든 데이터셋 Example 객체입니다.

요약 평가자 출력

요약 평가자는 다음 타입 중 하나를 반환해야 합니다: Python 및 JS/TS
  • dict: {"score": ..., "name": ...} 형식의 dict를 사용하면 숫자 또는 불리언 점수와 메트릭 이름을 전달할 수 있습니다.
현재 Python만 지원
  • int | float | bool: 이는 평균, 정렬 등이 가능한 연속 메트릭으로 해석됩니다. 함수 이름이 메트릭의 이름으로 사용됩니다.

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I