paddlenlp/metrics/rouge.py
def add_inst(self, cand, ref_list):
        '''
        Update the states based on the a pair of candidate and references.

        Args:
            cand (str): The candidate sentence generated by model.
            ref_list (list): List of ground truth sentences.
        '''
        precs, recalls = [], []
        for ref in ref_list:
            basic_lcs = self.lcs(cand, ref)
            prec = basic_lcs / len(cand) if len(cand) > 0. else 0.
            rec = basic_lcs / len(ref) if len(ref) > 0. else 0.
            precs.append(prec)
            recalls.append(rec)

        prec_max = max(precs)
        rec_max = max(recalls)

        if prec_max != 0 and rec_max != 0:
            score = ((1 + self.gamma**2) * prec_max * rec_max) / \
                    float(rec_max + self.gamma**2 * prec_max)
        else:
            score = 0.0
        self.inst_scores.append(score)

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

        Args:
            cand (str): The candidate sentence generated by model.
            ref_list (list): List of ground truth sentences.
        
Update the states based on the a pair of candidate and references.
Update the states based on the a pair of candidate and references .
def add_inst(self, cand, ref_list):
        precs, recalls = [], []
        for ref in ref_list:
            basic_lcs = self.lcs(cand, ref)
            prec = basic_lcs / len(cand) if len(cand) > 0. else 0.
            rec = basic_lcs / len(ref) if len(ref) > 0. else 0.
            precs.append(prec)
            recalls.append(rec)
        prec_max = max(precs)
        rec_max = max(recalls)
        if prec_max != 0 and rec_max != 0:
            score = ((1 + self.gamma**2) * prec_max * rec_max) / \
                    float(rec_max + self.gamma**2 * prec_max)
        else:
            score = 0.0
        self.inst_scores.append(score)
def add_inst ( self , cand , ref_list ) : precs , recalls = [ ] , [ ] for ref in ref_list : basic_lcs = self . lcs ( cand , ref ) prec = basic_lcs / len ( cand ) if len ( cand ) > 0. else 0. rec = basic_lcs / len ( ref ) if len ( ref ) > 0. else 0. precs . append ( prec ) recalls . append ( rec ) prec_max = max ( precs ) rec_max = max ( recalls ) if prec_max != 0 and rec_max != 0 : score = ( ( 1 + self . gamma ** 2 ) * prec_max * rec_max ) / float ( rec_max + self . gamma ** 2 * prec_max ) else : score = 0.0 self . inst_scores . append ( score )
Update the states based on the a pair of candidate and references.
Update the states based on the a pair of candidate and references .
'''
        Update the states based on the a pair of candidate and references.

        Args:
            cand (str): The candidate sentence generated by model.
            ref_list (list): List of ground truth sentences.
        '''
self
cand
The candidate sentence generated by model.
The candidate sentence generated by model .
ref_list
List of ground truth sentences.
List of ground truth sentences .