テキスト生成の評価指標

PyTorch で学ぶテキストの Deep Learning

Shubham Jain

Instructor

テキスト生成の評価

  • テキスト生成は人間らしい文を作る
  • 精度やF1などの汎用指標は不十分
  • 生成文の質を測る指標が必要
  • BLEU と ROUGE

テキスト生成用Dalleチャットボット

PyTorch で学ぶテキストの Deep Learning

BLEU(Bilingual Evaluation Understudy)

  • 生成文と参照文を比較
  • n-gram の一致を確認
  • 文「The cat is on the mat」では
    • 1-gram(ユニグラム): [the ,cat, is, on, the, mat]
    • 2-gram(バイグラム): ["the cat", "cat is", "is on", "on the", "the mat"]
    • n-gram は同様に拡張
  • 完全一致は 1.0
    • 0 は不一致
PyTorch で学ぶテキストの Deep Learning

PyTorchでBLEUを計算

from torchmetrics.text import BLEUScore

generated_text = ['the cat is on the mat'] real_text = [['there is a cat on the mat', 'a cat is on the mat']]
bleu = BLEUScore() bleu_metric = bleu(generated_text, real_text) print("BLEU Score: ", bleu_metric.item())
BLEU Score: tensor(0.7598)
PyTorch で学ぶテキストの Deep Learning

ROUGE(Recall-Oriented Understudy for Gisting Evaluation)

  • 生成文を参照文と2通りで比較
  • ROUGE-N: 両文の n-gram の重なり(N=1はユニグラム、2はバイグラム等)
  • ROUGE-L: 最長共通部分列(LCS)を比較
  • ROUGEの指標:
    • F値: 適合率と再現率の調和平均
    • 適合率: 生成文中の n-gram が参照文に一致
    • 再現率: 参照文中の n-gram が生成文に一致
  • 'rouge1'、'rouge2'、'rougeL' はそれぞれ1-gram、2-gram、LCSを指す
PyTorch で学ぶテキストの Deep Learning

PyTorchでROUGEを計算

from torchmetrics.text import  ROUGEScore

generated_text='Hello, how are you doing?' real_text= "Hello, how are you?"
rouge = ROUGEScore()
rouge_score = rouge([generated_text], [[real_text]]) print("ROUGE Score:", rouge_score)
PyTorch で学ぶテキストの Deep Learning

ROUGEスコア:出力

ROUGE Score: {'rouge1_fmeasure': tensor(0.8889), 
              'rouge1_precision': tensor(0.8000), 
              'rouge1_recall': tensor(1.),

'rouge2_fmeasure': tensor(0.8571), 'rouge2_precision': tensor(0.7500), 'rouge2_recall': tensor(1.),
'rougeL_fmeasure': tensor(0.8889), 'rougeL_precision': tensor(0.8000), 'rougeL_recall': tensor(1.),
'rougeLsum_fmeasure': tensor(0.8889), 'rougeLsum_precision': tensor(0.8000), 'rougeLsum_recall': tensor(1.)}
PyTorch で学ぶテキストの Deep Learning

考慮点と限界

  • 語の一致を評価し、意味理解は評価しない
  • 生成文の長さに影響を受けやすい
  • 参照文の品質がスコアに影響
PyTorch で学ぶテキストの Deep Learning

練習しましょう!

PyTorch で学ぶテキストの Deep Learning

Preparing Video For Download...