0
0
NLPml~10 mins

Summarization with Hugging Face in NLP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A"sentiment-analysis"
B"translation"
C"summarization"
D"text-generation"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong pipeline name like "translation" or "text-generation".
Forgetting to put the pipeline name in quotes.
2fill in blank
medium

Complete 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'
A"text"
Btext
Ctext[0]
Dsummary
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the string "text" instead of the variable text.
Passing summary or text[0] which are incorrect here.
3fill in blank
hard

Fix 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'
A0
B'summary_text'
C1
Dsummary
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 which is out of range.
Using a string as index which causes an error.
4fill in blank
hard

Fill 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'
A0
B1
Czip(sentences, summaries)
Denumerate(sentences)
Attempts:
3 left
💡 Hint
Common Mistakes
Using enumerate instead of zip which gives wrong pairs.
Using index 1 which is out of range.
5fill in blank
hard

Fill 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'
Atext
Ctexts
Dsentence
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not defined in the loop.
Passing the whole list instead of each text.