--- language: - tr license: gemma base_model: mlx-community/gemma-4-26B-A4B-it-OptiQ-4bit tags: - medical - triage - turkish - lora - mlx - emergency-medicine pipeline_tag: text-generation --- # Gemma 4 26B A4B — Turkish Emergency Triage ![AI-Triyaj](aitriyaj-banner.png) Türkiye acil servislerine özel, Türkçe triyaj kararı veren konuşmacı dil modeli. Küresel triyaj sistemleri (CTAS, ESI) genel nüfus ve geniş klinik senaryolar için tasarlanmış olup uygulamada uzun değerlendirme süreçleri gerektirmektedir. Bu model, Türkiye acil servis pratiğine uygun olarak; hızlı, odaklı ve spesifik sorularla hastayı yönlendiren, gereksiz adımları elemek yerine doğrudan karar noktasına ulaşan bir triyaj akışı için tasarlandı. Hasta ile Türkçe doğal dil diyalogu kurarak semptomları toplar ve **RED / YELLOW / GREEN** triyaj kararı üretir. > **Base model:** `mlx-community/gemma-4-26B-A4B-it-OptiQ-4bit` > **Fine-tuning:** LoRA (mlx-lm + mlx-optiq), 2000 iterasyon > **Format:** 4-bit quantized safetensors (fused, adapter ayrı gerekmez) --- ## Benchmark ![Triage Model Benchmark](benchmark.png) Fine-tuned modelimiz 648 vakalık test setinde tüm baseline modelleri geride bıraktı. Öne çıkan fark: diğer modeller RED'e aşırı yönelirken, fine-tuned model üç sınıf arasında en dengeli dağılımı gösterdi. --- ## Görev Hastanın şikayetini Türkçe konuşma diliyle alır, yapılandırılmış sorularla klinik bilgiyi toplar ve triyaj kararını verir: | Karar | Anlam | |-------|-------| | 🔴 RED | Acil, hemen müdahale gerektirir | | 🟡 YELLOW | Yarı acil, kısa sürede bakılmalı | | 🟢 GREEN | Acil değil, bekleyebilir | --- ## Model Mimarisi - **Gemma 4 26B A4B** (Mixture-of-Experts): 26B toplam parametre, token başına 4B aktif - **4-bit OptiQ quantization**: hassasiyet-odaklı mixed-precision (attention katmanları 8-bit, MLP 4-bit) - **LoRA fine-tuning**: yalnızca adapter ağırlıkları eğitildi, ardından base model ile birleştirildi --- ## Eğitim Verisi Eğitim verisi, bir acil tıp doktoru ile iş birliği yapılarak oluşturuldu. Doktorumuz, 117 farklı şikayet kategorisi (göğüs ağrısı, nefes darlığı, karın ağrısı vb.) için CTAS/ESI protokollerine dayalı ve Türkiye'deki sisteme uygun **karar ağaçları (path)** tasarladı. Her path; hangi soruların sorulacağını, hangi cevabın hangi triyaj kararına yol açacağını ve doğrudan RED kararı gerektiren tetikleyici semptomları tanımlar. Bu pathler temel alınarak **Gemini** ile 6.475 sentetik Türkçe diyalog üretildi: - **441 karar yolu** (path) — 117 şikayet kategorisi - **Hasta profili çeşitliliği:** temiz / hafif messy / ağır messy / çelişkili - **Muğlak cevap senaryoları** (%20): hasta önce belirsiz cevap verir, asistan netleştirir - **8 farklı senaryo stili:** yüz yüze triyaj, 112 araması, ambulansla geliş vb. - **Risk faktörleri:** diyabet, kalp hastası, hamilelik, hipertansiyon vb. | Split | Kayıt | |-------|-------| | Train | 5.180 | | Val | 646 | | Test | 648 | | **Toplam** | **6.474** | --- ## Fine-tuning Eğitim, Apple Silicon üzerinde MacBook M4 Pro 24GB kullanılarak tamamen yerel olarak **mlx-lm** ve **mlx-optiq** kütüphaneleri ile gerçekleştirildi. ``` Framework : mlx-lm 0.31.3 + mlx-optiq Yöntem : LoRA (r=8, alpha=16) İterasyon : 2000 Batch size : 4 Max seq len: 1024 Optimizer : AdamW Donanım : Apple Silicon (MacBook M4 Pro 24GB) ``` Val loss: **9.9 → 0.761** (2000 iterasyon) --- ## Değerlendirme Test seti: 648 örnek, tüm modeller aynı diyaloglar üzerinde, data leakage olmadan değerlendirildi. ### Genel Accuracy | Model | Accuracy | Doğru/Toplam | |-------|----------|--------------| | **Gemma 4 26B Fine-tuned (bizim)** | **75.0%** | 486/648 | | Gemini Flash 3.1 Lite | 73.5% | 476/648 | | GPT-5.4 | 71.3% | 462/648 | | GPT-4.1 | 70.2% | 455/648 | | GPT-4.1 mini | 60.8% | 394/648 | | Gemma 4 26B Base (fine-tune öncesi) | 56.8% | 25/50 | ### Per-Class Recall (Fine-tuned Model) | Sınıf | Recall | n | RED | YELLOW | GREEN | |-------|--------|---|-----|--------|-------| | RED | 76.0% | 317 | 241 | 72 | 4 | | YELLOW | 79.2% | 197 | 15 | 156 | 26 | | GREEN | 66.4% | 134 | 0 | 45 | 89 | > **Not:** RED→YELLOW karışması (%22.7) en kritik hata tipidir. Gerçek klinik kullanımda insan gözetimi zorunludur. --- ## Kullanım ### MLX ile (önerilen) ```bash pip install mlx-lm ``` ```python from mlx_lm import load, generate model, tokenizer = load("ai-triyaj/gemma4-26B-A4B-triage-turkish") SYSTEM = """Sen bir acil servis triyaj asistanısın. Hastayla Türkçe konuşarak şikayetini anlıyorsun. Her turda tek soru soruyorsun. Yeterli bilgiyi topladıktan sonra son mesajında nötr kapanış yap ve triyaj kararını söyle. Son mesaj formatı: "Bilgiler için teşekkürler, sizi ilgili birime yönlendiriyorum. Karar: RED/YELLOW/GREEN" Triyaj kararı: RED (kırmızı) = acil, YELLOW (sarı) = yarı acil, GREEN (yeşil) = acil değil.""" messages = [ {"role": "system", "content": SYSTEM}, {"role": "user", "content": "Göğsümde ağrı var"}, ] prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) response = generate(model, tokenizer, prompt=prompt, max_tokens=200) print(response) ``` ### Terminal Chat ```bash python -m mlx_lm.chat \ --model ai-triyaj/gemma4-26B-A4B-triage-turkish \ --system "Sen bir acil servis triyaj asistanısın. Hastayla Türkçe konuşarak şikayetini anlıyorsun. Her turda tek soru soruyorsun. Yeterli bilgiyi topladıktan sonra son mesajında nötr kapanış yap ve triyaj kararını söyle. Son mesaj formatı: 'Bilgiler için teşekkürler, sizi ilgili birime yönlendiriyorum. Karar: RED/YELLOW/GREEN' Triyaj kararı: RED (kırmızı) = acil, YELLOW (sarı) = yarı acil, GREEN (yeşil) = acil değil." ``` ## Sınırlamalar ve Uyarılar - Bu model **araştırma amaçlıdır**, klinik karar desteği için **insan gözetimi zorunludur** - Eğitim verisi sentetik olup gerçek hasta popülasyonunu tam temsil etmeyebilir - RED→YELLOW karışması (%22.7) hayati risk taşıyan vakalarda yanlış önceliklendirmeye yol açabilir - Model yalnızca **Türkçe** için optimize edilmiştir --- ## Teşekkür Bu projenin klinik temeli, **Dr. Altuğ Hasanbaşoğlu**'nun uzmanlığı ve katkılarıyla oluşturuldu. Türkiye acil servis pratiğine uygun triyaj karar ağaçlarının tasarımı, klinik kriterlerin belirlenmesi ve doğrulanması süreçlerindeki değerli katkıları için kendisine içtenlikle teşekkür ederiz. --- ## Lisans Bu model Google'ın [Gemma Lisansı](https://ai.google.dev/gemma/terms) kapsamındadır. --- --- # Gemma 4 26B A4B — Turkish Emergency Triage (English) ![AI-Triyaj](aitriyaj-banner.png) A conversational language model designed for Turkish emergency department triage, making **RED / YELLOW / GREEN** triage decisions through natural dialogue with patients in Turkish. > **Base model:** `mlx-community/gemma-4-26B-A4B-it-OptiQ-4bit` > **Fine-tuning:** LoRA (mlx-lm + mlx-optiq), 2000 iterations > **Format:** 4-bit quantized safetensors (fused, no separate adapter needed) --- ## Overview Global triage systems such as CTAS and ESI are designed for broad patient populations and wide clinical scenarios, often requiring lengthy assessment workflows. This model was built specifically for Turkish emergency department practice — guiding patients through fast, focused, and symptom-specific questions that cut straight to the decision point without unnecessary steps. It engages patients in natural Turkish dialogue, collects clinical information, and outputs a triage decision. | Decision | Meaning | |----------|---------| | 🔴 RED | Critical — requires immediate intervention | | 🟡 YELLOW | Semi-urgent — should be seen shortly | | 🟢 GREEN | Non-urgent — can wait | --- ## Model Architecture - **Gemma 4 26B A4B** (Mixture-of-Experts): 26B total parameters, 4B active per token - **4-bit OptiQ quantization**: sensitivity-aware mixed-precision (attention layers at 8-bit, MLP at 4-bit) - **LoRA fine-tuning**: only adapter weights were trained, then merged into the base model (fused) --- ## Training Data The training data was developed in collaboration with an emergency medicine physician. Our physician designed **decision trees (paths)** for 117 complaint categories (chest pain, shortness of breath, abdominal pain, etc.), grounded in CTAS/ESI protocols and adapted to Turkish emergency practice. Each path defines which questions to ask, which answers lead to which triage decision, and which symptoms immediately trigger a RED classification. Based on these paths, **6,475 synthetic Turkish dialogues** were generated using Gemini: - **441 decision paths** across 117 complaint categories - **Patient profile diversity:** clean / mildly messy / severely messy / contradictory - **Ambiguous response scenarios** (20%): patient gives vague answer, assistant clarifies - **8 scenario styles:** face-to-face triage, emergency call, ambulance arrival, etc. - **Risk factors:** diabetes, cardiac history, pregnancy, hypertension, etc. | Split | Records | |-------|---------| | Train | 5,180 | | Val | 646 | | Test | 648 | | **Total** | **6,474** | --- ## Fine-tuning Training was performed entirely locally on Apple Silicon using **mlx-lm** and **mlx-optiq**: ``` Framework : mlx-lm 0.31.3 + mlx-optiq Method : LoRA (r=8, alpha=16) Iterations : 2000 Batch size : 4 Max seq len: 1024 Optimizer : AdamW Hardware : Apple Silicon (MacBook M4 Pro 24GB) ``` Val loss: **9.9 → 0.761** (2000 iterations) --- ## Evaluation Test set: 648 samples, all models evaluated on the same dialogues with no data leakage. ### Overall Accuracy | Model | Accuracy | Correct/Total | |-------|----------|---------------| | **Gemma 4 26B Fine-tuned (ours)** | **75.0%** | 486/648 | | Gemini Flash 3.1 Lite | 73.5% | 476/648 | | GPT-5.4 | 71.3% | 462/648 | | GPT-4.1 | 70.2% | 455/648 | | GPT-4.1 mini | 60.8% | 394/648 | | Gemma 4 26B Base (before fine-tuning) | 56.8% | 25/50 | ### Per-Class Recall (Fine-tuned Model) | Class | Recall | n | RED | YELLOW | GREEN | |-------|--------|---|-----|--------|-------| | RED | 76.0% | 317 | 241 | 72 | 4 | | YELLOW | 79.2% | 197 | 15 | 156 | 26 | | GREEN | 66.4% | 134 | 0 | 45 | 89 | > **Note:** RED→YELLOW confusion (22.7%) is the most critical error type. Human oversight is mandatory for any real clinical use. --- ## Usage ### With MLX (recommended) ```bash pip install mlx-lm ``` ```python from mlx_lm import load, generate model, tokenizer = load("ai-triyaj/gemma4-26B-A4B-triage-turkish") SYSTEM = """You are an emergency department triage assistant. Speak with the patient in Turkish to understand their complaint. Ask one question per turn. Once you have gathered enough information, close with a neutral statement and give the triage decision. Final message format: "Bilgiler için teşekkürler, sizi ilgili birime yönlendiriyorum. Karar: RED/YELLOW/GREEN" Triage decision: RED = critical, YELLOW = semi-urgent, GREEN = non-urgent.""" messages = [ {"role": "system", "content": SYSTEM}, {"role": "user", "content": "Göğsümde ağrı var"}, ] prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) response = generate(model, tokenizer, prompt=prompt, max_tokens=200) print(response) ``` ### Terminal Chat ```bash python -m mlx_lm.chat \ --model ai-triyaj/gemma4-26B-A4B-triage-turkish \ --system "Sen bir acil servis triyaj asistanısın. Hastayla Türkçe konuşarak şikayetini anlıyorsun. Her turda tek soru soruyorsun. Yeterli bilgiyi topladıktan sonra son mesajında nötr kapanış yap ve triyaj kararını söyle. Son mesaj formatı: 'Bilgiler için teşekkürler, sizi ilgili birime yönlendiriyorum. Karar: RED/YELLOW/GREEN' Triyaj kararı: RED (kırmızı) = acil, YELLOW (sarı) = yarı acil, GREEN (yeşil) = acil değil." ``` ### LM Studio 1. LM Studio → Search 2. Search for `ai-triyaj/gemma4-26B-A4B-triage-turkish` 3. Download and launch --- ## System Requirements | Hardware | Status | |----------|--------| | Apple Silicon M2 Pro (16GB) | ✅ Works | | Apple Silicon M3/M4 (16GB+) | ✅ Recommended | | CUDA GPU (8GB+) | Works via PyTorch safetensors | --- ## Limitations & Warnings - This model is intended for **research purposes only** — human oversight is mandatory for clinical decision support - Training data is synthetic and may not fully represent real patient populations - RED→YELLOW confusion (22.7%) may lead to incorrect prioritization in life-threatening cases - The model is optimized for **Turkish only** --- ## Acknowledgements The clinical foundation of this project was built with the expertise and contributions of **Dr. Altuğ Hasanbaşoğlu**. We sincerely thank him for designing the triage decision trees adapted to Turkish emergency practice, defining the clinical criteria, and validating the decision logic throughout the project. --- ## License This model is subject to Google's [Gemma License](https://ai.google.dev/gemma/terms).