0
0
Prompt Engineering / GenAIml~10 mins

Summarization in Prompt Engineering / GenAI - 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 Transformers.

Prompt Engineering / GenAI
from transformers import pipeline
summarizer = pipeline([1])
Drag options to blanks, or click blank then click option'
A"text-generation"
B"sentiment-analysis"
C"summarization"
D"translation"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'translation' instead of 'summarization'.
Using 'text-generation' which creates new text, not summaries.
2fill in blank
medium

Complete 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'
Atext
Btext.split()
Ctext.lower()
Dtext.upper()
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a list of words instead of a string.
Passing an uppercase or lowercase transformed string unnecessarily.
3fill in blank
hard

Fix 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'
A[0]
B['summary_text']
C['text']
D[0]['summary_text']
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to access 'summary_text' directly from the list.
Using wrong keys like 'text' instead of 'summary_text'.
4fill in blank
hard

Fill 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'
A[0]['summary_text']
B>
C<
D[0]
Attempts:
3 left
💡 Hint
Common Mistakes
Using '[0]' only returns a dict, not the text string.
Using '<' instead of '>' in the filter condition.
5fill in blank
hard

Fill 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'
As.upper()
Bsummarizer(s, max_length=15, min_length=5, do_sample=False)[0]['summary_text']
C>
Dlen(s)
Attempts:
3 left
💡 Hint
Common Mistakes
Using s instead of s.upper() as key.
Using '<' instead of '>' in the filter condition.