0
0
NLPml~10 mins

Abstractive summarization 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 a pretrained abstractive summarization model using Hugging Face Transformers.

NLP
from transformers import pipeline
summarizer = pipeline('[1]')
Drag options to blanks, or click blank then click option'
Asummarization
Btext-classification
Ctranslation
Dquestion-answering
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text-classification' instead of 'summarization'.
Confusing summarization with translation.
2fill in blank
medium

Complete the code to generate a summary from the input text using the summarizer pipeline.

NLP
text = "Machine learning helps computers learn from data."
summary = summarizer([1], max_length=30, min_length=5, do_sample=False)
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 a modified version of the text that changes meaning.
3fill in blank
hard

Fix the error in the code to correctly decode the generated summary tokens.

NLP
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

model_name = 'facebook/bart-large-cnn'
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

inputs = tokenizer('Deep learning is a subset of machine learning.', return_tensors='pt')
summary_ids = model.generate(inputs['input_ids'], max_length=20, num_beams=4, early_stopping=True)
summary = tokenizer.[1](summary_ids[0], skip_special_tokens=True)
Drag options to blanks, or click blank then click option'
Aconvert_tokens_to_ids
Bdecode
Cencode
Dtokenize
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'encode' which converts text to tokens.
Using 'tokenize' which splits text into tokens but does not decode.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.

NLP
words = ['data', 'AI', 'model', 'run']
lengths = { [1] : len([2]) for word in words if len(word) > 3 }
Drag options to blanks, or click blank then click option'
Aword
Bwords
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'words' instead of 'word' inside the comprehension.
Using a fixed string like 'data' instead of the loop variable.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each word in 'texts' to its uppercase form only if the word length is less than 5.

NLP
texts = ['AI', 'learn', 'code', 'data']
result = { [1] : [2] for [3] in texts if len([3]) < 5 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Bword
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Not applying the upper() method to the value.