Text Generation
Transformers
Safetensors
Turkish
ozan_llm
feature-extraction
turkish
turkce
causal-lm
ozanllm
base-model
pretraining
custom_code
Instructions to use coderian/OzanLLM-40M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use coderian/OzanLLM-40M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="coderian/OzanLLM-40M", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("coderian/OzanLLM-40M", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use coderian/OzanLLM-40M with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "coderian/OzanLLM-40M" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "coderian/OzanLLM-40M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/coderian/OzanLLM-40M
- SGLang
How to use coderian/OzanLLM-40M with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "coderian/OzanLLM-40M" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "coderian/OzanLLM-40M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "coderian/OzanLLM-40M" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "coderian/OzanLLM-40M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use coderian/OzanLLM-40M with Docker Model Runner:
docker model run hf.co/coderian/OzanLLM-40M
OzanLLM-40M: model kartini ve dosyalari guncelle
Browse filesFiles changed (8)
- README.mdAdded+187
- config.jsonAdded+18
- configuration_ozanllm.pyAdded+30
- generation_config.jsonAdded+10
- model.pyAdded+202
- model.safetensorsAdded+3
- tokenizer.jsonAdded
- tokenizer_config.jsonAdded+10
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187---language:- trlicense: apache-2.0library_name: transformerspipeline_tag: text-generationdatasets:- tascib/turkish-llm-datasettags:- turkish- turkce- causal-lm- ozanllm- base-model- pretraininginference: false---
# OzanLLM-40M
Sıfırdan eğitilmiş **38.3M parametreli küçük bir Türkçe dil modeli**. Base model'dir:instruction tuning yapılmamıştır; sohbet veya talimat takibi için değil, **metintamamlama** için tasarlanmıştır.
## Model Detayları
| | ||---|---|| Geliştirici | coderian || Yayın tarihi | Eylül 2026 || Dil | Türkçe (tr) || Lisans | Apache 2.0 || Mimari | Decoder-only Transformer (OzanLLM) || Parametre | 38.329.280 (38.3M) || Katman | 5 || Gizli boyut | 320 || Dikkat | Tek kafalı nedensel (causal) self-attention || Bağlam uzunluğu | 512 token || Kelime dağarcığı | 50.000 (BPE) || Konum kodlaması | Öğrenilebilir konum gömlemesi (512 × 320) || Aktivasyon | GELU (FFN genişliği 4× = 1.280) || Normalizasyon | Pre-norm LayerNorm || Çıktı katmanı | LM head (320 → 50.000), bağsız (untied) || KV cache | Yok (`use_cache=False`) || Hassasiyet | float32 |
## Mimari
- 5 adet Transformer bloğu; her blokta pre-norm LayerNorm ve residual bağlantılar- Nedensel öz-dikkat: Q/K/V projeksiyonları → ölçekli iç çarpım (1/√320) → gelecek pozisyonların maskelenmesi → softmax → 320 boyutlu çıktı- FFN: 320 → 1.280 (GELU) → 320- Girdi: token gömlemesi + öğrenilebilir konum gömlemesi toplamı- Çıkış: son LayerNorm + LM head; kayıp, kaydırılmış çapraz entropidir- Dropout ve ağırlık paylaşımı (weight tying) yok
## Hızlı Başlangıç
```bashpip install -U transformers torch```
```pythonfrom transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "coderian/OzanLLM-40M"tokenizer = AutoTokenizer.from_pretrained(model_id)model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True)
prompt = "Türkiye'nin en kalabalık şehri"inputs = tokenizer(prompt, return_tensors="pt")cikti = model.generate( **inputs, max_new_tokens=64, do_sample=True, temperature=0.8, top_p=0.9, repetition_penalty=1.1, # küçük model tekrara düşmesin)print(tokenizer.decode(cikti[0], skip_special_tokens=True))```
`trust_remote_code=True` gereklidir: model mimarisi standart transformerssınıflarından biri olmadığı için kendi kodunu (`model.py`,`configuration_ozanllm.py`) indirir. transformers 5.x ile yerel bir klasördenyüklerken de bu bayrak gereklidir.
Modeli indirdiğiniz klasörden yüklemek için:
```pythonmodel = AutoModelForCausalLM.from_pretrained("ozanllm", trust_remote_code=True)```
## Üretim Notları
- Model belgeleri `[BOS] ... [EOS]` çerçevesiyle eğitildi; en iyi sonuç için prompt'un başına `bos_token_id` (2) ekleyin.- Bağlam 512 token ile sınırlıdır; bu sınırın üzerindeki girdiler desteklenmez.- KV cache olmadığı için üretim token token ilerler ve uzun çıktılar yavaştır.- 38M'lik bir modelde tekrara düşme sık görülür; `repetition_penalty≈1.1` önerilir.- Örnekleme için `temperature≈0.8`, `top_p≈0.9` iyi çalışır.
## Eğitim
### Veri
| | ||---|---|| Veri seti | [tascib/turkish-llm-dataset](https://huggingface.co/datasets/tascib/turkish-llm-dataset) (CC BY-SA 4.0) || Kullanılan dilim | Akış (streaming) modunda alınan ilk 600.000 belge; yaklaşık 213M token || İşleme | Belgeler `[BOS] … [EOS]` olarak token'lanır ve 512'lik dizilere paketlenir; padding yoktur || Tokenizer | [coderian/QraXAi-Turkish-Tok-50K](https://huggingface.co/coderian/QraXAi-Turkish-Tok-50K) — BPE, 50.000 token, `[PAD]=0 [UNK]=1 [BOS]=2 [EOS]=3` |
### Hiperparametreler
| | ||---|---|| Optimizer adımı | 3.252 || Etkin batch | 128 dizi × 512 token = 65.536 token/adım || Toplam token | ≈213M || Optimizer | AdamW (β₁=0.9, β₂=0.95, weight decay 0.1) || Öğrenme oranı | 3e-4; 200 adım ısınma, ardından kosinüs ile 0.1×'e düşüş || Gradyan kırpma | 1.0 || Karışık hassasiyet | fp16 + GradScaler || Donanım | Kaggle, 2× Tesla T4 (otomatik DataParallel) || Çerçeve | PyTorch + Hugging Face transformers/datasets, safetensors |
Eğitim betiği tek dosyadır (`train.py`); model boyutları `EMBED_DIM=320`,`N_LAYERS=5`, `SEQ_LEN=512`, `BATCH_SIZE=16`, `GRAD_ACCUM=8` ile ayarlanmıştır.
## Kullanım Amacı
Uygun kullanımlar:
- Türkçe metin tamamlama, taslak sürdürme, yaratıcı yazı denemeleri- Türkçe NLP araştırmaları ve küçük model deneyleri- Fine-tuning için başlangıç noktası (base model)
Uygun olmayan kullanımlar:
- Soru-cevap, sohbet, talimat takibi (instruction tuning yoktur)- Olgusal doğruluk gerektiren üretim kullanımları- Hukuki, tıbbi veya güvenlik açısından kritik karar sistemleri
## Sınırlamalar ve Önyargılar
- 38M parametre ve ≈213M token ile eğitilmiş küçük bir base modeldir; bilgisi, akıcılığı ve tutarlılığı sınırlıdır.- Uzun üretimlerde tekrara düşebilir veya konudan sapabilir.- Eğitim verisi filtrelenmemiş web metni içerdiği için model önyargılı veya istenmeyen ifadeler üretebilir; çıktılar kullanılmadan önce gözden geçirilmelidir.- Türkçe dışındaki dillerde ve kod üretiminde güvenilir değildir.- Resmî bir benchmark değerlendirmesi yapılmamıştır.
## Dosyalar
| Dosya | Açıklama ||---|---|| `model.safetensors` | Model ağırlıkları (float32, ~153 MB) || `config.json` | Model yapılandırması (`auto_map` ile özel kod bağlantıları) || `generation_config.json` | Varsayılan üretim ayarları (BOS/EOS/PAD id'leri) || `model.py` | OzanLLM mimarisi (`trust_remote_code`) || `configuration_ozanllm.py` | `GPTConfig` yapılandırma sınıfı || `tokenizer.json`, `tokenizer_config.json` | Tokenizer (50.000 token) || `README.md` | Bu model kartı |
## Atıf
```bibtex@misc{ozanllm-40m, title = {OzanLLM-40M: Turkish Base Language Model}, author = {coderian}, year = {2026}, url = {https://huggingface.co/coderian/OzanLLM-40M}}```
---
## English Summary
**OzanLLM-40M** is a 38.3M-parameter Turkish base language model trained fromscratch on the first 600k documents (~213M tokens) of the`tascib/turkish-llm-dataset`. It is a 5-layer, 320-dim decoder-only Transformerwith single-head causal attention, learned absolute position embeddings and a50k BPE tokenizer. It is a base model intended for Turkish text completion, notfor chat or instruction following. Use `trust_remote_code=True` to load it.123456789101112131415161718{ "architectures": [ "OzanForCausalLM" ], "auto_map": { "AutoConfig": "configuration_ozanllm.GPTConfig", "AutoModel": "model.OzanForCausalLM", "AutoModelForCausalLM": "model.OzanForCausalLM" }, "dtype": "float32", "embed_dim": 320, "max_seq_len": 512, "model_type": "ozan_llm", "n_layers": 5, "transformers_version": "5.0.0", "use_cache": false, "vocab_size": 50000}123456789101112131415161718192021222324252627282930from transformers import PretrainedConfig
class GPTConfig(PretrainedConfig):
model_type = "ozan_llm"
# Hugging Face'te model kendi koduyla birlikte yuklenebilsin diye: # config.json'a yazilir, kullanici trust_remote_code=True ile yukler. auto_map = { "AutoConfig": "configuration_ozanllm.GPTConfig", "AutoModel": "model.OzanForCausalLM", "AutoModelForCausalLM": "model.OzanForCausalLM", }
def __init__( self, vocab_size=10000, n_layers=6, max_seq_len=512, embed_dim=256, use_cache=False, **kwargs ): super().__init__(**kwargs)
self.use_cache = use_cache self.vocab_size = vocab_size self.n_layers = n_layers self.max_seq_len = max_seq_len self.embed_dim = embed_dim12345678910{ "_from_model_config": true, "bos_token_id": 2, "eos_token_id": 3, "output_attentions": false, "output_hidden_states": false, "pad_token_id": 0, "transformers_version": "5.0.0", "use_cache": false}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202from transformers import GenerationMixin, PreTrainedModelfrom transformers.modeling_outputs import CausalLMOutputimport torch.nn as nnimport torchimport math
try: from .configuration_ozanllm import GPTConfigexcept ImportError: from configuration_ozanllm import GPTConfig
class CausalSelfAttention(nn.Module):
def __init__( self, embed_dim ): super().__init__()
self.q_proj = nn.Linear(embed_dim, embed_dim) self.k_proj = nn.Linear(embed_dim, embed_dim) self.v_proj = nn.Linear(embed_dim, embed_dim)
self.o_proj = nn.Linear(embed_dim, embed_dim)
def forward(self, x): batch_size, seq_len, embed_dim = x.shape
Q = self.q_proj(x) K = self.k_proj(x) V = self.v_proj(x)
scores = Q @ K.transpose(-2,-1)
scores = scores / math.sqrt(embed_dim)
mask = torch.triu( torch.ones( seq_len, seq_len, device=x.device ), diagonal=1 ).bool()
scores = scores.masked_fill(mask, torch.finfo(scores.dtype).min)
attention_w = torch.softmax( scores, dim=-1 )
output = attention_w @ V
output = self.o_proj(output)
return output
class TransformerBlock(nn.Module):
def __init__( self, embed_dim ): super().__init__()
self.ln1 = nn.LayerNorm(embed_dim)
self.attention = CausalSelfAttention( embed_dim )
self.ln2 = nn.LayerNorm(embed_dim)
self.ffn = nn.Sequential( nn.Linear( in_features=embed_dim, out_features=4*embed_dim ),
nn.GELU(),
nn.Linear( in_features=4*embed_dim, out_features=embed_dim ) )
def forward(self, x):
x = x + self.attention( self.ln1(x) )
x = x + self.ffn( self.ln2(x) )
return x
class OzanForCausalLM(PreTrainedModel, GenerationMixin):
config_class = GPTConfig
def __init__( self, config ):
super().__init__(config)
self.token_embedding = nn.Embedding( config.vocab_size, config.embed_dim )
self.position_embedding = nn.Embedding( config.max_seq_len, config.embed_dim )
self.transformer_blocks = nn.ModuleList([ TransformerBlock(config.embed_dim) for _ in range(config.n_layers) ])
self.ln_f = nn.LayerNorm( config.embed_dim )
self.lm_head = nn.Linear( config.embed_dim, config.vocab_size, bias=False )
self.post_init()
def forward( self, input_ids, labels=None, **kwargs ):
batch_size, seq_len = input_ids.shape
if seq_len > self.config.max_seq_len: raise ValueError( f"Sequence length ({seq_len}) " f"cannot be greater than " f"max_seq_len ({self.config.max_seq_len})" )
positions = torch.arange( seq_len, device=input_ids.device )
token_emb = self.token_embedding( input_ids )
pos_emb = self.position_embedding( positions )
x = token_emb + pos_emb
for block in self.transformer_blocks: x = block(x)
x = self.ln_f(x)
logits = self.lm_head(x)
loss = None
if labels is not None:
shift_logits = logits[ :, :-1, : ].contiguous()
shift_labels = labels[ :, 1: ].contiguous()
loss = nn.functional.cross_entropy( shift_logits.view( -1, shift_logits.size(-1) ), shift_labels.view(-1) )
return CausalLMOutput( loss=loss, logits=logits )123version https://git-lfs.github.com/spec/v1oid sha256:b5863fe6bf3208cd8d2fb431d394d6be7fdcd4ec2d60f400625f4c60b7c0117asize 15332628812345678910{ "backend": "tokenizers", "bos_token": "[BOS]", "eos_token": "[EOS]", "is_local": false, "model_max_length": 1000000000000000019884624838656, "pad_token": "[PAD]", "tokenizer_class": "TokenizersBackend", "unk_token": "[UNK]"}README.mdAdded+187
config.jsonAdded+18
configuration_ozanllm.pyAdded+30
generation_config.jsonAdded+10
model.pyAdded+202
model.safetensorsAdded+3
tokenizer.jsonAdded
tokenizer_config.jsonAdded+10