Metriky hodnocení generování textu

Deep Learning for Text with PyTorch

Shubham Jain

Instructor

Hodnocení generování textu

  • Úlohy generování textu vytvářejí text podobný lidskému
  • Standardní metriky jako přesnost nebo F1 pro tyto úlohy nestačí
  • Potřebujeme metriky hodnotící kvalitu generovaného textu
  • BLEU a ROUGE

Chatbot Dalle pro generování textu

Deep Learning for Text with PyTorch

BLEU (Bilingual Evaluation Understudy)

  • Porovnává generovaný text s referenčním textem
  • Kontroluje výskyt n-gramů
  • Ve větě "The cat is on the mat"
    • 1-gramy (uni-gram): [the, cat, is, on, the, mat]
    • 2-gramy (bi-gram): ["the cat", "cat is", "is on", "on the", „the mat"]
    • a tak dále pro n-gramy
  • Perfektní shoda: skóre 1,0
    • 0 znamená žádnou shodu
Deep Learning for Text with PyTorch

Výpočet skóre BLEU pomocí PyTorch

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)
Deep Learning for Text with PyTorch

ROUGE (Recall-Oriented Understudy for Gisting Evaluation)

  • Porovnává generovaný text s referenčním textem dvěma způsoby
  • ROUGE-N: Zohledňuje překrývající se n-gramy (N=1 pro unigramy, 2 pro bigramy atd.)
  • ROUGE-L: Hledá nejdelší společnou podsekvenci (LCS) mezi texty
  • Metriky ROUGE:
    • F-míra: harmonický průměr přesnosti a úplnosti
    • Přesnost: shody n-gramů generovaného textu v referenčním textu
    • Úplnost: shody n-gramů referenčního textu v generovaném textu
  • Předpony 'rouge1', 'rouge2' a 'rougeL' označují 1-gram, 2-gram nebo LCS
Deep Learning for Text with PyTorch

Výpočet skóre ROUGE pomocí PyTorch

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)
Deep Learning for Text with PyTorch

Skóre ROUGE: výstup

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.)}
Deep Learning for Text with PyTorch

Omezení a úskalí

  • Hodnotí přítomnost slov, nikoli sémantické porozumění
  • Citlivé na délku generovaného textu
  • Kvalita referenčního textu ovlivňuje skóre
Deep Learning for Text with PyTorch

Pojďme procvičovat!

Deep Learning for Text with PyTorch

Preparing Video For Download...