File size: 10,078 Bytes
06f1504
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3e02e98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
06f1504
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
---
language:
- tr
license: mit
library_name: transformers
pipeline_tag: text-generation
tags:
- turkish
- chain-of-thought
- reasoning
- thinking
- cot
- fine-tuned
- experimental
- kayra
datasets:
- sixfingerdev/kayra-thinking-data
base_model: sixfingerdev/kayra-1-exp
---

# 🧠 Kayra-1-Thinking-Exp

**A thinking Turkish language model — Chain-of-Thought reasoning fine-tune of Kayra-1-exp**

This is an experimental fine-tune of [sixfingerdev/kayra-1-exp](https://huggingface.co/sixfingerdev/kayra-1-exp) (86.4M parameters) on a **chain-of-thought reasoning** dataset. It learns to produce step-by-step reasoning within `<|think|>` tags before generating the final answer.

### Model Details

| Property | Value |
|----------|-------|
| **Base Model** | [sixfingerdev/kayra-1-exp](https://huggingface.co/sixfingerdev/kayra-1-exp) |
| **Parameters** | ~86.4M (106.8M with copied tied embeddings) |
| **Architecture** | Transformer Decoder (GPT-style), 10 layers, 640 hidden, 10 heads |
| **Context Length** | 512 tokens |
| **Vocabulary** | 32,000 BPE tokens |
| **Training Data** | [kayra-thinking-data](https://huggingface.co/datasets/sixfingerdev/kayra-thinking-data) (4,191 Turkish reasoning examples) |
| **Version** | Experimental (exp) |

### Training

| Hyperparameter | Value |
|----------------|-------|
| Epochs | 5 |
| Batch Size | 8 (per device) |
| Learning Rate | 5e-5 |
| Scheduler | Cosine (20 steps warmup) |
| Optimizer | AdamW |
| Precision | FP16 |
| Train / Eval Split | 95% / 5% (3,981 / 210) |
| Total Steps | 2,490 |

Eval loss decreased from 2.73 → **2.25** over 5 epochs.

### Dataset

Trained on [kayra-thinking-data](https://huggingface.co/datasets/sixfingerdev/kayra-thinking-data): a curated collection of 4,191 Turkish reasoning examples combining 4 sources — duxx (226), efe (350), Gemma-4 generated (32), and ThinkingData-200K-Turkish (~3,583).

Format:
```text
### Soru: <question>

### Yanit: <|think|><step-by-step reasoning></|think|><final answer>
```

### Usage

```python
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained(
    "sixfingerdev/kayra-1-thinking-exp",
    trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained("sixfingerdev/kayra-1-thinking-exp")

prompt = "### Soru: Türkiye'nin başkenti neresidir?\n\n### Yanit: <|think|>"
inputs = tokenizer(prompt, return_tensors="pt")

outputs = model.generate(
    **inputs,
    max_new_tokens=120,
    do_sample=True,
    temperature=0.3,
    top_k=40,
    repetition_penalty=1.2,
    pad_token_id=tokenizer.pad_token_id,
)
```

Recommended generation parameters: `temperature=0.3`, `top_k=40`, `repetition_penalty=1.2`, `max_new_tokens=100-150`.

### Known Limitations

1. **Model capacity**: 86M parameters is too small for reliable complex reasoning. The model learns the *format* of thinking but struggles with *correct logical inference*.
2. **Function-call contamination**: The ThinkingData-200K source contains tool/API call examples. The model may occasionally generate function-call syntax (`get_name_by_id`, `tool_call`).
3. **Repetition**: Like most small models, it can enter repetitive loops. Use `repetition_penalty` to mitigate.
4. **Tokenizer spacing**: BPE subword tokenization can introduce spaces in Turkish words ("soruyor" → "sor uyor", "düşüneyim" → "düşün eyim").
5. **No factuality guarantee**: This is an experimental model. Do not use in production without verification.

---

# 🧠 Kayra-1-Thinking-Exp (Türkçe)

**Düşünen Türkçe model — Chain-of-Thought reasoning fine-tune of Kayra-1-exp**

Bu model, `sixfingerdev/kayra-1-exp` (86.4M parametre) üzerine **chain-of-thought reasoning** formatında fine-tune edilmiş deneysel bir sürümdür. `<|think|>` etiketleri arasında adım adım muhakeme yapıp ardından nihai cevabı üretmeyi öğrenir.

---

## 📊 Model Details

| Özellik | Değer |
|---------|-------|
| **Base Model** | [sixfingerdev/kayra-1-exp](https://huggingface.co/sixfingerdev/kayra-1-exp) |
| **Parametreler** | ~86.4M (106.8M with tied embeddings copied) |
| **Mimari** | Transformer Decoder (GPT-style), 10 katman, 640 hidden, 10 heads |
| **Context Length** | 512 token |
| **Vocabulary** | 32,000 BPE token |
| **Eğitim Verisi** | [kayra-thinking-data](https://huggingface.co/datasets/sixfingerdev/kayra-thinking-data) (4,191 Türkçe reasoning örneği) |
| **Sürüm** | Experimental (exp) |

---

## 📈 Training Details

### Hyperparameters

| Parametre | Değer |
|-----------|-------|
| Epochs | 5 |
| Batch Size | 8 (per device) |
| Learning Rate | 5e-5 |
| Scheduler | Cosine (20 step warmup) |
| Optimizer | AdamW |
| Precision | FP16 |
| Train / Eval Split | 95% / 5% (3,981 / 210) |
| Total Steps | 2,490 |

### Training Metrics

| Step | Train Loss | Eval Loss |
|------|-----------|-----------|
| 200 | 4.26 | 2.73 |
| 400 | 3.87 | 2.54 |
| 600 | 3.72 | 2.45 |
| 800 | 3.60 | 2.38 |
| 1000 | 3.43 | 2.33 |
| 1200 | 3.28 | 2.30 |
| 1400 | 3.18 | 2.28 |
| 1600 | 3.04 | 2.27 |
| 1800 | 2.93 | 2.26 |
| 2000 | 2.83 | 2.25 |
| 2200 | 2.65 | 2.25 |
| 2400 | 2.60 | **2.248** |
| 2490 | 2.56 | 2.248 |

Loss monotonik olarak düştü, eval loss 2.25'te plateu yaptı. Daha fazla epoch overfitting riski taşır.

### Weight Tying Fix

Kayra-1-exp'in checkpoint'ında `lm_head.weight` bulunmaz (`tie_word_embeddings=True`). Eğitim öncesi `lm_head.weight.data.copy_(model.tok_emb.weight.data)` ile embedding ağırlıkları kopyalanır. Transformers 5.x'te `tie_word_embeddings=False` ile kaydedilir, böylece checkpoint save hatası önlenir.

---

## 📦 Dataset

Fine-tune verisi: **[kayra-thinking-data](https://huggingface.co/datasets/sixfingerdev/kayra-thinking-data)**

4 kaynaktan derlenmiş, dedupe edilmiş 4,191 Türkçe reasoning örneği:

| Kaynak | Adet | Açıklama |
|--------|------|----------|
| duxx | 226 | Türkçe matematik problemleri + CoT çözüm |
| efe | 350 | Türkçe matematik reasoning |
| Gemma-4 (E2B-it) | 32 | Gemma ile üretilip Türkçeleştirilmiş |
| ThinkingData-200K-Turkish | ~3,583 | İngilizce ThinkingData-200K'nın Türkçe çevirisi |

Her örnek şu formattadır:

```text
### Soru: <soru>

### Yanit: <|think|><adım adım muhakeme></|think|><nihai cevap>
```

---

## 🚀 Usage

### Yükleme

```python
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained(
    "sixfingerdev/kayra-1-thinking-exp",
    trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained("sixfingerdev/kayra-1-thinking-exp")
```

### Generate

```python
prompt = "### Soru: Türkiye'nin başkenti neresidir?\n\n### Yanit: <|think|>"
inputs = tokenizer(prompt, return_tensors="pt")

outputs = model.generate(
    **inputs,
    max_new_tokens=120,
    do_sample=True,
    temperature=0.3,
    top_k=40,
    repetition_penalty=1.2,
    pad_token_id=tokenizer.pad_token_id,
)

generated = outputs[0][inputs.input_ids.shape[1]:]
print(tokenizer.decode(generated, skip_special_tokens=False))
```

**Önerilen generation parametreleri:**
- `temperature`: 0.3-0.4 (düşük = daha deterministik)
- `top_k`: 40
- `repetition_penalty`: 1.15-1.25 (tekrarlamayı azaltır)
- `max_new_tokens`: 100-150 (512 context sınırı)
- `do_sample`: True

### Output Format

Model çıktısı şu pattern'i takip eder:

```
<|think|>Öncelikle, <adım 1>. Sonra, <adım 2>. ... </|think|><nihai cevap>
```

Not: Model bazen `</|think|>` kapatma etiketi üretmez. Bu durumda tüm çıktı thinking aşaması olarak kabul edilmelidir.

---

## ⚠️ Limitations & Known Issues

### 1. Model Kapasitesi
86M parametre karmaşık muhakeme için çok küçüktür. Model **muhakeme formatını** öğrenir ancak **doğru mantıksal çıkarımı** tutarlı şekilde yapamaz.

### 2. Function-Call Contamination
ThinkingData-200K verisi tool/API çağrısı formatında örnekler içerir. Model bazen `get_name_by_id`, `tool_call` gibi fonksiyon çağrısı syntax'ı üretebilir.

### 3. Tekrarlama (Repetition)
Küçük modellerde yaygın olduğu gibi, model uzun generation'larda tekrara girebilir. `repetition_penalty` ve `no_repeat_ngram_size` ile kontrol edilebilir.

### 4. Tokenizer Spacing
BPE tokenizer bazı kelimelerde boşluk ekler ("soruyor" → "sor uyor", "düşüneyim" → "düşün eyim"). Bu, tokenizer'ın alt kelime bölümlemesinden kaynaklanır ve model çıktısında görülebilir.

### 5. Doğruluk Garantisi Yok
Bu deneysel bir modeldir. Ürettiği bilgilerin doğruluğu garanti edilmez. Production kullanımı için uygun değildir.

---

## 🧪 Sample Outputs

### Türkiye'nin başkenti neresidir?
```
Tamam, kullanıcı Türkiye'nin başkentini soruyor. Türkiye'nin başkenti nedir ve nerede olduğunu bilmek istiyorlar. Kullanılabilir işlevleri kontrol edeyim...
```
→ Doğru yanıtı üretmekte zorlanır, function-call pattern'ine kayar.

### 2+2 kaç eder?
```
Doğrudan sonuca atlamadan önce verilenleri düzenli okuyorum. İlk olarak, ikinci veya üçüncü şahıs zamirlerinden kaçınmam gerekiyor...
```
→ </|think|> kapatır ama matematiksel doğruluk zayıftır.

---

## 🔬 Comparison: Base vs Fine-tuned

| Özellik | kayra-1-exp (base) | kayra-1-thinking-exp |
|---------|-------------------|---------------------|
| Loss | 3.75 (base eval) | 2.25 (fine-tune eval) |
| Reasoning Format | Yok | `<|think|>` CoT formatı |
| Yanıt Yapısı | Serbest metin | Soru → Düşünce → Cevap |
| Doğruluk | Düşük (85M hallücinasyon) | Düşük (kapasite sınırı) |

---

## 📜 License

MIT License — Ticari ve akademik kullanım serbesttir.

---

## 🙏 Acknowledgments

- **Base model**: [sixfingerdev/kayra-1-exp](https://huggingface.co/sixfingerdev/kayra-1-exp) — Sıfırdan Türkçe eğitilmiş GPT
- **Dataset**: [kayra-thinking-data](https://huggingface.co/datasets/sixfingerdev/kayra-thinking-data)
- **Framework**: PyTorch, HuggingFace Transformers
- **Inspired by**: DeepSeek-R1, ThinkingData-200K

---

**Kayra-1-Thinking-Exp***Küçük modeller de düşünebilir* 🧠