Python ROUGE Score Implementation

1.0.1 · active · verified Sun Apr 12

The 'rouge' library provides a full, native Python implementation of the ROUGE (Recall-Oriented Understudy for Gisting Evaluation) metric, used for evaluating automatic text summarization and machine translation. Unlike some other ROUGE packages, it is not a wrapper around the original Perl script. The current stable version is 1.0.1, with releases occurring periodically to introduce features and fixes.

Warnings

Install

Imports

Quickstart

Calculate ROUGE scores (ROUGE-1, ROUGE-2, ROUGE-L) for a single hypothesis-reference pair. The `get_scores` method returns a list of dictionaries, each containing 'f' (F1-score), 'p' (precision), and 'r' (recall) for each ROUGE type.

from rouge import Rouge

hypothesis = "the cat sat on the mat"
reference = "the cat is on the mat"

rouge = Rouge()
scores = rouge.get_scores(hypothesis, reference)
print(scores)

view raw JSON →