Hint: Use 'translation_en_to_fr' for English to French translation [OK]
Common Mistakes:
Using wrong pipeline name
Confusing translation with image tasks
Calling text generation instead of translation
3. Given the following Python code using a translation model, what will be the output?
from transformers import pipeline
translator = pipeline('translation_en_to_de')
result = translator('Hello, how are you?')
print(result[0]['translation_text'])
medium
A. Ciao, come stai?
B. Bonjour, comment ça va?
C. Hallo, wie geht es dir?
D. Hola, ¿cómo estás?
Solution
Step 1: Identify the translation direction
The pipeline is 'translation_en_to_de', which means English to German translation.
Step 2: Translate the input text
'Hello, how are you?' translates to 'Hallo, wie geht es dir?' in German.
Final Answer:
Hallo, wie geht es dir? -> Option C
Quick Check:
English to German translation = Hallo, wie geht es dir? [OK]
Hint: Check language codes: en_to_de means English to German [OK]
Common Mistakes:
Choosing French or Spanish output
Ignoring language direction
Assuming output is same as input
4. You wrote this code to translate English to Spanish but get an error:
from transformers import pipeline
translator = pipeline('translation_en_to_es')
result = translator('Good morning')
print(result['translation_text'])
What is the error and how to fix it?
medium
A. Accessing result as dict instead of list; use result[0]['translation_text']
B. Wrong pipeline name; should be 'translation_en_to_fr'
C. Missing model download; add download=True parameter
D. print statement syntax error; use print result['translation_text']
Solution
Step 1: Understand the output format of pipeline
The pipeline returns a list of dicts, so result is a list, not a dict.
Step 2: Correct the access to translation text
Access the first element with result[0], then get 'translation_text' key.
Final Answer:
Accessing result as dict instead of list; use result[0]['translation_text'] -> Option A
Quick Check:
Pipeline output is list of dicts [OK]
Hint: Pipeline returns list; access first item before keys [OK]
Common Mistakes:
Treating output as dict directly
Using wrong pipeline name
Incorrect print syntax
5. You want to build a program that translates a list of English sentences to French and then back to English to check accuracy. Which approach is best?
hard
A. Translate sentences manually without AI models
B. Use two pipelines: 'translation_en_to_fr' then 'translation_fr_to_en' on each sentence
C. Use 'translation_en_to_de' pipeline followed by 'translation_de_to_en'
D. Use only 'translation_en_to_fr' pipeline twice on each sentence
Solution
Step 1: Identify correct translation directions
To translate English to French and back, use 'translation_en_to_fr' then 'translation_fr_to_en'.
Step 2: Avoid wrong language pairs
Using German pipelines or repeating the same pipeline won't give correct back translation.
Step 3: Manual translation is inefficient and error-prone
AI pipelines automate and improve accuracy checking.
Final Answer:
Use two pipelines: 'translation_en_to_fr' then 'translation_fr_to_en' on each sentence -> Option B
Quick Check:
Back translation needs correct language pairs [OK]
Hint: Use matching forward and backward pipelines for accuracy check [OK]