Complete the code to load a multilingual transformer model using Hugging Face Transformers.
from transformers import AutoModelForSequenceClassification model = AutoModelForSequenceClassification.from_pretrained('[1]')
The xlm-roberta-base model is a popular multilingual transformer model that supports many languages.
Complete the code to tokenize input text for a multilingual model.
from transformers import AutoTokenizer tokenizer = AutoTokenizer.from_pretrained('[1]') inputs = tokenizer('Hello world', return_tensors='pt')
The tokenizer must match the multilingual model, so xlm-roberta-base is correct.
Fix the error in the code to correctly predict with a multilingual model.
outputs = model(**[1]) predictions = outputs.logits.argmax(dim=1)
The model expects tokenized inputs, so passing inputs is correct.
Fill both blanks to create a dictionary comprehension that maps languages to their ISO codes.
language_codes = {lang[1]: lang[2] for lang in ['eng', 'fra', 'spa', 'deu']}Using [:3] slices the first three characters, which are the ISO codes.
Fill all three blanks to create a dictionary of language names and their token counts from a multilingual tokenizer.
token_counts = [1]([2]: len(tokenizer.tokenize([2])) for [3] in ['Hello', 'Bonjour', 'Hola'])
The dictionary is created with dict, and the loop variable is w used twice.