텍스트 생성 평가 지표

PyTorch로 배우는 텍스트 딥러닝

Shubham Jain

Instructor

텍스트 생성 평가

  • 텍스트 생성은 사람처럼 읽히는 텍스트를 만듭니다
  • 정확도, F1 같은 일반 지표는 부적합합니다
  • 생성 텍스트의 품질을 평가할 지표가 필요합니다
  • BLEU와 ROUGE

텍스트 생성을 위한 Dalle 챗봇

PyTorch로 배우는 텍스트 딥러닝

BLEU (Bilingual Evaluation Understudy)

  • 생성 텍스트와 기준(reference) 텍스트를 비교합니다
  • n-그램 발생을 확인합니다
  • 문장 "The cat is on the mat"에서
    • 1-그램(유니그램): [the ,cat, is, on, the, mat]
    • 2-그램(바이그램): ["the cat", "cat is", "is on", "on the", "the mat"]
    • n-그램은 n에 따라 계속됩니다
  • 완전 일치: 점수 1.0
    • 0은 불일치
PyTorch로 배우는 텍스트 딥러닝

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로 배우는 텍스트 딥러닝

ROUGE (Recall-Oriented Understudy for Gisting Evaluation)

  • 생성 텍스트를 기준 텍스트와 두 방식으로 비교합니다
  • ROUGE-N: 두 텍스트의 n-그램 겹침(N=1은 유니그램, 2는 바이그램 등)
  • ROUGE-L: 두 텍스트의 최장 공통 부분수열(LCS)
  • ROUGE 지표:
    • F-측도: 정밀도와 재현율의 조화 평균
    • 정밀도: 생성 텍스트의 n-그램이 기준 텍스트와 일치
    • 재현율: 기준 텍스트의 n-그램이 생성 텍스트와 일치
  • 'rouge1', 'rouge2', 'rougeL'은 각각 1-그램, 2-그램, LCS를 의미합니다
PyTorch로 배우는 텍스트 딥러닝

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로 배우는 텍스트 딥러닝

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로 배우는 텍스트 딥러닝

고려사항과 한계

  • 의미 이해가 아닌 단어 존재 여부를 평가합니다
  • 생성 텍스트 길이에 민감합니다
  • 기준(reference) 텍스트의 품질이 점수에 영향합니다
PyTorch로 배우는 텍스트 딥러닝

연습해 봅시다!

PyTorch로 배우는 텍스트 딥러닝

Preparing Video For Download...