ROUGE
Recall-Oriented Understudy for Gisting Evaluation
A family of metrics for measuring summary quality. ROUGE-1, ROUGE-L, and others.
Recall-Oriented Understudy for Gisting Evaluation
A family of metrics for measuring summary quality. ROUGE-1, ROUGE-L, and others.
ROUGE (Recall-Oriented Understudy for Gisting Evaluation) is a family of metrics that automatically evaluate the quality of text summaries. It calculates scores by measuring n-gram overlap between a generated summary and a reference summary, and it has several variants such as ROUGE-1, ROUGE-2, and ROUGE-L.
ROUGE was developed by Chin-Yew Lin at USC in 2004 and was originally designed to evaluate document summarization systems. While BLEU focuses on precision in machine translation, ROUGE emphasizes recall, which makes it better suited to evaluating summaries.
The core principle of ROUGE is n-gram matching. ROUGE-1 measures word (unigram) overlap, and ROUGE-2 measures overlap of two consecutive words (bigrams). ROUGE-L uses the longest common subsequence (LCS) to calculate similarity that takes word order into account. In general, the F1 score (the harmonic mean of precision and recall) is used as the final metric.
In practice, ROUGE is a standard evaluation metric for NLG tasks such as summarization, question answering, and dialogue generation. However, it has a limitation in that it cannot fully capture semantic similarity, so there is a trend of using it together with embedding-based metrics such as BERTScore and BLEURT. In the LLM era, GPT-4-based evaluation is also used in parallel.
This is an example of calculating ROUGE scores using the rouge-score library.
# pip install rouge-score
from rouge_score import rouge_scorer
# ROUGE Scorer μ΄κΈ°ν
scorer = rouge_scorer.RougeScorer(['rouge1', 'rouge2', 'rougeL'], use_stemmer=True)
# μ°Έμ‘° μμ½ (μ λ΅)
reference = "μΈκ³΅μ§λ₯μ κΈ°κ³κ° μΈκ°μ²λΌ νμ΅νκ³ νλ¨νλ κΈ°μ μ
λλ€."
# μμ±λ μμ½ (λͺ¨λΈ μΆλ ₯)
candidate = "AIλ κΈ°κ³κ° νμ΅νκ³ μΆλ‘ νλ κΈ°μ μ
λλ€."
# ROUGE μ μ κ³μ°
scores = scorer.score(reference, candidate)
print("=== ROUGE Scores ===")
for metric, score in scores.items():
print(f"{metric}:")
print(f" Precision: {score.precision:.4f}")
print(f" Recall: {score.recall:.4f}")
print(f" F1: {score.fmeasure:.4f}")
# μ¬λ¬ μνμ νκ· κ³μ°
def calculate_avg_rouge(references, candidates):
"""μ¬λ¬ μνμ νκ· ROUGE μ μ κ³μ°"""
total_scores = {'rouge1': 0, 'rouge2': 0, 'rougeL': 0}
for ref, cand in zip(references, candidates):
scores = scorer.score(ref, cand)
for metric in total_scores:
total_scores[metric] += scores[metric].fmeasure
return {k: v / len(references) for k, v in total_scores.items()}
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free