0
0
NLPml~10 mins

Language modeling concept 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 pre-trained language model using Hugging Face Transformers.

NLP
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained([1])
Drag options to blanks, or click blank then click option'
A"bert-base-uncased"
B"gpt2"
C"resnet50"
D"vgg16"
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing BERT which is not a causal language model.
Selecting image models like ResNet or VGG.
2fill in blank
medium

Complete the code to tokenize input text for the language model.

NLP
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("gpt2")
inputs = tokenizer([1], return_tensors="pt")
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 instead of a string.
Passing a number or None.
3fill in blank
hard

Fix the error in the code to generate text from the model.

NLP
outputs = model.generate([1])
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Drag options to blanks, or click blank then click option'
Ainputs
Binputs['token_type_ids']
Cinputs['attention_mask']
Dinputs['input_ids']
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the entire inputs dictionary instead of input_ids.
Passing attention_mask or token_type_ids instead of input_ids.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

NLP
word_lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Clen(word) > 3
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Checking if the word string is greater than 3 instead of length.
5fill in blank
hard

Fill all three blanks to create a filtered dictionary of words with length greater than 4 and convert keys to uppercase.

NLP
filtered = [1]: [2] for [3] in words if len([3]) > 4}
Drag options to blanks, or click blank then click option'
Aword.upper()
Bword
Dlen(word)
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Not converting keys to uppercase.