rouge

class RougeL(trans_func=None, vocab=None, gamma=1.2, name='rouge-l', *args, **kwargs)[source]

Bases: paddle.metric.metrics.Metric

Rouge-L is Recall-Oriented Understudy for Gisting Evaluation based on Longest Common Subsequence (LCS). Longest common subsequence problem takes into account sentence level structure similarity naturally and identifies longest co-occurring in sequence n-grams automatically.

\[ \begin{align}\begin{aligned}R_{LCS} & = \frac{LCS(C,S)}{len(S)}\\P_{LCS} & = \frac{LCS(C,S)}{len(C)}\\F_{LCS} & = \frac{(1 + \gamma^2)R_{LCS}P_{LCS}}}{R_{LCS} + \gamma^2{R_{LCS}}\end{aligned}\end{align} \]

where C is the candidate sentence, and ‘S’ is the refrence sentence.

Parameters

gamma (float) – A hyperparameter to decide the weight of recall. Default: 1.2.

Examples:(TODO: liujiaqi)
  1. Using as a general evaluation object.

  2. Using as an instance of paddle.metric.Metric.

lcs(string, sub)[source]

Calculate the length of longest common subsequence of string and sub.

add_inst(cand, ref_list)[source]

Update the states based on the a pair of candidate and references.

Parameters
  • cand (str) – The candidate sentence generated by model.

  • ref_list (list) – List of ground truth sentences.

update(output, label, seq_mask=None)[source]

Update states for metric

Inputs of update is the outputs of Metric.compute, if compute is not defined, the inputs of update will be flatten arguments of output of mode and label from data: update(output1, output2, ..., label1, label2,...)

see Metric.compute

accumulate()[source]

Calculate the final rouge-l metric.

reset()[source]

Reset states and result

name()[source]

Returns metric name

class RougeLForDuReader(alpha=1.0, beta=1.0, gamma=1.2)[source]

Bases: paddlenlp.metrics.rouge.RougeL

Rouge-L metric with bonus for DuReader contest.

Please refer to `DuReader Homepage<https://ai.baidu.com//broad/subordinate?dataset=dureader>`_ for more details.

add_inst(cand, ref_list, yn_label=None, yn_ref=None, entity_ref=None)[source]

Update the states based on the a pair of candidate and references.

Parameters
  • cand (str) – The candidate sentence generated by model.

  • ref_list (list) – List of ground truth sentences.