File size: 2,069 Bytes
69fca15 3fdc066 8700cdc 7ffe7cc a66e92f 69fca15 58f13b1 69fca15 58f13b1 69fca15 483c402 58f13b1 483c402 58f13b1 69fca15 58f13b1 69fca15 58f13b1 69fca15 58f13b1 483c402 58f13b1 69fca15 58f13b1 69fca15 58f13b1 69fca15 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
---
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] |