0
0
NLPml~10 mins

Multilingual models 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 multilingual transformer model using Hugging Face Transformers.

NLP
from transformers import AutoModelForSequenceClassification
model = AutoModelForSequenceClassification.from_pretrained('[1]')
Drag options to blanks, or click blank then click option'
Agpt2
Bbert-base-uncased
Cxlm-roberta-base
Ddistilbert-base-uncased
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a monolingual model like bert-base-uncased.
2fill in blank
medium

Complete the code to tokenize input text for a multilingual model.

NLP
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained('[1]')
inputs = tokenizer('Hello world', return_tensors='pt')
Drag options to blanks, or click blank then click option'
Abert-base-cased
Bxlm-roberta-base
Croberta-base
Dgpt2
Attempts:
3 left
💡 Hint
Common Mistakes
Using a tokenizer for a different model causes errors.
3fill in blank
hard

Fix the error in the code to correctly predict with a multilingual model.

NLP
outputs = model(**[1])
predictions = outputs.logits.argmax(dim=1)
Drag options to blanks, or click blank then click option'
Ainputs
Btokenizer
Ctext
Dlabels
Attempts:
3 left
💡 Hint
Common Mistakes
Passing raw text or tokenizer object instead of tokenized inputs.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps languages to their ISO codes.

NLP
language_codes = {lang[1]: lang[2] for lang in ['eng', 'fra', 'spa', 'deu']}
Drag options to blanks, or click blank then click option'
A[:]
B[::]
C[:3]
D[3:]
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect slice like [3:] which gets characters after index 3.
5fill in blank
hard

Fill all three blanks to create a dictionary of language names and their token counts from a multilingual tokenizer.

NLP
token_counts = [1]([2]: len(tokenizer.tokenize([2])) for [3] in ['Hello', 'Bonjour', 'Hola'])
Drag options to blanks, or click blank then click option'
Adict
Bword
Cw
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.