Quark-50m-v2 / README.md
ThingsAI's picture
Quark-50M-v2: 43.8M Italian-first LM (loss 0.9409551193519028)
52135a8 verified
|
Raw
History Blame Contribute Delete
4.21 kB
---
language:
- it
- en
license: apache-2.0
tags:
- italian
- causal-lm
- small-language-model
- trained-from-scratch
- chatml
- conversational
pipeline_tag: text-generation
---
# βš› Quark-50M-v2
**43.8M parameter Italian-first bilingual language model, trained from scratch by ThingAI.**
Quark-50M is an ultra-compact causal language model that speaks fluent Italian. Designed as a proof-of-concept for small, efficient, Italian-centric AI.
## Highlights
- **43.8M parameters** β€” runs on any device, even CPU
- **Italian-first** β€” trained on 60% Italian data (books, Wikipedia, web)
- **ChatML format** β€” `<|im_start|>user`/`<|im_start|>assistant`
- **Custom tokenizer** β€” 16k BPE, optimized for Italian (4.15 chars/token)
- **Trained from scratch** β€” architecture, tokenizer, and training pipeline all custom
## Architecture
| Component | Value |
|-----------|-------|
| Parameters | 43.8M |
| Vocabulary | 16,384 (BPE) |
| Dimensions | 512 |
| Layers | 12 |
| Heads | 8 (4 KV heads, GQA) |
| FFN | 1,408 (SwiGLU) |
| Context | 2,048 tokens |
| Normalization | RMSNorm |
| Position | RoPE |
| Weight Tying | Yes |
## Training
**Pretraining:** 5B tokens on a curated mix:
| Dataset | Weight | Type |
|---------|--------|------|
| PleIAs/Italian-PD | 25% | 171K Italian books (public domain) |
| FineWeb-2 Italian | 20% | Cleaned, deduplicated web |
| Wikipedia IT | 15% | Encyclopedia |
| Cosmopedia | 15% | Synthetic educational |
| SmolLM-Corpus | 10% | Curated mix |
| StarCoder Python | 8% | Code |
| OpenWebMath | 7% | Mathematics |
**SFT:** Fine-tuned on [quattro-chiacchiere](https://huggingface.co/datasets/ThingAI/quattro-chiacchiere), a synthetic Italian Q&A dataset generated with [Alembic](https://github.com/skein-labs/Alembic).
## Usage
```python
import torch
from huggingface_hub import hf_hub_download
from transformers import PreTrainedTokenizerFast
# Load
ckpt_path = hf_hub_download("ThingAI/Quark-50M", "model.pt")
model_py = hf_hub_download("ThingAI/Quark-50M", "model.py")
tok_file = hf_hub_download("ThingAI/Quark-50M", "tokenizer.json")
# Tokenizer
tokenizer = PreTrainedTokenizerFast(tokenizer_file=tok_file)
tokenizer.eos_token = "<|endoftext|>"
# Model
import importlib.util
spec = importlib.util.spec_from_file_location("model", model_py)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
ckpt = torch.load(ckpt_path, map_location="cpu", weights_only=False)
cfg = mod.ModelConfig(**ckpt["model_cfg"])
model = mod.Quark(cfg).eval()
model.load_state_dict(ckpt["model"])
# Chat
prompt = "<|im_start|>user\nQual Γ¨ la capitale d'Italia?<|im_end|>\n<|im_start|>assistant\n"
ids = tokenizer.encode(prompt, return_tensors="pt")
with torch.no_grad():
for _ in range(100):
logits = model(ids)[1][:, -1, :].float()
nxt = logits.argmax(-1, keepdim=True)
if nxt.item() == tokenizer.convert_tokens_to_ids("<|im_end|>"): break
ids = torch.cat([ids, nxt], -1)
print(tokenizer.decode(ids[0], skip_special_tokens=True))
# La capitale d'Italia Γ¨ Roma.
```
## Examples
```
Tu: Qual Γ¨ la capitale d'Italia?
Quark: La capitale d'Italia Γ¨ Roma.
Tu: Chi sei?
Quark: Sono Quark, piacere di conoscerti.
Tu: Come ti chiami?
Quark: Mi chiamo Quark, piacere di conoscerti.
```
## Limitations
- **43.8M parameters** β€” cannot perform complex reasoning or long-form generation
- **Factual accuracy** β€” may hallucinate facts, especially on niche topics
- **SFT dataset** β€” currently limited; more data will improve reliability
- **No safety training** β€” not recommended for production without guardrails
## Related
- [Quark3Tokenizer](https://huggingface.co/ThingAI/Quark3Tokenizer) β€” the tokenizer
- [quattro-chiacchiere](https://huggingface.co/datasets/ThingAI/quattro-chiacchiere) β€” the SFT dataset
- [Alembic](https://github.com/skein-labs/Alembic) β€” the dataset distillation tool
- [Glyph](https://huggingface.co/ThingAI/Glyph) β€” multi-task text classifier by ThingAI
## Citation
```bibtex
@misc{quark50m,
author = {ThingAI},
title = {Quark-50M-v2: Italian-First Small Language Model},
year = {2026},
url = {https://huggingface.co/ThingAI/Quark-50M}
}
```
## License
Apache 2.0