Get startedGet started for free

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.

This exercise is part of the course

Working with Hugging Face

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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 and Run Code