语言任务评测指标:ROUGE、METEOR、EM

Python 中的 LLM 入门

Jasmin Ludolf

Senior Data Science Content Developer, DataCamp

LLM 任务与指标

 

语言任务的评测指标

Python 中的 LLM 入门

LLM 任务与指标

 

语言任务的评测指标

Python 中的 LLM 入门

LLM 任务与指标

 

语言任务的评测指标

Python 中的 LLM 入门

ROUGE

  • ROUGE: 生成摘要与参考摘要的相似度
    • 基于 n-gram 与重合
    • predictions: LLM 输出
    • references: 人工摘要

比较 the cat sat on the mat 和 the cat is on the mat

Python 中的 LLM 入门

ROUGE

rouge = evaluate.load("rouge")
predictions = ["""as we learn more about the frequency and size distribution of 
exoplanets, we are discovering that terrestrial planets are exceedingly common."""]
references = ["""The more we learn about the frequency and size distribution of 
exoplanets, the more confident we are that they are exceedingly common."""]

ROUGE 分数:

  • rouge1:unigram 重合
  • rouge2:bigram 重合
  • rougeL:最长公共子序列
Python 中的 LLM 入门

ROUGE 输出

ROUGE 分数:

  • rouge1:unigram 重合
  • rouge2:bigram 重合
  • rougeL:最长公共子序列

 

  • 分数 0-1:越高表示相似度越高
results = rouge.compute(predictions=predictions,
                         references=references)

print(results)
{'rouge1': 0.7441860465116279, 
'rouge2': 0.4878048780487805, 
'rougeL': 0.6976744186046512, 
'rougeLsum': 0.6976744186046512}
Python 中的 LLM 入门

METEOR

  • METEOR: 考虑更多语言特征,如词形变化、同义与词序
bleu = evaluate.load("bleu")
meteor = evaluate.load("meteor")


prediction = ["He thought it right and necessary to become a knight-errant, roaming the world in armor, seeking adventures and practicing the deeds he had read about in chivalric tales."] reference = ["He believed it was proper and essential to transform into a knight-errant, traveling the world in armor, pursuing adventures, and enacting the heroic deeds he had encountered in tales of chivalry."]
Python 中的 LLM 入门

METEOR

results_bleu = bleu.compute(predictions=pred, references=ref)
results_meteor = meteor.compute(predictions=pred, references=ref)
print("Bleu: ", results_bleu['bleu'])
print("Meteor: ", results_meteor['meteor'])
Bleu:  0.19088841781992524
Meteor:  0.5350702240481536
  • 0-1 分数:越高越好
Python 中的 LLM 入门

问答

 

语言任务的评测指标

Python 中的 LLM 入门

完全匹配(EM)

  • Exact Match(EM): 若 LLM 输出与参考答案完全一致则为 1

 

  • 通常与 F1 分数 一起使用
from evaluate import load
em_metric = load("exact_match")

exact_match = evaluate.load("exact_match")
predictions = ["The cat sat on the mat.",
               "Theaters are great.", 
               "Like comparing oranges and apples."]
references = ["The cat sat on the mat?", 
              "Theaters are great.", 
              "Like comparing apples and oranges."]

results = exact_match.compute(
  references=references, predictions=predictions)
print(results)
{'exact_match': 0.3333333333333333}
Python 中的 LLM 入门

让我们来练习!

Python 中的 LLM 入门

Preparing Video For Download...