Downloads · 30 days
29
11% of all-time downloads
Shams03/EgyLated
EgyLated is a translation model from Shams03. Use it when you need text moved from one language to another. It is set up for transformers. The card lists the license as apache-2.0.
This project develops a translation system specifically for the Egyptian dialect (Masri), built entirely from scratch. Rather than fine-tuning an existing model, it implements a custom Encoder-Decoder architecture wit…
Downloads · 30 days
29
11% of all-time downloads
All-time downloads
255
Public
Parameters
98.4M
399 MB on disk
Likes
2
Public
Click a slice to open those files.
.safetensors394 MB · 97%
From the Hugging Face model README
This project develops a translation system specifically for the Egyptian dialect (Masri), built entirely from scratch. Rather than fine-tuning an existing model, it implements a custom Encoder-Decoder architecture with stability improvements—like replacing LayerNorm with RMSNorm—and a BPE tokenizer designed to handle irregular spelling and slang. The system produces a robust model that reaches a BLEU score of 28.5, showing that reliable translation is achievable even without huge standard datasets.
Subsets of standard English datasets (C4, FineWeb, OpenSubtitles) were selected to cover a wide range of topics and writing styles.
This pipeline employs rigorous cleaning steps to ensure high-quality input:
" → ") and splits bilingual text lines into separate lists.|, tabs \t) into a unified format for consistent parsing.[music]) and promotional phrases (e.g., اشترك في القناة).The model uses a custom Encoder-Decoder (BART configuration) built from scratch with the following specifications:

This project addresses critical failure points common in training dialectal models:
1. The "RMSNorm" Stability Fix
2. Morphological Pre-Tokenization
3. The "Lobotomy" Embedding Fix
model.shared.weight) during the loading state, ensuring semantic alignment.4. Data Imbalance (Weighted Sampling)
| Metric | Score | Note |
|---|---|---|
| BLEU Score | 28.5 | View Kaggle Logs |
| Validation Loss | 2.18 | Stable convergence |
| Training Loss | 2.33 |
| Type | English Input | Model Output (Masri) | Notes |
|---|---|---|---|
| Good | "Get in the car, we have to go now!" | "ادخل العربية، لازم نمشي دلوقتي!" | Captures urgency and dialect terms. |
| Good | "I have a very bad feeling about this." | "عندي إحساس وحش أوي بخصوص الموضوع ده." | Natural phrasing. |
| Good | "Why are you doing this?" | "انت بتعمل كده ليه؟" | Correct question structure. |
| Bad | "The mitochondria is the powerhouse of the cell." | "الأرياريا هو كتلة الخلايا الجذعية" | Limitation: Struggles with scientific terms. |
| Bad | "Complex philosophical prose with archaic terms." | "الأفكار الفلسفية بالمصطلحات القديمة" | Limitation: Acceptable but not optimized for complex phrasing. |
This model requires a specific patching procedure to load the custom RMSNorm architecture and ensure the correct special tokens are used.
torch>=2.0.0, transformers>=4.30.0
import torch
import torch.nn as nn
import re
from transformers import AutoTokenizer, AutoConfig, AutoModelForSeq2SeqLM
from safetensors.torch import load_file
from huggingface_hub import hf_hub_download
# 1. Define Architecture Components
class RMSNorm(nn.Module):
def __init__(self, dim: int, eps: float = 1e-6):
super().__init__()
self.dim = dim
self.eps = eps
self.scale = nn.Parameter(torch.ones(dim))
def forward(self, x: torch.Tensor) -> torch.Tensor:
rms = torch.sqrt(x.pow(2).mean(-1, keepdim=True) + self.eps)
return x / rms * self.scale
def load_patched_model(repo_id):
device = "cuda" if torch.cuda.is_available() else "cpu"
# Load Config and fix Token IDs (overriding config.json errors)
config = AutoConfig.from_pretrained(repo_id)
tokenizer = AutoTokenizer.from_pretrained(repo_id)
model = AutoModelForSeq2SeqLM.from_config(config)
# Patch LayerNorm -> RMSNorm
for name, child in list(model.named_children()):
def patch_recursive(m):
for n, c in list(m.named_children()):
if isinstance(c, nn.LayerNorm):
dim = c.normalized_shape[0] if isinstance(c.normalized_shape, (tuple, list)) else c.normalized_shape
setattr(m, n, RMSNorm(dim))
else:
patch_recursive(c)
patch_recursive(model)
# Load Weights
try:
f = hf_hub_download(repo_id, "model.safetensors")
model.load_state_dict(load_file(f), strict=False)
except:
f = hf_hub_download(repo_id, "pytorch_model.bin")
model.load_state_dict(torch.load(f, map_location="cpu"), strict=False)
return model.to(device).eval(), tokenizer
def fix_arabic(text):
if not text: return text
# Re-connect prefixes and fix punctuation
text = re.sub(r'(^|\s)(ال|لل|وال|بال)\s+(?=\S)', r'\1\2', text)
text = re.sub(r'\s+([،؟!.,])', r'\1', text)
return text.strip()
# 2. Run Inference
REPO_NAME = "Shams03/EgyLated"
model, tokenizer = load_patched_model(REPO_NAME)
def translate(text):
inputs = tokenizer(text, return_tensors="pt").to(model.device)
if "token_type_ids" in inputs: del inputs["token_type_ids"]
with torch.no_grad():
out = model.generate(
**inputs,
max_new_tokens=128,
num_beams=5,
early_stopping=True,
)
raw = tokenizer.decode(out[0], skip_special_tokens=True)
return fix_arabic(raw)
print(translate("I am really happy because the model works."))
# Output: "أنا مبسوط جدا عشان الموديل شغال"
This project is licensed under the MIT License.