File size: 4,483 Bytes
9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 9fb41e6 1910046 | 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | ---
language:
- en
- it
license: apache-2.0
tags:
- tokenizer
- bpe
- bilingual
- italian
- english
- quark
model_type: quark
vocab_size: 65536
---
# Quark Tokenizer
Tokenizer BPE byte-level bilingue **EN + IT** sviluppato per la famiglia di modelli **Quark** di [OvercastLab / ThingAI](https://huggingface.co/ThingAI).
## Caratteristiche
| Proprietà | Valore |
|---|---|
| Algoritmo | Byte-Level BPE |
| Vocab size | 65.536 (2¹⁶) |
| Lingue | Inglese + Italiano |
| Special tokens | 64 |
| Context length | 2048 (estendibile) |
| Compatibilità | 🤗 `transformers`, `tokenizers` |
# Corpus di addestramento
Il tokenizer è stato addestrato su ~14M righe bilanciate EN/IT (50%/50%) provenienti da:
| Dataset | Lingua | Righe |
|---|---|---|
| Wikipedia EN | EN | 3.000.000 |
| Pile Uncopyrighted | EN | 2.000.000 |
| Falcon RefinedWeb | EN | 2.000.000 |
| Wikipedia IT | IT | 3.000.000 |
| FineWeb-2 (`ita_Latn`) | IT | 2.000.000 |
| MADLAD-400 IT | IT | 1.500.000 |
La parità EN/IT è una scelta deliberata: i tokenizer addestrati prevalentemente su inglese tendono a usare 2–3× più token per rappresentare testi italiani. Questo tokenizer è ottimizzato per entrambe le lingue.
# Special Tokens
```
<unk> → unknown
<s> → inizio sequenza (BOS) — id: 1
</s> → fine sequenza (EOS) — id: 2
<pad> → padding
<|system|> → turno system
<|user|> → turno user
<|assistant|> → turno assistant
<|endofturn|> → fine turno esplicito
<|thinking|> → inizio ragionamento (chain-of-thought)
<|/thinking|> → fine ragionamento
<|reserved_0|> … <|reserved_53|> → slot riservati (tool use, multimodale, ecc.)
```
Totale: **64 special tokens**
# Chat Template
Il tokenizer include un chat template compatibile con `apply_chat_template`:
```python
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("ThingAI/QuarkTokenizer")
messages = [
{"role": "system", "content": "Sei Quark, un assistente AI creato da OvercastLab."},
{"role": "user", "content": "Cos'è la derivata di una funzione?"},
{"role": "assistant", "content": "La derivata misura la variazione istantanea..."},
]
text = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
print(text)
```
## Uso base
```python
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("ThingAI/quark-tokenizer")
# Encoding
text = "Il cielo è azzurro e il sole splende."
ids = tok.encode(text)
print(f"Token: {len(ids)}") # ~9 token
# Decoding
decoded = tok.decode(ids, skip_special_tokens=True)
print(decoded)
# Batch
batch = tok(["Hello world!", "Ciao mondo!"], padding=True, return_tensors="pt")
```
## Integrazione con modelli Quark
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
tok = AutoTokenizer.from_pretrained("ThingAI/QuarkTokenizer")
model = AutoModelForCausalLM.from_pretrained("ThingAI/Quark-135M")
inputs = tok("La matematica è", return_tensors="pt")
output = model.generate(**inputs, max_new_tokens=50)
print(tok.decode(output[0], skip_special_tokens=True))
```
## Design Choices
**Perché 65.536?**
È una potenza di 2 (2¹⁶), ottimale per operazioni hardware su GPU/TPU. Più grande di GPT-2 (50.257) e LLaMA-2 (32.000), ma più compatto di LLaMA-3 (128.256). Bilancia efficienza di rappresentazione e dimensione dell'embedding layer.
**Perché Byte-Level BPE?**
Garantisce copertura completa di qualsiasi sequenza UTF-8 senza token `<unk>`. Robustezza su emoji, caratteri accentati italiani (à, è, ì, ò, ù), simboli matematici e codice sorgente.
**Perché 50% italiano?**
I tokenizer standard (GPT-2, LLaMA) sono addestrati su corpus predominantemente inglesi e penalizzano le lingue latine con un overhead di 2–3× nel numero di token. Il bilanciamento 50/50 elimina questa disparità per l'italiano mantenendo piena competenza in inglese.
## Famiglia Quark
| Modello | Parametri | Token pretraining | Stato |
|---|---|---|---|
| Quark-135M v1 | 135M | 15B | ✅ Rilasciato |
| Quark-135M v2 | 135M | 65B | 🔄 In training |
## Licenza
Apache 2.0 — uso libero anche commerciale.
## Citazione
```bibtex
@misc{quark2025,
title = {Quark: A Bilingual EN/IT Language Model},
author = {OvercastLab / ThingAI},
year = {2025},
url = {https://huggingface.co/ThingAI/quark-tokenizer}
}
```
---
*Sviluppato da [OvercastLab](https://things-ai.org) · Made in Italy 🇮🇹* |