CoolFace
Modelpublic

Slasky/HebrewGPT-296M

sourceHugging Faceapache-2.0updated 6mo agoView on Hugging Face
0likes50downloads
Model Card

HebrewGPT-296M ๐Ÿ‡ฎ๐Ÿ‡ฑ

HebrewGPT-296M is a 296 million parameter autoregressive Hebrew language model โ€” the smaller sibling of HebrewGPT-1B. Trained on 1 billion tokens of Hebrew Wikipedia using the Muon optimizer with Lookahead and SWA, it demonstrates strong Hebrew language understanding despite its compact size.

This model achieves 39.6% Top-1 and 68.4% Top-5 token prediction accuracy, making it suitable for research, prototyping, and resource-constrained Hebrew NLP applications.

Model Description

ParameterValue
Parameters296M
Hidden size (WIDTH)1536
Layers (DEPTH)10
Attention heads12
Head dimension128
MLP typeSwiGLU (intermediate_size=4096)
Positional encodingRoPE (interleaved, ฮธ=10000)
NormalizationRMSNorm
Vocabulary32,000 (Hebrew-native SentencePiece BPE)
Context length512 tokens
Weight tyingYes (embedding โ†” output head)
Precisionbfloat16

Architecture

Same design principles as HebrewGPT-1B but scaled down:

  • โ€”SwiGLU MLP with hidden dim = 4096
  • โ€”RoPE with interleaved pattern
  • โ€”RMSNorm pre-norm architecture
  • โ€”Weight tying between embedding and output head

Training Details

Optimizer

  • โ€”Muon optimizer + Lookahead (k=5, ฮฑ=0.6) + Stochastic Weight Averaging (SWA)
  • โ€”Cosine annealing with warm restarts

Data

  • โ€”~1 billion tokens from Hebrew Wikipedia

Hardware

  • โ€”Hardware: 4ร— NVIDIA A10G GPUs
  • โ€”Training time: Several hours

Evaluation Results

Overall Metrics

MetricValue
Validation BPB (SWA)4.42
Perplexity31.40
Top-1 Token Accuracy39.6%
Top-5 Token Accuracy68.4%
Top-10 Token Accuracy78.9%

Comparison Across Model Sizes

ModelParamsDataTop-1Top-5Top-10PPL
HebrewGPT-296M (this)296M1B tokens39.6%68.4%78.9%31.40
HebrewGPT-1B1.08B2.48B tokens38.4%56.1%63.6%29.75

Note: The 296M model shows higher token accuracy on its evaluation set (Wikipedia-focused), while the 1B model was trained on more diverse data and has lower perplexity overall.

Usage

โš ๏ธ Custom Architecture: This model uses a custom architecture. See `generate.py` for the full model class definition.

Quick Start

python
import torch
import sentencepiece as spm
from generate import HebrewGPT, ModelConfig

config = ModelConfig(
    vocab_size=32000,
    width=1536,
    depth=10,
    n_heads=12,
    head_dim=128,
    max_seq_len=512,
    dropout=0.0,
)
model = HebrewGPT(config)

state_dict = torch.load("swa_best.pt", map_location="cpu", weights_only=True)
model.load_state_dict(state_dict)
model.eval()

sp = spm.SentencePieceProcessor()
sp.Load("tokenizer.model")

prompt = "ื™ืจื•ืฉืœื™ื ื”ื™ื ืขื™ืจ"
input_ids = torch.tensor([sp.Encode(prompt)])
output = model.generate(input_ids, max_new_tokens=100)
print(sp.Decode(output[0].tolist()))

Command Line

bash
python generate.py \
    --model_path swa_best.pt \
    --prompt "ื™ืจื•ืฉืœื™ื ื”ื™ื ืขื™ืจ" \
    --width 1536 --depth 10 --n_heads 12 --max_seq_len 512 \
    --max_tokens 100 --temperature 0.8

Limitations

  • โ€”Hebrew-only: Trained exclusively on Hebrew Wikipedia text
  • โ€”Short context: Limited to 512 tokens (vs 2048 for the 1B model)
  • โ€”Wikipedia-focused: Training data is primarily encyclopedic โ€” may struggle with conversational or legal text
  • โ€”No instruction tuning: Base language model only
  • โ€”Custom architecture: Requires the provided model class to load
  • โ€”No safety filtering: May generate inappropriate or incorrect content

Citation

bibtex
@article{slasky2025hebrewgpt,
  title={Hebrew Language Model Research via Agentic AI: Training HebrewGPT from Scratch},
  author={Slasky, Ronnen},
  year={2025},
  url={https://d11k83yu06biio.cloudfront.net/paper/hebrew-autoresearch.html}
}

Acknowledgments

  • โ€”Loki โ€” AI research assistant (Amazon Bedrock on OpenClaw)
  • โ€”Andrej Karpathy โ€” For the autoresearch framework

Contact