rouge

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

基类: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.

参数

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)[源代码]

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

add_inst(cand, ref_list)[源代码]

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

参数
  • cand (str) -- The candidate sentence generated by model.

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

update(output, label, seq_mask=None)[源代码]

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()[源代码]

Calculate the final rouge-l metric.

reset()[源代码]

Reset states and result

name()[源代码]

Returns metric name

class RougeLForDuReader(alpha=1.0, beta=1.0, gamma=1.2)[源代码]

基类: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)[源代码]

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

参数
  • cand (str) -- The candidate sentence generated by model.

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