Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load the summarization pipeline from Hugging Face Transformers.
Prompt Engineering / GenAI
from transformers import pipeline summarizer = pipeline([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'translation' instead of 'summarization'.
Using 'text-generation' which creates new text, not summaries.
✗ Incorrect
The pipeline type for text summarization is "summarization".
2fill in blank
mediumComplete the code to summarize the input text using the summarizer pipeline.
Prompt Engineering / GenAI
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 a list of words instead of a string.
Passing an uppercase or lowercase transformed string unnecessarily.
✗ Incorrect
The summarizer expects a string input, so passing 'text' directly is correct.
3fill in blank
hardFix the error in the code to correctly get the summary text from the output.
Prompt Engineering / GenAI
result = summarizer(text, max_length=30, min_length=10, do_sample=False) summary_text = result[1] print(summary_text)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to access 'summary_text' directly from the list.
Using wrong keys like 'text' instead of 'summary_text'.
✗ Incorrect
The summarizer returns a list with one dict; access the first item and then the 'summary_text' key.
4fill in blank
hardFill both blanks to create a dictionary comprehension that maps each sentence to its summary length.
Prompt Engineering / GenAI
sentences = ["AI is fascinating.", "It can learn patterns.", "Summarization helps understand text."] summary_lengths = {sentence: len(summarizer(sentence, max_length=10, min_length=5, do_sample=False)[1]) for sentence in sentences if len(sentence) [2] 10} print(summary_lengths)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '[0]' only returns a dict, not the text string.
Using '<' instead of '>' in the filter condition.
✗ Incorrect
Access the summary text with [0]['summary_text'] and filter sentences longer than 10 characters.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps each sentence's uppercase form to its summary.
Prompt Engineering / GenAI
sentences = ["AI is cool.", "It learns fast.", "Summarization is useful."] summary_info = [1]: [2] for s in sentences if len(s) [3] 8 print(summary_info)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using s instead of s.upper() as key.
Using '<' instead of '>' in the filter condition.
✗ Incorrect
Use s.upper() as key, summary text as value, and filter sentences longer than 8 characters.