Views
No views yet
torch.optim.AdamW (cosine learning rate scheduler with 100 warmup steps)1from transformers import AutoTokenizer, AutoModelForCausalLM
2import json_repair # Make sure to install this package if you haven't already
3import torch
4
5device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
6
7tokenizer = AutoTokenizer.from_pretrained("Polygl0t/portuguese-qwen3-4b-instruct-quality-judge")
8model = AutoModelForCausalLM.from_pretrained("Polygl0t/portuguese-qwen3-4b-instruct-quality-judge")
9model.to(device)
10
11good_messages = [
12 {
13 "role": "user",
14 "content": "Qual é a capital de Portugal?"
15 },
16 {
17 "role": "assistant",
18 "content": "A capital de Portugal é Lisboa."
19 }
20]
21
22bad_messages = [
23 {
24 "role": "user",
25 "content": "Qual é a capital de Portugal?"
26 },
27 {
28 "role": "assistant",
29 "content": "Minha cor favorita é azul."
30 }
31]
32
33for message in [good_messages, bad_messages]:
34 text = tokenizer.apply_chat_template(
35 message,
36 tokenize=False,
37 add_generation_prompt=True,
38 tools=None,
39 # The chat template can handle tools, but we don't use them in this case.
40 )
41
42 # This model was fine-tuned with sequences up to 6032 tokens long
43 inputs = tokenizer([text], return_tensors="pt").to(device)
44 generated_ids = model.generate(
45 **inputs,
46 max_new_tokens=250,
47 )
48 output_ids = generated_ids[0][inputs["input_ids"].shape[1]:]
49 output = tokenizer.decode(output_ids, skip_special_tokens=True)
50 # `json_repair` allows us to safely parse the JSON output, turning it into a Python dictionary. But you can also manually parse the output if you prefer.
51 decoded_output = json_repair.loads(output)
52
53 print(
54 {
55 "input": message,
56 "int_score": decoded_output.get("score", None),
57 "justification": decoded_output.get("reason", None)
58 }
59 )1@misc{correa2026tucano2cool,
2 title={{Tucano 2 Cool: Better Open Source LLMs for Portuguese}},
3 author={Nicholas Kluge Corr{\^e}a and Aniket Sen and Shiza Fatimah and Sophia Falk and Lennard Landgraf and Julia Kastner and Lucie Flek},
4 year={2026},
5 eprint={2603.03543},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2603.03543},
9}