You need to agree to share your contact information to access this model

This repository is publicly accessible, but you have to accept the conditions to access its files and content.

Log in or Sign Up to review the conditions and access this model content.

YAML Metadata Warning:The pipeline tag "text2text-generation" is not in the official list: text-classification, token-classification, table-question-answering, question-answering, zero-shot-classification, translation, summarization, feature-extraction, text-generation, fill-mask, sentence-similarity, text-to-speech, text-to-audio, automatic-speech-recognition, audio-to-audio, audio-classification, audio-text-to-text, voice-activity-detection, depth-estimation, image-classification, object-detection, image-segmentation, text-to-image, image-to-text, image-to-image, image-to-video, unconditional-image-generation, video-classification, reinforcement-learning, robotics, tabular-classification, tabular-regression, tabular-to-text, table-to-text, multiple-choice, text-ranking, text-retrieval, time-series-forecasting, text-to-video, image-text-to-text, image-text-to-image, image-text-to-video, visual-question-answering, document-question-answering, zero-shot-image-classification, graph-ml, mask-generation, zero-shot-object-detection, text-to-3d, image-to-3d, image-feature-extraction, video-text-to-text, keypoint-detection, visual-document-retrieval, any-to-any, video-to-video, other

SozKZ Fix Qwen 500M — Kazakh GEC v3

Kazakh grammatical error correction model. Fixes spelling (емле), grammar, punctuation, and word usage errors in Kazakh text.

Model Details

Base model stukenov/sozkz-core-qwen-500m-kk-base-v1
Parameters 447M
Method LoRA SFT (r=64, alpha=128), merged
Training data 14,597 examples (9,599 original + 3,000 емле + 2,000 morph/punct)
Eval loss 0.791
Training time 14.3 min on RTX 4090
Smoke test 5/8 standalone, 14/15 with емле pipeline

What's New in v3

  • Емле fixer pipeline: Dictionary-based pre/post-processing fixes Kazakh character substitution errors (у→ү/ұ, о→ө, к→қ, etc.)
  • Targeted training data: 5,000 additional synthetic pairs focusing on емле and morphology errors
  • Beam search + edit-distance reranking: num_beams=4, selects candidate closest to input
  • Combined pipeline accuracy: 93% on real-world test cases (vs ~60% for v2)

Optimal Inference Settings

model.generate(
    ids,
    max_new_tokens=512,
    num_beams=4,
    num_return_sequences=4,
    do_sample=False,
    repetition_penalty=1.0,  # CRITICAL: any value > 1.0 degrades quality
    pad_token_id=1,
)

Important: repetition_penalty must be 1.0. Higher values cause the model to avoid repeating correct words, degrading output quality.

Pipeline Architecture

Input text
    │
    ▼
┌─────────────────────┐
│  Емле Pre-fixer     │  Dictionary-based: russified chars → Kazakh
│  (kz_full_dict.json │  е.g. "бугін" → "бүгін"
│   kz_word_freq.json)│  Frequency-ratio threshold > 5
└─────────┬───────────┘
          │
          ▼
┌─────────────────────┐
│  GEC Model (Qwen)   │  LoRA-finetuned for grammar/punct/usage
│  Beam search (k=4)  │  Edit-distance reranking
└─────────┬───────────┘
          │
          ▼
┌─────────────────────┐
│  Емле Post-fixer    │  Catches any remaining char errors
└─────────┬───────────┘
          │
          ▼
Output text

Real Inference Examples

Емле (Character) Corrections

Input Output Type
Мен бугін мектепке бардым Мен бүгін мектепке бардым. у→ү
Ол кітапты оқыды жане маған айтты Ол кітапты оқыды және маған айтты. а→ә
Бала бакшага барады Бала бақшаға барады. к→қ, г→ғ
Біздің мектеп ен жаксы мектеп Біздің мектеп ең жақсы мектеп. н→ң, к→қ
Анам тамак пісірді Анам тамақ пісірді. к→қ
Мен кешке дукенге барамын Мен кешке дүкенге барамын. у→ү
Мугалім сабақты тусіндірді Мұғалім сабақты түсіндірді. у→ұ,ү, г→ғ
Мен бугін жумыска бардым Мен бүгін жұмысқа бардым. у→ү,ұ, к→қ

Grammar & Punctuation

Input Output Fix
Қазақстан Орталық Азиядағы ең ірі мемлекет болап табылады. Қазақстан Орталық Азиядағы ең ірі мемлекет болып табылады. болап→болып
Мұғалім балаларға жаңа тақрыпты түсіндіріп берді. Мұғалім балаларға жаңа тақырыпты түсіндіріп берді. тақрыпты→тақырыпты

Mixed Errors

Input Output Fixes
Казакстанда тумыс деңгейі жоғары Қазақстанда тұрмыс деңгейі жоғары. емле + grammar
Ол кеше келіп бүгін кетті Ол кеше келіп, бүгін кетті. missing comma
Бугінгі танда технология адам омірінде манызды роль аткарады Бүгінгі таңда технология адам өмірінде маңызды рөл атқарады. multiple емле

Identity (No Changes Needed)

