Instructions to use Helsinki-NLP/opus-mt-sv-en with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Helsinki-NLP/opus-mt-sv-en with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "translation" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # 'pip install "transformers<5.0.0' from transformers import pipeline pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-sv-en")# Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-sv-en") model = AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-sv-en", device_map="auto") - Inference
- Notebooks
- Google Colab
- Kaggle
Wrong generations on empty strings
#3
by Alealejandrooo - opened
The model will output:
["I'm sorry. I'm sorry. I'm sorry."]
when prompted on an empty string:
Code to reproduce the error:
'''from transformers import MarianTokenizer, AutoModelForSeq2SeqLM
name = "Helsinki-NLP/opus-mt-sv-en"
model = AutoModelForSeq2SeqLM.from_pretrained(name)
tokenizer = MarianTokenizer.from_pretrained(name)
inputs = tokenizer(" ", padding=True, truncation=True, return_tensors="pt")
translated_outputs = model.generate(**inputs)
translations = [tokenizer.decode(output, skip_special_tokens=True) for output in translated_outputs]'''
Anyone having the same issue and possibly a solution to fix it?
Thanks!