사전 학습된 텍스트 생성 모델 평가하기
PyBooks 팀은 여러분이 실습했던 사전 학습된 GPT-2 모델을 사용해 주어진 프롬프트로부터 텍스트를 생성했어요. 이제 생성된 텍스트의 품질을 평가하고자 합니다. 이를 위해, 기준(reference) 텍스트를 사용해 생성된 텍스트를 평가해 달라고 여러분에게 맡겼어요.
BLEUScore, ROUGEScore는 미리 로드되어 있어요.
이 연습은 강의의 일부입니다
PyTorch로 배우는 텍스트 딥러닝
연습 안내
torchmetrics.text에서 제공하는 두 메트릭(BLEU, ROUGE)을 초기화하세요.- 초기화한 메트릭을 사용해 생성된 텍스트와 기준 텍스트 사이의 점수를 계산하세요.
- 계산한 BLEU와 ROUGE 점수를 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
reference_text = "Once upon a time, there was a little girl who lived in a village near the forest."
generated_text = "Once upon a time, the world was a place of great beauty and great danger. The world of the gods was the place where the great gods were born, and where they were to live."
# Initialize BLEU and ROUGE scorers
bleu = ____()
rouge = ____()
# Calculate the BLEU and ROUGE scores
bleu_score = bleu([____], [[reference_text]])
rouge_score = rouge([generated_text], [[____]])
# Print the BLEU and ROUGE scores
print("BLEU Score:", bleu_score.____())
print("ROUGE Score:", rouge_score)