Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load the summarization pipeline from Hugging Face.
NLP
from transformers import pipeline summarizer = pipeline([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong pipeline name like "translation" or "text-generation".
Forgetting to put the pipeline name in quotes.
✗ Incorrect
The pipeline for text summarization is called "summarization" in Hugging Face.
2fill in blank
mediumComplete the code to summarize the given text using the summarizer pipeline.
NLP
text = "Machine learning helps computers learn from data." summary = summarizer([1], max_length=20, min_length=5, do_sample=False) print(summary[0]['summary_text'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the string "text" instead of the variable text.
Passing summary or text[0] which are incorrect here.
✗ Incorrect
You need to pass the variable 'text' containing the input string to the summarizer.
3fill in blank
hardFix the error in the code to correctly print the summary text.
NLP
print(summary[[1]]['summary_text'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 which is out of range.
Using a string as index which causes an error.
✗ Incorrect
The summarizer returns a list with one dictionary, so index 0 accesses the first summary.
4fill in blank
hardFill both blanks to create a dictionary comprehension that maps each sentence to its summary length.
NLP
sentences = ["AI is fun.", "It helps solve problems."] summary_lengths = {sentence: len(summary[[1]]['summary_text']) for sentence, summary in [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using enumerate instead of zip which gives wrong pairs.
Using index 1 which is out of range.
✗ Incorrect
Index 0 accesses the summary text in each summary dict. zip(sentences, summaries) pairs sentences with their summaries.
5fill in blank
hardFill all three blanks to generate summaries for multiple texts and print each summary.
NLP
texts = ["AI is amazing.", "It changes the world."] summaries = [summarizer([1], max_length=15, min_length=5, do_sample=False) for [2] in [3]] for summary in summaries: print(summary[0]['summary_text'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not defined in the loop.
Passing the whole list instead of each text.
✗ Incorrect
We loop over 'texts' with variable 'text' and summarize each text.