0
0
NLPml~10 mins

Translation with Hugging Face 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 the translation pipeline from Hugging Face.

NLP
from transformers import pipeline
translator = pipeline([1])
Drag options to blanks, or click blank then click option'
A"translation_en_to_de"
B"sentiment-analysis"
C"translation_en_to_es"
D"translation_en_to_fr"
Attempts:
3 left
💡 Hint
Common Mistakes
Using sentiment-analysis instead of a translation pipeline.
Choosing the wrong target language code.
2fill in blank
medium

Complete the code to translate the English sentence to German using the pipeline.

NLP
result = translator([1])
print(result[0]['translation_text'])
Drag options to blanks, or click blank then click option'
A"Hello, how are you?"
BHello, how are you?
C'Hello, how are you?'
D['Hello, how are you?']
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the sentence without quotes causing a syntax error.
Passing a list instead of a string.
3fill in blank
hard

Fix the error in the code to correctly translate the sentence.

NLP
from transformers import pipeline
translator = pipeline("translation_en_to_de")
result = translator([1])
print(result[0]['translation_text'])
Drag options to blanks, or click blank then click option'
A"Good morning"
BGood morning
C'Good morning'
D[Good morning]
Attempts:
3 left
💡 Hint
Common Mistakes
Passing unquoted text causing NameError.
Passing a list instead of a string.
4fill in blank
hard

Fill both blanks to create a translation pipeline from English to French and translate a sentence.

NLP
from transformers import pipeline
translator = pipeline([1])
result = translator([2])
print(result[0]['translation_text'])
Drag options to blanks, or click blank then click option'
A"translation_en_to_fr"
B"translation_en_to_de"
C"Hello, how are you?"
D"Good evening"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong pipeline name.
Passing input without quotes.
5fill in blank
hard

Fill all three blanks to translate a list of English sentences to Spanish and print each translation.

NLP
from transformers import pipeline
translator = pipeline([1])
sentences = ["Hello", "Good night", "Thank you"]
translations = [translator([2])[0]['translation_text'] for [3] in sentences]
for t in translations:
    print(t)
Drag options to blanks, or click blank then click option'
A"translation_en_to_es"
Bsentence
C"sentence"
Dsent
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the string "sentence" instead of the variable sentence.
Using a different loop variable than the one passed to translator.