Valutare un modello preaddestrato di generazione del testo
Il team di PyBooks ha usato un modello GPT-2 preaddestrato, con cui hai già fatto esperimenti, per generare un testo a partire da un prompt. Ora vogliono valutare la qualità di questo testo generato. Per farlo, ti hanno incaricato di valutare il testo generato usando un testo di riferimento.
BLEUScore, ROUGEScore sono già stati caricati per te.
Questo esercizio fa parte del corso
Deep Learning per il testo con PyTorch
Istruzioni dell'esercizio
- Inizia inizializzando le due metriche (BLEU e ROUGE) fornite da
torchmetrics.text. - Usa queste metriche inizializzate per calcolare i punteggi tra il testo generato e il testo di riferimento.
- Mostra i punteggi BLEU e ROUGE calcolati.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
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)