MulaiMulai sekarang secara gratis

Adjusting the summary length

The pipeline() function, has two important parameters: min_new_tokens and max_new_tokens. These are useful for adjusting the length of the resulting summary text to be short, longer, or within a certain number of words. You might want to do this if there are space constraints (i.e., small storage), to enhance readability, or improve the quality of the summary.

You'll experiment with a short and long summarizer by setting these two parameters to a small range, then a wider range.

pipeline from the transformers library and the original_text have already been loaded for you.

Latihan ini adalah bagian dari kursus

Working with Hugging Face

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Generate a summary of original_text between 1 and 10 tokens
short_summarizer = pipeline(task="summarization", model="cnicu/t5-small-booksum", ____=1, ____=10)

short_summary_text = ____(original_text)

print(short_summary_text[0]["summary_text"])
Edit dan Jalankan Kode