เมตริกการประเมินสำหรับการสร้างข้อความ

Deep Learning สำหรับข้อความด้วย PyTorch

Shubham Jain

Instructor

การประเมินการสร้างข้อความ

  • งานการสร้างข้อความจะสร้างข้อความที่คล้ายมนุษย์
  • เมตริกความแม่นยำมาตรฐาน เช่น accuracy และ F1 ไม่เหมาะกับงานเหล่านี้
  • ต้องใช้เมตริกที่ประเมินคุณภาพของข้อความที่สร้างขึ้น
  • BLEU และ ROUGE

Dalle Chatbot สำหรับการสร้างข้อความ

Deep Learning สำหรับข้อความด้วย PyTorch

BLEU (Bilingual Evaluation Understudy)

  • เปรียบเทียบข้อความที่สร้างขึ้นกับข้อความอ้างอิง
  • ตรวจสอบการปรากฏของ n-gram
  • ในประโยค "The cat is on the mat"
    • 1-gram (uni-gram): [the, cat, is, on, the, mat]
    • 2-gram (bi-gram): ["the cat", "cat is", "is on", "on the", และ "the mat"]
    • และต่อไปสำหรับ n-gram
  • ตรงทั้งหมด: คะแนน 1.0
    • 0 หมายถึงไม่ตรงเลย
Deep Learning สำหรับข้อความด้วย PyTorch

การคำนวณคะแนน BLEU ด้วย 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 สำหรับข้อความด้วย PyTorch

ROUGE (Recall-Oriented Understudy for Gisting Evaluation)

  • เปรียบเทียบข้อความที่สร้างขึ้นกับข้อความอ้างอิงใน 2 วิธี
  • ROUGE-N: พิจารณา n-gram ที่ซ้อนทับกัน (N=1 สำหรับ unigram, 2 สำหรับ bigram เป็นต้น) ในทั้งสองข้อความ
  • ROUGE-L: ดูลำดับย่อยร่วมที่ยาวที่สุด (LCS) ระหว่างข้อความ
  • เมตริก ROUGE:
    • F-measure: ค่าเฉลี่ยฮาร์มอนิกของ precision และ recall
    • Precision: n-gram ในข้อความที่สร้างขึ้นที่ตรงกับข้อความอ้างอิง
    • Recall: n-gram ในข้อความอ้างอิงที่ตรงกับข้อความที่สร้างขึ้น
  • คำนำหน้า 'rouge1', 'rouge2', และ 'rougeL' หมายถึง 1-gram, 2-gram, หรือ LCS ตามลำดับ
Deep Learning สำหรับข้อความด้วย PyTorch

การคำนวณคะแนน ROUGE ด้วย 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 สำหรับข้อความด้วย PyTorch

คะแนน 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.)}
Deep Learning สำหรับข้อความด้วย PyTorch

ข้อควรพิจารณาและข้อจำกัด

  • ประเมินการปรากฏของคำ ไม่ใช่ความเข้าใจเชิงความหมาย
  • อ่อนไหวต่อความยาวของข้อความที่สร้างขึ้น
  • คุณภาพของข้อความอ้างอิงส่งผลต่อคะแนน
Deep Learning สำหรับข้อความด้วย PyTorch

มาฝึกกันเถอะ!

Deep Learning สำหรับข้อความด้วย PyTorch

Preparing Video For Download...