0
0
NLPml~10 mins

Why translation breaks language barriers in NLP - Test Your Understanding

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 translation model from Hugging Face.

NLP
from transformers import MarianMTModel, MarianTokenizer
model_name = 'Helsinki-NLP/opus-mt-en-de'
tokenizer = MarianTokenizer.from_pretrained([1])
Drag options to blanks, or click blank then click option'
A'Helsinki-NLP/opus-mt-en-de'
B'bert-base-uncased'
C'facebook/wav2vec2-base-960h'
D'gpt2'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a language model like 'bert-base-uncased' instead of a translation model.
Confusing speech models with translation models.
2fill in blank
medium

Complete the code to tokenize the input text for translation.

NLP
text = 'Hello, how are you?'
tokenized = tokenizer([1], return_tensors='pt', padding=True)
Drag options to blanks, or click blank then click option'
Atokenizer
B'Hello, how are you?'
C['Hello', 'how', 'are', 'you']
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a list of words instead of a string.
Passing the tokenizer object instead of the text.
3fill in blank
hard

Fix the error in generating the translated tokens.

NLP
translated_tokens = model.generate([1].input_ids, max_length=40)
Drag options to blanks, or click blank then click option'
Atext
Btokenized
Cmodel
Dtokenizer
Attempts:
3 left
💡 Hint
Common Mistakes
Passing raw text instead of token IDs.
Passing the tokenizer or model object instead of token IDs.
4fill in blank
hard

Fill both blanks to decode the translated tokens into readable text.

NLP
translated_text = tokenizer.[1](translated_tokens[0], skip_special_tokens=[2])
Drag options to blanks, or click blank then click option'
Adecode
BTrue
CFalse
Dencode
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'encode' instead of 'decode'.
Not skipping special tokens, resulting in unwanted symbols.
5fill in blank
hard

Fill all three blanks to create a function that translates English text to German.

NLP
def translate_en_to_de(text):
    inputs = tokenizer(text, return_tensors=[1], padding=True)
    outputs = model.generate(inputs.[2], max_length=50)
    return tokenizer.[3](outputs[0], skip_special_tokens=True)
Drag options to blanks, or click blank then click option'
A'pt'
Binput_ids
Cdecode
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text' instead of 'input_ids' for model input.
Returning tokens without decoding.
Using wrong tensor type like 'tf' instead of 'pt'.