본문 바로가기
C.W.K.
Stream
Lesson 02 of 06 · published

BLEU와 ROUGE

~22 min · metrics, deterministic, translation, summarization

Level 0추측자
0 XP0/55 lessons0/10 achievements
0/150 XP to next level150 XP to go0% complete

오래됐지만 주의해서 쓰면 여전히 유용한 두 지표

BLEU와 ROUGE는 2000년대 초에 기계 번역과 요약을 평가하려고 만들어졌어. 불완전하고 비판도 자주 받지만, 처음 설계된 좁은 범위의 과제에서는 여전히 유용해. 참조 출력이 있고 빠르고 무료인 언어 독립적 유사도 점수가 필요할 때 사용할 수 있지.

BLEU — 번역용

BLEU (Bilingual Evaluation Understudy)는 후보 출력과 하나 이상의 참조 답안 사이에서 n-그램이 얼마나 겹치는지 측정하고, 지나치게 짧은 출력에는 길이 벌점을 적용해. 점수 범위는 0~1이며 일부 라이브러리에서는 0~100으로 표시해. 실제 번역 과제에서는 0.3이면 괜찮고, 0.5면 좋으며, 0.7 이상은 드물어.

ROUGE — 요약용

ROUGE (Recall-Oriented Understudy for Gisting Evaluation)는 요약을 평가하는 지표야. ROUGE-N은 n-그램 겹침을 측정하고, ROUGE-L은 최장 공통 부분 수열을 사용하며, ROUGE-W는 연속된 일치에 더 큰 가중치를 둬. 재현율이 높을수록 후보 출력이 참조 답안의 내용을 더 많이 담았다는 뜻이야.

원칙: BLEU와 ROUGE는 표면적인 단어 겹침을 측정할 뿐, 의미 자체를 측정하지는 않아. 참조 답안과 같은 단어를 쓴 출력에는 높은 점수를 주지만, 같은 의미를 다른 말로 표현하면 불이익을 줘.

쓰면 안 되는 곳

  • 개방형 생성(창작, 브레인스토밍) — 올바른 출력이 다양해서 하나의 참조 답안과 겹치는 부분이 적을 수 있어.
  • 코드 생성 — 기능이 같은 코드라도 사용한 어휘와 구조가 크게 다를 수 있어.
  • 대화 — 좋은 답변이 참조 답안과 같은 단어를 하나도 쓰지 않을 수 있어.
  • 표면적인 형태보다 의미가 더 중요한 모든 과제. 이런 경우에는 BERTScore나 LLM 판정 모델을 사용해.

Code

sacreBLEU — 표준 참조 구현·python
# pip install sacrebleu
from sacrebleu import corpus_bleu, sentence_bleu

refs   = [["The cat sat on the mat."]]
hyps   = ["The cat is on the mat."]
bleu = sentence_bleu(hyps[0], refs[0])
print(bleu.score)   # ~46 (out of 100)

# Corpus-level — better statistics, what papers report.
refs_corpus = [["The cat sat on the mat.", "It is raining."]]
hyps_corpus = ["The cat is on the mat.", "It rains today."]
corpus = corpus_bleu(hyps_corpus, refs_corpus)
print(corpus.score, corpus.brevity_penalty)
ROUGE — ROUGE-1, ROUGE-2, ROUGE-L·python
# pip install rouge-score
from rouge_score import rouge_scorer

scorer = rouge_scorer.RougeScorer(["rouge1", "rouge2", "rougeL"], use_stemmer=True)

reference = "The cat sat on the mat and watched the rain."
candidate = "A cat watched the rain from the mat."

result = scorer.score(reference, candidate)
for metric, score in result.items():
    print(f"{metric}: P={score.precision:.2f} R={score.recall:.2f} F1={score.fmeasure:.2f}")

# Output:
# rouge1: P=0.62 R=0.50 F1=0.56
# rouge2: P=0.40 R=0.30 F1=0.34
# rougeL: P=0.62 R=0.50 F1=0.56
BLEU가 실제 시스템에서 오해를 불러오는 한 가지 이유·python
# Two outputs that mean the same thing — BLEU disagrees.
ref  = "The doctor prescribed antibiotics for the infection."
a    = "The doctor prescribed antibiotics for the infection."   # identical
b    = "For the infection, the physician prescribed antibiotics."  # paraphrase

from sacrebleu import sentence_bleu
print(sentence_bleu(a, [ref]).score)  # ~100
print(sentence_bleu(b, [ref]).score)  # ~30 — penalized for word reordering

External links

Exercise

중요하게 보는 요약 과제의 출력 30개를 가져와. 참조 답안과 비교해 ROUGE-L F1을 계산하고, 동료에게 같은 출력의 품질을 1~5점으로 평가해 달라고 부탁해. 두 결과의 상관관계를 그래프로 그린 뒤 BLEU/ROUGE와 인간 판단이 어디에서 달라지는지 살펴봐.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.