ISLAM-PO/MasryGPT-Chat-1.5B
MasryGPT Chat โ Egyptian Dialect Conversational AI ๐ช๐ฌ
Naming note: The repository name is retained for backward compatibility; the recommended project title is MasryGPT Chat. Try the model: Open `MasryGPT_Chat_Test.ipynb` in Colab with a T4 GPU, or follow `TESTING.md`.
<div align="center">
Qwen2.5-1.5B-Instruct โข Fine-tuned for Egyptian Arabic (Masry) โข QLoRA + Unsloth
80,000 Egyptian terms โข 2,500 steps โข Loss 0.079 โข 2.9GB 16-bit Merged
</div>
๐ฌ๐ง English - Professional Documentation
Table of Contents
- Project Overview
- Motivation
- Model Details
- Dataset
- Training Pipeline & Deep Analysis
- Evaluation & Benchmarks
- Usage
- Limitations & Error Analysis
- Ethics & Bias
- Roadmap
- File Structure
- Citation & Contribution
1. Project Overview
MasryGPT Chat is an experimental open-source Egyptian Arabic (Masry / ุนุงู
ูุฉ ุงููุงูุฑุฉ) chat model based on Qwen2.5-1.5B-Instruct. This project explores the gap between Modern Standard Arabic and authentic Egyptian daily speech, humor, and idioms. The results below are an internal pilot and are not an independent benchmark.
Goal: Build a lightweight (1.5B), fast, and deployable model that speaks like an Egyptian โ not a textbook โ for chatbots, customer service, social media, and education in Egypt.
Internal pilot result: After 1 epoch on 80k Egyptian examples, training loss moved from 0.091 โ 0.074 (-18.7%) with an average of 0.079. A 100-prompt internal review by 3 native speakers reported 4.6/5 for Egyptian-dialect fluency; this is not an independent benchmark. Inference is ready for a single T4 in 4-bit mode (about 1.2GB VRAM).
2. Motivation
- MSA vs Dialect Gap: Existing Arabic LLMs (Qwen, Jais, AceGPT) optimize for MSA, but 105M Egyptians speak Masry daily. "ุงุฒูู" vs "ููู ุญุงูู" โ difference is cultural.
- Lightweight Deployment: 7B models need 14GB+ VRAM. 1.5B runs on mobile/T4/edge, perfect for startups in Egypt with limited GPU.
- Unsloth Efficiency: 2x faster fine-tuning on free Kaggle T4 x2 without A100.
3. Model Details
4. Dataset
Name: qwen_egyptian_80k_terms.jsonl โ 80,000 examples
Source & Curation:
- Synthetic generation from Egyptian lexicon + manual filtering of vulgarity.
- Format:
{"messages": [{"role": "user", "content": "..."}, {"role": "assistant", "content": "ู ุตุฑู..."}]} - Preprocessing:
get_chat_template(tokenizer, chat_template="qwen-2.5")+tokenizer.apply_chat_template(..., tokenize=False)โ fieldtextwith packing.
Distribution:
- Greetings & Daily Chat: 35%
- Humor & Jokes: 15%
- Expressions & Idioms: 15%
- Customer Service & Instructions: 20%
- Culture & Food: 15%
Example:
{"messages": [{"role": "user", "content": "ูุนูู ุงูู ุนูุด ูู
ูุญุ"}, {"role": "assistant", "content": "ุนูุด ูู
ูุญ ูุนูู ุงูุนุดุฑุฉ ูุงูุนูุฏ ุจูู ุงูุตุญุงุจุ ุงููู ูู ู
ุนุงู ุนูุด ูู
ูุญ ู
ูุฎูููุด"}]}Preprocessing Code:
from datasets import load_dataset
from unsloth import get_chat_template
tokenizer = get_chat_template(tokenizer, chat_template="qwen-2.5")
def formatting_prompts_func(examples):
convos = examples["messages"]
texts = [tokenizer.apply_chat_template(c, tokenize=False, add_generation_prompt=False) for c in convos]
return {"text": texts}
dataset = dataset.map(formatting_prompts_func, batched=True)5. Training Pipeline & Deep Analysis
Pipeline: Hugging Face Hub (ISLAM-PO/MasryGPT) โ FastLanguageModel.from_pretrained (4bit) โ get_peft_model (QLoRA) โ SFTTrainer (TRL) โ save_pretrained_merged (16bit) โ Hugging Face
Hyperparameters (Final Fast Config โ Kaggle T4 x2): | Param | Value | Why | |---|---|---| | max_seq_length | 2048 | Balance: 1024 was 2x faster but 2048 captures longer Egyptian rants without OOM | | per_device_train_batch_size | 32 | Maximized for T4 15GB (2.4-4.1GB actual due to Unsloth memory efficiency) | | gradient_accumulation_steps | 1 | Effective batch 32 = 80k/32 = 2,500 steps | | learning_rate | 2e-4 | QLoRA standard for 1.5B, cosine scheduler for smooth decay | | optim | adamw_8bit | GPU-resident (vs paged_adamw_8bit โ RAM). Chose GPU for your 30GB VRAM requirement | | weight_decay | 0.01 | Regularization against overfitting on 80k | | warmup_steps | 20 | 0.8% of steps for stable start | | lr_scheduler | cosine | Best for 1 epoch | | gradient_checkpointing | False | Disabled to force VRAM usage (vs True saves VRAM to RAM) | | packing | True | Packs short Egyptian sentences โ 10x sample/sec | | dataloader_num_workers | 0 | Minimized RAM (vs 8 used 25GB RAM) | | seed | 3407 | Unsloth default | | num_train_epochs | 1 | 80k needs 1 epoch; 2nd epoch risks memorization |
Deep Loss Analysis (2,500 steps, 2h13m):
Step 10: 0.091025
Step 100: 0.098729 โ initial spike (warmup)
Step 500: 0.082923
Step 1000: 0.081538
Step 1500: 0.077019
Step 2000: 0.074811
Step 2500: 0.074394
Avg: 0.07995 | Perplexity exp(0.079) โ 1.083- Convergence: Smooth 18.7% drop, no divergence. Loss stabilizes at 0.074-0.077 after step 1500 โ model saturated on 80k. More epochs would overfit.
- FLOPs:
1.05e17total โ ~13.1 TFLOPs/s on T4. - Throughput:
10.002 samples/sec,0.313 steps/sec(Unsloth 2x faster vs vanilla). - GPU Utilization: 2.4GB/15GB (GPU0 93%) + 4.1GB/15GB (GPU1 51%) โ low memory is feature of 4-bit + Unsloth, not bug. Compute is high, memory is low.
- CPU 100%, RAM 6-7GB โ CPU is bottleneck for tokenization, not GPU.
Why Not 10GB VRAM? 1.5B 4-bit quantized weights = 0.8GB. Even batch 32 only adds ~1.5GB activations. To force 10GB you need load_in_4bit=False (full 16-bit = 3GB base + 6GB optimizer) โ but that's 3x slower and unnecessary. Current 2-4GB is optimal.
6. Evaluation & Benchmarks
Evaluation status: The figures in this section are an internal pilot, not an independently reproduced benchmark. See `EVALUATION.md` for the protocol and limitations.
Quantitative: | Benchmark | MasryGPT Chat | Qwen2.5-1.5B Base | Gain | |---|---|---|---| | Train Loss | 0.074 | 0.115 (zero-shot) | -35% | | Perplexity (80k test split 5%) | 1.08 | 1.22 | -11% | | Egyptian Fluency (human 100 prompts, 1-5) | 4.6 | 3.1 | +48% | | MSA Fluency | 4.2 | 4.7 | -10% (tradeoff) | | Idiom Correctness ("ุนูุด ูู ูุญ") | 40% | 20% | +100% but still weak |
Qualitative Examples:
- โ
User: ุงุฒููุโุงุฒูู ูุง ุจุงุดุง ุนุงู ู ุงูู ุงูููุงุฑุฏุฉุ(natural) - โ
User: ูุนูู ุงูู ุนูุด ูู ูุญุโููู ุฉ ุนูุด ูู ูุณ ู ุนูุงูุง ุฎุจุฒ ู ุตุฑู(FAIL โ needs idiom data) - โ
User: ุงุญูููู ููุชุฉโ generates short joke (needs longermax_new_tokens=256+temperature 0.8)
Comparison vs Base: Base Qwen answers in MSA: "ููู ุญุงููุ" โ MasryGPT answers "ุงุฒูู ูุง ุจุงุดุงุ" โ 48% more Egyptian as judged by 3 native speakers.
7. Usage
A. Unsloth (Recommended, Fast):
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
model_name="ISLAM-PO/MasryGPT-Chat-1.5B",
max_seq_length=2048, dtype=None, load_in_4bit=True,
)
FastLanguageModel.for_inference(model)
messages=[{"role":"user","content":"ุงุฒูู ูุง ุจุงุดุงุ"}]
inputs=tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt", return_dict=True).to("cuda")
outputs=model.generate(**inputs, max_new_tokens=256, temperature=0.8, top_p=0.95, do_sample=True, repetition_penalty=1.1)
print(tokenizer.batch_decode(outputs[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)[0])B. Transformers (Standard):
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("ISLAM-PO/MasryGPT-Chat-1.5B", device_map="auto", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("ISLAM-PO/MasryGPT-Chat-1.5B")
# same generate codeC. API & Gradio:
pip install gradio
# then wrap generate() in gr.InterfaceGeneration Tips:
temperature 0.7-0.8best for Masry creativity,0.3for factual.- Always set
return_dict=Trueto fixattention_maskwarning. - If you see
fix_mistral_regexwarning, addfix_mistral_regex=Truewhen loading tokenizer viaAutoTokenizer.
8. Limitations & Error Analysis
- Idioms Weakness: "ุนูุด ูู ูุญ = ุงูุนูุฏ" fails 60% โ dataset has only 15% idioms, needs 5k more real idiom pairs.
- Hallucination: May invent Egyptian facts. No RAG.
- Short Responses: Trained on short
textpacking โ tends to 20-30 tokens. Increasemax_new_tokensand userepetition_penalty. - MSA Degradation: -10% MSA due to catastrophic forgetting (1 epoch minimizes it, but still).
- No Safety Filter: Beyond base Qwen, may repeat vulgar terms if in data.
Failure Mode Analysis (2500 steps): Loss plateau at 1500 steps โ dataset saturated. Solution: add 40k diverse real conversations + 1 more epoch with LR 1e-4.
9. Ethics & Bias
- Data is synthetic Egyptian, may reflect Cairo dialect bias over Upper Egypt/Saidi.
- No PII. Vulgarity filtered but not perfect.
- Use responsibly: not for medical/legal advice in Egyptian.
- Model inherits Qwen license and potential biases.
10. Roadmap
- [ ] v1.1: Add 5k idioms + 10k real chat logs โ target idiom 90%
- [ ] v2.0: DPO/RLHF for Egyptian humor alignment
- [ ] v2.5: 3B version for better reasoning, keep 1.5B lite
- [ ] Deployment: GGUF + Ollama + ONNX
Training data and reproducibility
The 80k training JSONL referenced by this model is not published in this repository. Treat the reported metrics as an internal pilot until the exact dataset, generation script, filtering rules, and evaluation prompts are released or linked. This prevents overstating reproducibility while preserving the existing model weights.
11. File Structure
MasryGPT-merged/
โโโ config.json # Qwen2 config, model_type=qwen2, vocab 151936
โโโ model.safetensors # 2.9GB 16-bit merged (1.05GB 4-bit before merge)
โโโ tokenizer.json # 11.4 MB
โโโ tokenizer_config.json # 7.03 kB (fix_mistral_regex warning documented)
โโโ chat_template.jinja # qwen-2.5 template
โโโ generation_config.json # eos 151645, pad 151654
โโโ README.md # This file12. Citation & Contribution
Citation:
@misc{masrygpt_chat2026,
author = {ISLAM-PO},
title = {MasryGPT Chat: Egyptian Dialect Qwen2.5-1.5B-Instruct via QLoRA & Unsloth},
year = {2026},
publisher = {Hugging Face},
url = {https://huggingface.co/ISLAM-PO/MasryGPT-Chat-1.5B},
note = {80k terms, 2500 steps, loss 0.079}
}Contribution โ We Need You!
- Found a wrong Masry word? Open Issue with prompt + expected answer.
- Have Egyptian chat data (Facebook or WhatsApp, properly anonymized and with documented permission)? Propose a separate dataset repository after privacy and provenance review.
- Want to help evaluate? Run
eval_masry.py(100 prompts) and submit scores.
Contact: Hugging Face Discussion tab โ ISLAM-PO
๐ช๐ฌ ุจุงูู ุตุฑู - ุงููุซุงุฆู ุงูุงุญุชุฑุงููุฉ
ุงูููุฑุณ
- ูุธุฑุฉ ุนุงู ุฉ
- ููู ุนู ููุง ุงูู ุดุฑูุน ุฏูุ
- ุชูุงุตูู ุงูู ูุฏูู
- ุงูุฏุงุชุง
- ุงูุชุฏุฑูุจ ูุชุญููู ุนู ูู
- ุงูุชูููู
- ุงุฒุงู ุชุณุชุฎุฏู ู
- ุนููุจู
- ุงูุฃุฎูุงููุงุช
- ุงูุฎุทุฉ ุงูุฌุงูุฉ
1. ูุธุฑุฉ ุนุงู ุฉ
MasryGPT Chat ูู ุฃูู ู
ูุฏูู ู
ูุชูุญ ุงูู
ุตุฏุฑ ุจูุชููู
ู
ุตุฑู ุนุงู
ู ุฃุตูู ู
ุด ูุตุญู ู
ุชุฑุฌู
ุฉ. ู
ุจูู ุนูู Qwen 1.5B ูู
ุชุฏุฑุจ ุจู QLoRA ุนูู 80 ุฃูู ุชุนุจูุฑ ู
ุตุฑู. ูุฏูู: ุฃู ุญุฏ ูู ู
ุตุฑ ูุดุบู ุดุงุช ุจูุช ุจูุชููู
ุฒูู ุจุงูุธุจุท ุนูู ู
ูุจุงูู ุฃู ูุงุจ ุชูุจ ุถุนููุ ู
ู ุบูุฑ ู
ุง ูุญุชุงุฌ ุณูุฑูุฑ ุบุงูู.
ูุชูุฌุฉ ุงูุชูููู
ุงูุฏุงุฎูู: ุจุนุฏ epoch ูุงุญุฏ ุนูู 80 ุฃูู ู
ุซุงู ู
ุตุฑูุ ุงูุฎูุถ Loss ู
ู 0.091 ุฅูู 0.074 ุฎูุงู ุณุงุนุชูู ู13 ุฏูููุฉ ุนูู ุจุทุงูุชู T4. ูููู
3 ู
ุชุญุฏุซูู ุฃุตูููู 100 prompt ุจู
ุชูุณุท 4.6/5 ูุทูุงูุฉ ุงูููุฌุฉ ุงูู
ุตุฑูุฉุ ูุฐุง ุชูููู
ุฏุงุฎูู ูููุณ benchmark ู
ุณุชูููุง.
2. ููู ุนู ููุง ุงูู ุดุฑูุน ุฏูุ
- ุงููุตุญู ู ุด ููุงูุฉ: ูู ุงูู ูุฏููุงุช ุงูุนุฑุจูุฉ ุจุชุชููู "ููู ุญุงูู" ููู ุงูู ุตุฑู ุจูููู "ุงุฒูู ูุง ุจุงุดุงุ" ุงููุฑู ุซูุงูู ู ุด ูุบูู.
- ู
ูุฏูู ุฎููู:
7Bู ุญุชุงุฌ14GBูุงุฑุชุ1.5Bูุดุชุบู ุนูู4GBโ ู ูุงุณุจ ูุดุฑูุงุช ูุงุดุฆุฉ ูู ู ุตุฑ. - ุณุฑุนุฉ Unsloth: ุจูุฏุฑุจ
2xุฃุณุฑุน ุจุจูุงุด.
3. ุชูุงุตูู ุงูู ูุฏูู
4. ุงูุฏุงุชุง
80 ุฃูู ู
ุซุงู ุจุตูุบุฉ messages:
- ุณูุงู
ุงุช ูุฏุฑุฏุดุฉ ููู
ูุฉ
35% - ูุฒุงุฑ ูููุช
15% - ุฃู
ุซุงู ูุชุนุจูุฑุงุช
15%(ูููู ูุฏู ุณุจุจ ุบูุท "ุนูุด ูู ูุญ") - ุฎุฏู
ุฉ ุนู
ูุงุก
20% - ุซูุงูุฉ ูุฃูู
15%
ู
ุซุงู: User: ูุนูู ุงูู ุนูุด ูู
ูุญุ โ Assistant: ูุนูู ุงูุนุดุฑุฉ ูุงูุนูุฏุ ุงููู ููุช ู
ุนุงู ุนูุด ูู
ูุญ ู
ุณุชุญูู ูุฎููู
ุงูููุฏ: get_chat_template(tokenizer, chat_template="qwen-2.5") + packing=True ุนุดุงู ุงูุฌู
ู ุงููุตูุฑุฉ ุชุชุฌู
ุน.
5. ุงูุชุฏุฑูุจ ูุชุญููู ุนู ูู
ุงูุฎุทูุงุช: Hub โ 4bit โ QLoRA โ SFTTrainer โ ุฏู
ุฌ 16bit
ุงูุฅุนุฏุงุฏุงุช ุงูููุงุฆูุฉ (ุงููู ุฎูุตุช ูู 2:13): batch 32, lr 2e-4 cosine, optim adamw_8bit (ุนูู ุงููุงุฑุช ู
ุด ุงูุฑุงู
), max_seq 2048, warmup 20, 1 epoch
ุชุญููู ุงูู Loss ุจุนู
ู: 0.091 โ 0.074 ูุฒูู 18.7%. ูู ุงูุฃูู ุทูุน ูู 0.098 ุจุณุจุจ warmup ูุจุนุฏูู ูุฒู ุจุซุจุงุช ูุญุฏ 1500 ุฎุทูุฉ ูููู ุนูุฏ 0.074 โ ู
ุนูุงูุง ุงูุฏุงุชุง ุฎูุตุช ูุงูู
ูุฏูู ุญูุธูุง. ูู ูู
ููุง Epoch ุชุงูู ููุญูุธ ุบูุท (overfit). ุงูู Perplexity 1.08 ู
ู
ุชุงุฒุฉ (1 = ู
ุซุงูู).
ุงูุณุฑุนุฉ: 10 sample/sec, 0.313 step/sec, 1.05e17 FLOPs. ุงูู GPU ุงุณุชููู 2.4GB ู 4.1GB ุจุณ โ ุฏู ุชูููุฑ ู
ูุตูุฏ ู
ู Unsloth ู
ุด ุถุนู. ุงูู CPU 100% ูู ุงููู ูุงู ู
ุฎููู ู
ู ุชุญุถูุฑ ุงูุฏุงุชุง.
ููู ู
ุด 10GBุ ุงูู
ูุฏูู 1.5B 4-bit ูุฒูู 0.8GB ุจุณุ ุญุชู batch 32 ูุฒูุฏ 1.5GB. ุนุดุงู ุชูุตู 10GB ูุงุฒู
ุชูุบู 4-bit ูุชุดุบูู 16-bit ูุงู
ู โ ุฃุจุทุฃ 3x ูู
ููุด ูุงุฒู
ุฉ.
6. ุงูุชูููู
ุฃู ุซูุฉ:
- โ
ุงุฒููุโุงุฒูู ูุง ุจุงุดุง ุนุงู ู ุงูู ุงูููุงุฑุฏุฉุ(ู ู ุชุงุฒ) - โ
ุนูุด ูู ูุญโุนูุด ูู ูุณ = ุฎุจุฒ(ุบูุท โ ู ุญุชุงุฌ ุฏุงุชุง ุฃู ุซุงู) - โ
ููุชุฉ โ ุจูุญูู ููุชุฉ ูุตูุฑุฉ ูู ุฒูุฏุช
temperature 0.8
7. ุงุฒุงู ุชุณุชุฎุฏู ู
ููุณ ููุฏ ุงูุงูุฌููุฒู ูููุ ุจุณ ุบูุฑ ุงูุฑุณุงูุฉ:
messages = [{"role": "user", "content": "ุงุญูููู ููุชุฉ ู
ุตุฑูุฉ ูุตูุฑุฉ"}]
# ุฃู
messages = [{"role": "user", "content": "ุงุดุฑุญ ูุฎูุงุฌุฉ ูุนูู ุงูู ูุฎุฑู
ุจูุชู ุจุงูู
ุตุฑู"}]ูุตูุญุฉ: temperature 0.8 ูููุฒุงุฑุ 0.3 ููู
ุนููู
ุงุช.
8. ุนููุจู
- ุงูุฃู
ุซุงู ูุณู ุถุนูู โ ู
ุญุชุงุฌ
5kู ุซู ุฒูุงุฏุฉ. - ุจูุฃูู ุฃุญูุงูุงู โ ู
ููุด
RAG. - ุฑุฏูุฏู ูุตูุฑุฉ โ ุฒูุฏ
max_new_tokens=256. - ุงููุตุญู ููุช ุดููุฉ.
- ู ููุด ููุชุฑ ุดุชุงูู ููู.
9. ุงูุฃุฎูุงููุงุช
ุงูุฏุงุชุง ูููุง ููุฌุฉ ูุงูุฑูุฉ ุฃูุชุฑ ู ู ุงูุตุนูุฏู โ ููู ุงูุญูุงุฒ. ู ููุด ู ุนููู ุงุช ุดุฎุตูุฉ. ู ุชุณุชุฎุฏู ูุด ูู ูุตุงูุญ ุทุจูุฉ/ูุงููููุฉ.
10. ุงูุฎุทุฉ ุงูุฌุงูุฉ
- [ ] v1.1: ูุฒูุฏ
5kู ุซู +10kุดุงุช ุญูููู โ ููุตู90%ุฃู ุซุงู - [ ] v2.0:
DPOูููุฒุงุฑ - [ ] v2.5: ูุณุฎุฉ
3Bุฃููู ููุณูุจ1.5Bุฎูููุฉ - [ ] ุชุญููู ูู
GGUFููOllama
ู
ููุงุช ุงูู
ูุฏูู: config.json, model.safetensors 2.9GB, tokenizer.json 11MB, chat_template.jinja
ุงูู
ุณุงูู
ุฉ: ูููุช ููู
ุฉ ุบูุทุ ุงูุชุญ Issue. ุนูุฏู ุฏุงุชุง ู
ุตุฑูุ ุงุจุนุช PR. ุนุงูุฒ ุชููู
ุ ุฌุฑุจ 100 ุณุคุงู ูุงุจุนุช ุงููุชูุฌุฉ!
ุงูุชุฑุฎูุต: Apache 2.0
