File size: 2,372 Bytes
067d594
 
 
7a0fb78
 
 
 
 
 
c9eebf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7a0fb78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7881886
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
{}
---
# Tradutor

A translation system from English to European Portuguese.

## Usage


### Using the pipeline


```python
from transformers import pipeline

translator = pipeline("text-generation", model="liaad/Tradutor")

text = "Hello, how are you?"
chat = [
        {
            "role": "system",
            "content": "You are a translator from English to European Portuguese",
    },
    {
        "role": "user",
        "content": f"Translate this text from English to European Portuguese: {text}",
    },
]

translated_text = translator(
    chat, 
    max_length=1024,
    pad_token_id=translator.model.config.eos_token_id  # Not necessary. Just to avoid warning.
)

print(translated_text[-1]["generated_text"][-1]["content"])
```

### Using model and tokenizer

```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer


model_name = "liaad/Tradutor"
max_length = 1024

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    device_map="auto",
    torch_dtype=torch.bfloat16,
)


text = "Hello, how are you?"
chat = [
    {
        "role": "system",
        "content": "You are a translator from English to European Portuguese",
    },
    {
        "role": "user",
        "content": f"Translate this text from English to European Portuguese: {text}",
    },
]

input_ids = tokenizer.apply_chat_template(
    chat,
    add_generation_prompt=True,
    tokenize=True,
    return_tensors="pt",
    max_length=max_length,
)

output_ids = model.generate(
    input_ids,
    max_length=max_length,
    num_return_sequences=1,
    pad_token_id=tokenizer.eos_token_id,
)

generated_ids = output_ids[0, input_ids.shape[1] :]
translated_text = tokenizer.decode(generated_ids, skip_special_tokens=True)

print(translated_text.strip())
```

## Citation

If you use this model in your work, please cite the following paper:

```
@article{Sousa2025,
  author    = {Hugo Sousa and Satya Almasian and Ricardo Campos and Alipio Jorge},
  title     = {Tradutor: Building a Variety Specific Translation Model},
  journal   = {Proceedings of the AAAI Conference on Artificial Intelligence},
  volume    = {39},
  number    = {24},
  pages     = {25183--25191},
  year      = {2025},
  doi       = {10.1609/aaai.v39i24.34704},
  issn      = {2374-3468},
  month     = {April}
}
```