Main Content

rougeEvaluationScore

Evaluate translation or summarization with ROUGE similarity score

Description

The Recall-Oriented Understudy for Gisting Evaluation (ROUGE) scoring algorithm evaluates the similarity between a candidate document and a collection of reference documents. Use the ROUGE score to evaluate the quality of document translation and summarization models.

score = rougeEvaluationScore(candidate,references) returns the ROUGE score between the specified candidate document and the reference documents. The function, by default, computes unigram overlaps between candidate and references. This is also known as the ROUGE-N metric with n-gram length 1. For more information, see ROUGE Score.

example

score = rougeEvaluationScore(candidate,references,Name,Value) specifies additional options using one or more name-value pairs.

example

Examples

collapse all

Specify the candidate document as a tokenizedDocument object.

str = "the fast brown fox jumped over the lazy dog";
candidate = tokenizedDocument(str)
candidate = 
  tokenizedDocument:

   9 tokens: the fast brown fox jumped over the lazy dog

Specify the reference documents as a tokenizedDocument array.

str = [
    "the quick brown animal jumped over the lazy dog"
    "the quick brown fox jumped over the lazy dog"];
references = tokenizedDocument(str)
references = 
  2×1 tokenizedDocument:

    9 tokens: the quick brown animal jumped over the lazy dog
    9 tokens: the quick brown fox jumped over the lazy dog

Calculate the ROUGE score between the candidate document and the reference documents.

score = rougeEvaluationScore(candidate,references)
score = 
0.8889

Specify the candidate document as a tokenizedDocument object.

str = "a simple summary document containing some words";
candidate = tokenizedDocument(str)
candidate = 
  tokenizedDocument:

   7 tokens: a simple summary document containing some words

Specify the reference documents as a tokenizedDocument array.

str = [
    "a simple document"
    "another document with some words"];
references = tokenizedDocument(str)
references = 
  2×1 tokenizedDocument:

    3 tokens: a simple document
    5 tokens: another document with some words

Calculate the ROUGE score between the candidate document and the reference documents using the default options.

score = rougeEvaluationScore(candidate,references)
score = 
1

The rougeEvaluationScore function, by default, compares unigram (single-token) overlaps between the candidate document and the reference documents. Because the ROUGE score is a recall-based measure, if one of the reference documents is made up entirely of unigrams that appear in the candidate document, the resulting ROUGE score is one. In this scenario, the output of the rougeEvaluationScore function is uninformative.

For a more meaningful result, calculate the ROUGE score again using bigrams by setting the 'NgramLength' option to 2. The resulting score is less than one, since every reference document contains bigrams that do not appear in the candidate document.

score = rougeEvaluationScore(candidate,references,'NgramLength',2)
score = 
0.5000

Input Arguments

collapse all

Candidate document, specified as a tokenizedDocument scalar, a string array, or a cell array of character vectors. If candidate is not a tokenizedDocument scalar, then it must be a row vector representing a single document, where each element is a word.

Reference documents, specified as a tokenizedDocument array, a string array, or a cell array of character vectors. If references is not a tokenizedDocument array, then it must be a row vector representing a single document, where each element is a word. To evaluate against multiple reference documents, use a tokenizedDocument array.

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: scores = rougeEvaluationScore(candidate,references,'ROUGEMethod','weighted-subsequences') specifies to use the weighted subsequences ROUGE method.

ROUGE method, specified as the comma-separated pair consisting of 'ROUGEMethod' and one of the following:

  • 'n-grams' – Evaluate the ROUGE score using n-gram overlaps between the candidate document and the reference documents. This is also known as the ROUGE-N metric.

  • 'longest-common-subsequences' – Evaluate the ROUGE score using Longest Common Subsequence (LCS) statistics. This is also known as the ROUGE-L metric.

  • 'weighted-subsequences' – Evaluate the ROUGE score using weighted longest common subsequence statistics. This method favors consecutive LCSs. This is also known as the ROUGE-W metric.

  • 'skip-bigrams' – Evaluate the ROUGE score using skip-bigram (any pair of words in sentence order) co-occurrence statistics. This is also known as the ROUGE-S metric.

  • 'skip-bigrams-and-unigrams' – Evaluate the ROUGE score using skip-bigram and unigram co-occurrence statistics. This is also known as the ROUGE-SU metric.

N-gram length used for the 'n-grams' ROUGE method (ROUGE-N), specified as the comma-separated pair consisting of 'NgramLength' and a positive integer.

If the 'ROUGEMethod' option is not 'n-grams', then the 'NgramLength' option has no effect.

Tip

If the longest document in references has fewer than NgramLength words, then the resulting ROUGE score is NaN. If candidate has fewer than NgramLength words, then the resulting ROUGE score is zero. To ensure that rougeEvaluationScore returns nonzero scores for very short documents, set NgramLength to a positive integer smaller than the length of candidate and the length of the longest document in references.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Skip distance used for the 'skip-bigrams' and 'skip-bigrams-and-unigrams' ROUGE methods (ROUGE-S and ROUGE-SU), specified as the comma-separated pair consisting of 'SkipDistance' and a positive integer.

If the 'ROUGEMethod' option is not 'skip-bigrams' or 'skip-bigrams-and-unigrams', then the 'SkipDistance' option has no effect.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

ROUGE score, returned as a scalar value in the range [0,1] or NaN.

A ROUGE score close to zero indicates poor similarity between candidate and references. A ROUGE score close to one indicates strong similarity between candidate and references. If candidate is identical to one of the reference documents, then score is 1. If candidate and references are both empty documents, then the resulting ROUGE score is NaN.

Tip

If the longest document in references has fewer than NgramLength words, then the resulting ROUGE score is NaN. If candidate has fewer than NgramLength words, then the resulting ROUGE score is zero. To ensure that rougeEvaluationScore returns nonzero scores for very short documents, set NgramLength to a positive integer smaller than the length of candidate and the length of the longest document in references.

Algorithms

collapse all

References

[1] Lin, Chin-Yew. "Rouge: A package for automatic evaluation of summaries." In Text Summarization Branches Out, pp. 74-81. 2004.

Version History

Introduced in R2020a