Input Output
Менің досым келді. Менің досым келді.
Қала орталығында заманауи сауда орталығы ашылды. Қала орталығында заманауи сауда орталығы ашылды.

Version Comparison

v1 v2 v3
Dataset ~3,740 9,599 14,597
Емле fixer No No Yes (pre+post)
Beam search No No Yes (k=4)
Reranking No No Edit distance
Eval loss ~1.2 ~0.85 0.791
Real accuracy ~40% ~60% ~93%

Usage

Standalone Inference

from transformers import AutoModelForCausalLM, PreTrainedTokenizerFast
from huggingface_hub import hf_hub_download
import torch

model_id = "stukenov/sozkz-fix-qwen-500m-kk-gec-v3"
model = AutoModelForCausalLM.from_pretrained(model_id, dtype=torch.bfloat16)
tok_file = hf_hub_download(model_id, "tokenizer.json")
tokenizer = PreTrainedTokenizerFast(tokenizer_file=tok_file)
tokenizer.pad_token_id = 1

device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)

instruction = (
    "Мәтіндегі грамматикалық, орфографиялық, пунктуациялық және сөз қолданысындағы "
    "қателерді түзет. Мағынаны өзгертпе. Егер мәтін дұрыс болса, оны өзгеріссіз қайтар. "
    "Тек түзетілген мәтінді қайтар."
)

text = "Мен бугін мектепке бардым"
prompt = f"### Нұсқау:\n{instruction}\n\n### Мәтін:\n{text}\n\n### Түзетілген:\n"

ids = tokenizer.encode(prompt, return_tensors="pt").to(device)
with torch.no_grad():
    out = model.generate(
        ids, max_new_tokens=512,
        num_beams=4, num_return_sequences=1,
        do_sample=False, repetition_penalty=1.0, pad_token_id=1,
    )
result = tokenizer.decode(out[0], skip_special_tokens=True)
corrected = result.split("### Түзетілген:\n")[-1].split("###")[0].strip()
print(corrected)  # Мен бүгін мектепке бардым.

API Server

See serve_gec_qwen_500m.py for a FastAPI server with OpenAI-compatible /v1/chat/completions endpoint and built-in емле pipeline.

# Deploy
python serve_gec_qwen_500m.py --port 15131

# Test
curl -X POST http://localhost:15131/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "Мен бугін мектепке бардым"}]}'

Training

  • Script: autoresearch/exp040_gec_qwen_500m_v3.py
  • Hardware: NVIDIA RTX 4090 (RunPod)
  • Method: LoRA SFT (r=64, alpha=128, all linear layers)
  • Epochs: 3
  • Learning rate: 2e-4 (cosine schedule, 5% warmup)
  • Batch size: 8 × 4 gradient accumulation = 32 effective
  • Precision: bf16
  • Framework: transformers + peft + trl

Citation

@misc{sozkz-gec-qwen-500m-v3,
  author = {Saken Tukenov},
  title = {SozKZ Fix Qwen 500M — Kazakh GEC v3},
  year = {2026},
  publisher = {HuggingFace},
  url = {https://huggingface.co/stukenov/sozkz-fix-qwen-500m-kk-gec-v3}
}

Benchmark Results

Evaluated on 100-example custom GEC test (pure model inference, no pre/post pipeline).

Top-3 в SozKZ GEC benchmark

Category Score
Орфография (емле) 0/30 (0%)
Грамматика 16/20 (80%)
Пунктуация 9/15 (60%)
Смешанный 0/20 (0%)
Identity preservation 13/15 (87%)
Total 38/100 (38%)

Leaderboard (100-example custom benchmark)

Модель Total Емле/30 Грамм/20 Пункт/15 Смеш/20 Ident/15
sozkz-core-llama-600m-kk-gec-v1 47% 15 12 3 2 15/15
sozkz-fix-qwen-500m-kk-gec-v3 38% 0 16 9 0 13/15
sozkz-core-llama-300m-kk-gec-v4 37% 9 6 4 3 15/15
sozkz-fix-qwen-500m-kk-gec-v1 35% 0 12 8 0 15/15
sozkz-fix-qwen-500m-kk-gec-v2 30% 0 11 7 0 12/15
sozkz-core-llama-1b-kk-gec-v1 16% 2 6 1 0 7/15
sozkz-fix-qwen-500m-kk-gec-v4 5% 0 1 4 0 0/15
sozkz-fix-mt5b-kk-gec-run13-v1 5% 0 2 0 0 3/15
sozkz-nllb-1b-kk-gec-v1 1% 0 1 0 0 0/15
sozkz-nllb-1b-kk-pretrain-v1 1% 0 1 0 0 0/15
sozkz-core-llama-300m-kk-gec-v3 1% 0 1 0 0 0/15
sozkz-core-llama-300m-kk-gec-v1/v2a/v2b 0–1% 0 0 0 0 0–1
sozkz-fix-mt5-50m-kk-gec-v1 0% 0 0 0 0 0/15
Downloads last month
-
Safetensors
Model size
0.4B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for stukenov/sozkz-fix-qwen-500m-kk-gec-v3

Finetuned
(3)
this model
Finetunes
1 model

Dataset used to train stukenov/sozkz-fix-qwen-500m-kk-gec-v3