Files
University_Labs_Nego_Agent/eval/tests/test_rouge.py
T
민헌andClaude Opus 5.5 13ab9dee84 chore: 2차년도 성능평가 측정 구성 초기 업로드
data(train 520·holdout 120), server(발화 생성 서버), eval(grounding_eval), run_eval.py·run_test.sh.
logs/ 는 실행 때마다 생기는 기록이라 README.md 만 올리고 나머지는 .gitignore 로 뺀다.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 14:05:48 +09:00

44 lines
1.5 KiB
Python

import pytest
from grounding_eval.rouge import rouge_all, rouge_l, rouge_n
def test_rouge1_counts_clipped_overlap():
# 후보 a a b c / 정답 a b b d → 공통 a(min 2,1)=1, b(min 1,2)=1 → 2
score = rouge_n(["a", "a", "b", "c"], ["a", "b", "b", "d"], 1)
assert score.precision == pytest.approx(2 / 4)
assert score.recall == pytest.approx(2 / 4)
assert score.f1 == pytest.approx(0.5)
def test_rouge2_uses_bigrams():
# 후보 바이그램 (a,b)(b,c) / 정답 (a,b)(b,d)(d,c) → 공통 1
score = rouge_n(["a", "b", "c"], ["a", "b", "d", "c"], 2)
assert score.precision == pytest.approx(1 / 2)
assert score.recall == pytest.approx(1 / 3)
assert score.f1 == pytest.approx(2 * (1 / 2) * (1 / 3) / (1 / 2 + 1 / 3))
def test_rouge_l_uses_longest_common_subsequence():
# LCS(a b c d e, a c e x) = a c e → 3
score = rouge_l(["a", "b", "c", "d", "e"], ["a", "c", "e", "x"])
assert score.precision == pytest.approx(3 / 5)
assert score.recall == pytest.approx(3 / 4)
def test_identical_sequences_score_one():
tokens = ["연간", "400", "개", "거래"]
assert all(s.f1 == pytest.approx(1.0) for s in rouge_all(tokens, tokens).values())
@pytest.mark.parametrize("cand, ref", [([], ["a"]), (["a"], []), ([], []), (["a"], ["b"])])
def test_empty_or_disjoint_scores_zero(cand, ref):
assert all(s.f1 == 0.0 for s in rouge_all(cand, ref).values())
def test_bigram_on_single_token_is_zero():
assert rouge_n(["a"], ["a"], 2).f1 == 0.0