utils.py
def calculate_metric_scores(cands, refs):
    """ calculate Rouge-1 precision, Bert precision
    and Entailment Scores
    """
    # calculate rouge-1 precision
    rouge = Rouge()
    rouge1_p = []
    for r, c in tqdm(zip(refs, cands)):
        r = " ".join(list(nlp_parser.tokenize(r))).lower()
        c = " ".join(list(nlp_parser.tokenize(c))).lower()
        scores = rouge.get_scores(c, r)[0]
        rouge1_p.append(round(scores['rouge-1']['p'], 4))
    # calculate bert precision
    P, _, _ = score(cands, refs, lang='en', verbose=True)
    P = [round(x, 4) for x in P.tolist()]
    ## calculate entaiment score
    url = 'http://localhost:5003/roberta_mnli_classifier'  # 'http://nlp1.cs.unc.edu:5003/roberta_mnli_classifier'
    mnli_data = []
    for p, h in zip(refs, cands):
        mnli_data.append({'premise': p, 'hypo': h})
    r = requests.post(url, json=mnli_data)
    results = r.json()
    ent_scores = []
    for ind, d in enumerate(results):
        ent_scores.append(float(d['entailment']))

    return rouge1_p, P, ent_scores
 calculate Rouge-1 precision, Bert precision
    and Entailment Scores
    
calculate Rouge-1 precision, Bert precision
and Entailment Scores
calculate Rouge - 1 precision Bert precision and Entailment Scores
def calculate_metric_scores(cands, refs):
    rouge = Rouge()
    rouge1_p = []
    for r, c in tqdm(zip(refs, cands)):
        r = " ".join(list(nlp_parser.tokenize(r))).lower()
        c = " ".join(list(nlp_parser.tokenize(c))).lower()
        scores = rouge.get_scores(c, r)[0]
        rouge1_p.append(round(scores['rouge-1']['p'], 4))
    P, _, _ = score(cands, refs, lang='en', verbose=True)
    P = [round(x, 4) for x in P.tolist()]
    url = 'http://localhost:5003/roberta_mnli_classifier'  
    mnli_data = []
    for p, h in zip(refs, cands):
        mnli_data.append({'premise': p, 'hypo': h})
    r = requests.post(url, json=mnli_data)
    results = r.json()
    ent_scores = []
    for ind, d in enumerate(results):
        ent_scores.append(float(d['entailment']))
    return rouge1_p, P, ent_scores
def calculate_metric_scores ( cands , refs ) : rouge = Rouge ( ) rouge1_p = [ ] for r , c in tqdm ( zip ( refs , cands ) ) : r = " " . join ( list ( nlp_parser . tokenize ( r ) ) ) . lower ( ) c = " " . join ( list ( nlp_parser . tokenize ( c ) ) ) . lower ( ) scores = rouge . get_scores ( c , r ) [ 0 ] rouge1_p . append ( round ( scores [ 'rouge-1' ] [ 'p' ] , 4 ) ) P , _ , _ = score ( cands , refs , lang = 'en' , verbose = True ) P = [ round ( x , 4 ) for x in P . tolist ( ) ] url = 'http://localhost:5003/roberta_mnli_classifier' mnli_data = [ ] for p , h in zip ( refs , cands ) : mnli_data . append ( { 'premise' : p , 'hypo' : h } ) r = requests . post ( url , json = mnli_data ) results = r . json ( ) ent_scores = [ ] for ind , d in enumerate ( results ) : ent_scores . append ( float ( d [ 'entailment' ] ) ) return rouge1_p , P , ent_scores
calculate Rouge-1 precision, Bert precision
and Entailment Scores
calculate Rouge - 1 precision Bert precision and Entailment Scores
""" calculate Rouge-1 precision, Bert precision
    and Entailment Scores
    """ # calculate rouge-1 precision # calculate bert precision ## calculate entaiment score # 'http://nlp1.cs.unc.edu:5003/roberta_mnli_classifier'
cands
refs