評估預訓練的文字生成模型
PyBooks 團隊使用了你先前操作過的預訓練 GPT-2 模型,根據給定的提示產生文字。現在,他們想評估這段生成文字的品質。為此,他們交給你一個任務:使用一段參考文字來評估生成文字。
BLEUScore、ROUGEScore 已為你載入。
本練習屬於課程
Deep Learning for Text with 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)