Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load a pre-trained sentiment analysis model using Hugging Face Transformers.
NLP
from transformers import pipeline sentiment_analyzer = pipeline([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing pipelines unrelated to text classification like 'image-classification'.
Using pipeline names meant for other modalities like speech or translation.
✗ Incorrect
The 'text-classification' pipeline is used for sentiment analysis tasks in NLP.
2fill in blank
mediumComplete the code to tokenize input text for a BERT model.
NLP
from transformers import BertTokenizer tokenizer = BertTokenizer.from_pretrained('bert-base-uncased') tokens = tokenizer.tokenize([1])
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 a number instead of text.
✗ Incorrect
The tokenizer.tokenize method expects a string input representing the text to tokenize.
3fill in blank
hardFix the error in the code to correctly perform named entity recognition (NER) using a Hugging Face pipeline.
NLP
from transformers import pipeline ner_pipeline = pipeline('ner') results = ner_pipeline([1])
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 a number or None instead of text.
✗ Incorrect
The NER pipeline expects a string input representing the sentence to analyze.
4fill in blank
hardFill both blanks to create a dictionary comprehension that maps words to their lengths only if the length is greater than 3.
NLP
{word: [1] for word in words if len(word) [2] 3} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using '<' instead of '>' in the condition.
✗ Incorrect
We want the dictionary to map each word to its length, but only include words longer than 3 characters.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps uppercase words to their frequencies only if frequency is greater than 1.
NLP
{ [1]: [2] for [3], freq in word_freq.items() if freq > 1 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using freq.upper() which is invalid since freq is a number.
Using 'freq' as the loop variable instead of 'word'.
✗ Incorrect
The keys are uppercase words, values are frequencies, and the loop variable is 'word'.