dspy.evaluate.SemanticF1

dspy.evaluate.SemanticF1

dspy.evaluate.SemanticF1(threshold=0.66, decompositional=False)

상위 클래스: Module

예측과 정답(ground truth) 사이의 **의미론적 F1(semantic F1)**을 LLM 기반 precision/recall로 계산하는 LLM-as-judge 메트릭이에요.

이름 타입 설명 기본값
threshold 최적화 중 수용할 최소 F1 점수 0.66
decompositional TrueDecompositionalSemanticRecallPrecision 사용 False

소스: dspy/evaluate/auto_evaluation.py

생성자는:

def __init__(self, threshold=0.66, decompositional=False):
    self.threshold = threshold

    if decompositional:
        self.module = ChainOfThought(DecompositionalSemanticRecallPrecision)
    else:
        self.module = ChainOfThought(SemanticRecallPrecision)

Module이라 검사·트레이스·최적화가 가능하고, batch·deepcopy·get_lm 등 일반 Module 메서드를 상속해요.

핵심: forward(example, pred, trace=None)

def forward(self, example, pred, trace=None):
    scores = self.module(question=example.question, ground_truth=example.response, system_response=pred.response)
    score = f1_score(scores.precision, scores.recall)

    return Prediction(score=score if trace is None else score >= self.threshold)

ChainOfThought 판정자에게 question·example.response(정답)·pred.response(시스템 답)를 주고 precision·recall을 얻은 뒤, 둘의 조화 평균으로 F1을 계산해요. 반환은 모드에 따라 달라져요trace is None(평가 시점)이면 연속 F1 점수를, trace is not None(최적화 시점)이면 score >= threshold의 이진화된 통과/실패를 돌려줘요. 같은 인스턴스가 두 모드를 모두 처리해요.

출처: 공식문서

더 알아보기 (Learn more)