Skip to content

Instantly share code, notes, and snippets.

View hsleonis's full-sized avatar
🏝️
Travellers unite.

Hasan Shahriar hsleonis

🏝️
Travellers unite.
View GitHub Profile
@ashleyha
ashleyha / hf_helsinki-nlp_translation.py
Created December 16, 2020 17:57
example using the huggingface transformers library with the Helsinki-NLP/opus-mt-ru-en model
from transformers import MarianTokenizer, AutoModelForSeq2SeqLM
text = 'Рада познакомиться'
mname = 'Helsinki-NLP/opus-mt-ru-en'
tokenizer = MarianTokenizer.from_pretrained(mname)
model = AutoModelForSeq2SeqLM.from_pretrained(mname)
input_ids = tokenizer.encode(text, return_tensors="pt")
outputs = model.generate(input_ids)
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(decoded) #Nice to meet you