0
0
NLPml~20 mins

Translation with Hugging Face in NLP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Translation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of Hugging Face Translation Pipeline
What is the output of this code snippet that translates English to French using Hugging Face?
NLP
from transformers import pipeline
translator = pipeline('translation_en_to_fr')
result = translator('Hello, how are you?', max_length=40)
print(result)
A[{'translation_text': 'Bonjour, comment allez-vous ?'}]
B[{'translation_text': 'Salut, comment Γͺtes-vous ?'}]
C[{'translation_text': 'Hello, comment Γ§a va ?'}]
D[{'translation_text': 'Bonjour, comment Γͺtes-vous ?'}]
Attempts:
2 left
πŸ’‘ Hint
Look for the most natural French translation of 'Hello, how are you?'.
❓ Model Choice
intermediate
1:30remaining
Choosing the Correct Model for English to German Translation
Which Hugging Face model is best suited for translating English text to German?
Aroberta-base
BHelsinki-NLP/opus-mt-en-de
Cgpt2
Dbert-base-uncased
Attempts:
2 left
πŸ’‘ Hint
Look for a model specifically trained for translation between English and German.
❓ Hyperparameter
advanced
1:30remaining
Effect of max_length in Translation Pipeline
What happens if you set max_length too low in the Hugging Face translation pipeline?
AThe translation will be more accurate and detailed.
BThe model will generate longer translations than usual.
CThe translation output may be cut off and incomplete.
DThe pipeline will raise a runtime error.
Attempts:
2 left
πŸ’‘ Hint
Think about what max_length controls in text generation.
❓ Metrics
advanced
1:30remaining
Evaluating Translation Quality
Which metric is commonly used to evaluate the quality of machine translation outputs?
ABLEU score
BMean Squared Error
CAccuracy
DF1 Score
Attempts:
2 left
πŸ’‘ Hint
This metric compares n-grams between the candidate and reference translations.
πŸ”§ Debug
expert
2:30remaining
Debugging Translation Pipeline Error
What error will this code raise and why? from transformers import pipeline translator = pipeline('translation_en_to_fr') result = translator(['Hello', 'Goodbye'], max_length=40) print(result)
NLP
from transformers import pipeline
translator = pipeline('translation_en_to_fr')
result = translator(['Hello', 'Goodbye'], max_length=40)
print(result)
ATypeError: pipeline() argument must be a string, not list
BValueError: Batch input not supported for this pipeline
CTypeError: 'list' object is not callable
DNo error; outputs a list of translations
Attempts:
2 left
πŸ’‘ Hint
Check if the translation pipeline supports batch input as a list.