transformers safetensors mt5 text2text-generation seq2seq translation en it dataset:Helsinki-NLP/europarl dataset:Helsinki-NLP/opus-100 base_model:bigscience/mt0-small base_model:finetune:bigscience/mt0-small license:apache-2.0 autotrain_compatible endpoints_compatible region:us
---
base_model:
- bigscience/mt0-small
datasets:
- Helsinki-NLP/europarl
- Helsinki-NLP/opus-100
language:
- en
- it
library_name: transformers
license: apache-2.0
metrics:
- bleu
pipeline_tag: translation
tags:
- seq2seq
---

## 🍀 Quadrifoglio - A small model for Italian -> English translation

Quadrifoglio is an encoder-decoder transformer model for English-Italian text translation based on `bigscience/mt0-small`. It was trained on the `en-it` section of `Helsinki-NLP/opus-100` and `Helsinki-NLP/europarl`.


## Usage

```python
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# Load model and tokenizer from checkpoint directory
tokenizer = AutoTokenizer.from_pretrained("LeonardPuettmann/Quadrifoglio-mt-it-en")
model = AutoModelForSeq2SeqLM.from_pretrained("LeonardPuettmann/Quadrifoglio-mt-it-en")

def generate_response(input_text):
    input_ids = tokenizer("translate Italian to English:" + input_text, return_tensors="pt").input_ids
    output = model.generate(input_ids, max_new_tokens=256)
    return tokenizer.decode(output[0], skip_special_tokens=True)

text_to_translate = "Vorrei una tazza di tè nero, per favore."
response = generate_response(text_to_translate)
print(response)
```
As this model is trained on translating sentence pairs, it is best to split longer text into individual sentences, ideally using SpaCy. You can then translate the sentences and join the translations at the end like this:
```python
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import spacy
# First, install spaCy and the Italian language model if you haven't already
# !pip install spacy
# !python -m spacy download it_core_news_sm

nlp = spacy.load("it_core_news_sm")

tokenizer = AutoTokenizer.from_pretrained("LeonardPuettmann/Quadrifoglio-mt-it-en")
model = AutoModelForSeq2SeqLM.from_pretrained("LeonardPuettmann/Quadrifoglio-mt-it-en")

def generate_response(input_text):
    input_ids = tokenizer("translate Italian to English: " + input_text, return_tensors="pt").input_ids
    output = model.generate(input_ids, max_new_tokens=256)
    return tokenizer.decode(output[0], skip_special_tokens=True)

text = "Ciao, come stai? Oggi è una bella giornata. Spero che tu stia bene."
doc = nlp(text)
sentences = [sent.text for sent in doc.sents]

sentence_translations = []
for i, sentence in enumerate(sentences):
    sentence_translation = generate_response(sentence)
    sentence_translations.append(sentence_translation)

full_translation = " ".join(sentence_translations)
print(full_translation)
```

## Evaluation
Done on the Opus 100 test set.

### BLEU
|              | mt0-Quadrifoglio | mt0-small|
|--------------|------------------|----------|
| BLEU Score   | 0.4015           | 0.0159   |
| Precision 1  | 0.6987           | 0.2350   |
| Precision 2  | 0.4702           | 0.0290   |
| Precision 3  | 0.3443           | 0.0076   |
| Precision 4  | 0.2576           | 0.0013   |
