Inference for TFMarianMTModel (en to Romance language translation) is slow and inaccurate
See original GitHub issueSystem Info
System macOS Monterey 12.2.1
transformers==4.20.1
tensorflow==2.9.1
Who can help?
No response
Information
- The official example scripts
- My own modified scripts
Tasks
- An officially supported task in the
examples
folder (such as GLUE/SQuAD, …) - My own task or dataset (give details below)
Reproduction
from transformers import TFMarianMTModel, MarianTokenizer
model_name = "Helsinki-NLP/opus-mt-en-ROMANCE"
tokenizer = MarianTokenizer.from_pretrained(model_name)
model = TFMarianMTModel.from_pretrained(model_name)
text_in = ['>>fr<< hello']
batch = tokenizer(text_in, return_tensors='tf', padding=True)
translated = model.generate(**batch)
Output:
- Qu'est-ce qu'il y a, là-bas, là-bas, là---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expected behavior
I would expect similar performance to the PyTorch model.
Inference requires about 120s on my machine and outputs an incorrect translation. In contrast, the PyTorch model (replacing TFMarianMTModel
with MarianMTModel
and changing return_tensors
to 'pt'
in the code snippet) returns the correct translation (“Bonjour”) and inference requires about 6s on my machine.
Issue Analytics
- State:
- Created a year ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
MarianMT - Hugging Face
The language codes used to name models are inconsistent. Two digit codes can usually be found here, three digit codes require googling “language...
Read more >AmericasNLI: Machine translation and natural language ...
To explore this question, we present AmericasNLI, a natural language inference dataset covering 10 Indigenous languages of the Americas. We conduct experiments ...
Read more >Text Data Augmentation with MarianMT - Amit Chaudhary
Next, we write a helper function to translate a batch of text given the machine translation model, tokenizer and the target romance language....
Read more >Translate Any Two Languages in 60 Lines of Python
All that was to translate one language to one other language. ... the tokenizer model = MarianMTModel.from_pretrained(model_name) tokenizer ...
Read more >Hugging Face Pre-trained Models: Find the Best One for Your ...
It is the task of translating a text from one language to another. ... Learning and a lot of research has been done...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi there @ydshieh @danielenricocahall 👋
None of the Marian models can be successfully converted to TF – they all fail when validating the hidden layers and outputs of the models. This is a shame since there are a ton of Marian models for translation 😦
This means there is something wrong with either the model architecture or with weight cross-loading. I haven’t looked into it, other than noticing the issue when attempting to convert the weights from
Helsinki-NLP
@ydshieh Hi, I am experiencing the same issue. Expected the TF version would be faster than the PT version.