始める無料で始める

事前学習済みのテキスト生成モデルを評価する

PyBooks チームは、あなたが試した事前学習済みの GPT-2 モデルを使って、与えられたプロンプトに基づくテキストを生成しました。次に、この生成テキストの品質を評価したいと考えています。そのために、参照テキストを用いて生成テキストを評価するタスクがあなたに任されました。

BLEUScoreROUGEScore は読み込まれています。

この演習はコースの一部です

PyTorch で学ぶテキストの Deep Learning

コースを見る

演習の手順

  • torchmetrics.text から提供されている 2 つの評価指標(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)
コードを編集して実行