tiny-arabic-olmo2 / README.md
yahya-ai10's picture
Update README.md
a5bc994 verified
|
Raw History Blame Contribute Delete
2.87 kB
---
language:
- ar
license: apache-2.0
library_name: olmo-core
tags:
- olmo
- olmo-core
- pretraining
- arabic
- from-scratch
- student-project
datasets:
- wikimedia/wikipedia
pipeline_tag: text-generation
---
# Tiny Arabic OLMo-2 (olmo2_30M architecture, 11.8M parameters)
A very small language model **pre-trained from scratch on Arabic Wikipedia** with [OLMo-core](https://github.com/allenai/OLMo-core), AI2's open training library.
It is a **learning project**: it writes Arabic-looking sentences, but its facts are not reliable.
- **Author:** Yahya Majrashi ([LinkedIn](https://www.linkedin.com/in/yahya-majrashi-756974291/))
- **Course:** Generative AI, Data Science and AI Diploma, Tuwaiq Academy
## Model
| | |
|---|---|
| Architecture | OLMo-2 (`TransformerConfig.olmo2_30M`): d_model 256, 4 layers, 8 heads, RoPE, RMSNorm, SwiGLU, QK-norm |
| Parameters | 11.8M (7.6M without embeddings) |
| Tokenizer | own byte-level BPE, 16,384 tokens, trained on the same Arabic articles (`tokenizer.json`) |
| Context length | 256 tokens |
## Training
| | |
|---|---|
| Data | `wikimedia/wikipedia`, config `20231101.ar`: first 20,000 articles longer than 500 characters (40.6M tokens) |
| Steps / tokens | 1,000 steps × 16,384 tokens = 16.4M tokens (≈0.4 epochs) |
| Optimizer | AdamW, lr 1e-3, 100 warmup steps + cosine, grad clip 1.0, no weight decay on embeddings |
| Hardware | 1× Colab T4, fp32, about 6 minutes |
## Results (300 held-out Arabic Wikipedia articles)
| Model (same size, same data) | Val loss | Perplexity |
|---|---|---|
| Plain PyTorch GPT baseline | 5.90 | 365 |
| **This model (OLMo-core, OLMo-2 architecture)** | **5.08** | **161** |
## Files
- `model.safetensors`: OLMo-core `Transformer` state dict
- `olmo_core_config.json`: the `TransformerConfig` used to build the model
- `tokenizer.json`: the Arabic BPE tokenizer (load with `tokenizers.Tokenizer.from_file`)
## How to load
```python
import torch
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file
from tokenizers import Tokenizer
from olmo_core.nn.transformer import TransformerConfig
repo = "yahya-ai10/tiny-arabic-olmo2"
tokenizer = Tokenizer.from_file(hf_hub_download(repo, "tokenizer.json"))
model = TransformerConfig.olmo2_30M(vocab_size=16384).build(init_device="cpu")
model.load_state_dict(load_file(hf_hub_download(repo, "model.safetensors")))
logits = model(torch.tensor([tokenizer.encode("كان ابن خلدون").ids])) # (batch, seq, vocab)
```
## Limitations
Trained on only 16.4M tokens (real models use trillions), so it often invents names, dates and facts. It covers Modern Standard Arabic from Wikipedia only (no dialects) and is not instruction-tuned. Use it for learning and experiments only.
## Licence and data
The training data is Arabic Wikipedia (CC BY-SA 4.0). The training code is OLMo-core (Apache-2.0).