0
0
NLPml~10 mins

NLP applications in real world - 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 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'
A'translation'
B'text-classification'
C'image-classification'
D'speech-recognition'
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.
2fill in blank
medium

Complete 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'
A'Hello, how are you?'
B12345
C['Hello', 'how', 'are', 'you']
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a list of words instead of a string.
Passing a number instead of text.
3fill in blank
hard

Fix 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'
A'Apple is a company'
B['Apple', 'is', 'a', 'company']
C123
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a list of words instead of a string.
Passing a number or None instead of text.
4fill in blank
hard

Fill 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'
Alen(word)
B<
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using '<' instead of '>' in the condition.
5fill in blank
hard

Fill 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'
Aword.upper()
Bfreq
Cword
Dfreq.upper()
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'.