|
|
--- |
|
|
library_name: transformers |
|
|
tags: [] |
|
|
--- |
|
|
|
|
|
# Model Card for Model ID |
|
|
|
|
|
This model is a translator into Lithuanian and vice versa. |
|
|
It was trained on the following datasets: |
|
|
* [ted_talks_iwslt](https://huggingface.co/datasets/IWSLT/ted_talks_iwslt) |
|
|
* [werent4/lithuanian-translations](https://huggingface.co/datasets/werent4/lithuanian-translations) |
|
|
* [scoris/en-lt-merged-data](https://huggingface.co/datasets/scoris/en-lt-merged-data) |
|
|
|
|
|
|
|
|
|
|
|
## Model Usage |
|
|
```Python |
|
|
import torch |
|
|
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") |
|
|
|
|
|
from transformers import T5Tokenizer, MT5ForConditionalGeneration |
|
|
|
|
|
tokenizer = T5Tokenizer.from_pretrained('werent4/mt5TranslatorLT') |
|
|
model = MT5ForConditionalGeneration.from_pretrained("werent4/mt5TranslatorLT") |
|
|
model.to(device) |
|
|
def translate(text, model, tokenizer, device, translation_way = "en-lt"): |
|
|
translations_ways = { |
|
|
"en-lt": "<EN2LT>", |
|
|
"lt-en": "<LT2EN>" |
|
|
} |
|
|
if translation_way not in translations_ways: |
|
|
raise ValueError(f"Invalid translation way. Supported ways: {list(translations_ways.keys())}") |
|
|
input_text = f"{translations_ways[translation_way]} {text}" |
|
|
encoded_input = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True, max_length=128).to(device) |
|
|
with torch.no_grad(): |
|
|
output_tokens = model.generate( |
|
|
**encoded_input, |
|
|
max_length=128, |
|
|
num_beams=5, |
|
|
no_repeat_ngram_size=2, |
|
|
early_stopping=True |
|
|
) |
|
|
|
|
|
translated_text = tokenizer.decode(output_tokens[0], skip_special_tokens=True) |
|
|
return translated_text |
|
|
|
|
|
text = "How are you?" |
|
|
translate(text, model, tokenizer, device) |
|
|
`Kaip esate?` |
|
|
|
|
|
text = "I live in Kaunas" |
|
|
translate(text, model, tokenizer, device) |
|
|
`Aš gyvenu Kaunas` |
|
|
|
|
|
text = "Mano vardas yra Karolis" |
|
|
translate(text, model, tokenizer, device, translation_way= "lt-en") |
|
|
`My name is Karolis` |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
## Model Card Authors |
|
|
|
|
|
[werent4](https://huggingface.co/werent4) |
|
|
[Mykhailo Shtopko](https://huggingface.co/BioMike) |
|
|
|
|
|
## Model Card Contact |
|
|
|
|
|
[More Information Needed] |