Edit model card

Model Card for Model ID

This model is a translator into Lithuanian and vice versa. It was trained on the following datasets:

Model Usage

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
Mykhailo Shtopko

Model Card Contact

[More Information Needed]

Downloads last month
4
Safetensors
Model size
300M params
Tensor type
F32
·
Inference Examples
This model does not have enough activity to be deployed to Inference API (serverless) yet. Increase its social visibility and check back later, or deploy to Inference Endpoints (dedicated) instead.

Space using werent4/mt5TranslatorLT 1