TinyTurk v2.7d - Command Agent
1.1M-parameter Turkish GPT that turns natural language into structured commands.
Model Description
TinyTurk Command Agent is a 1.1M-parameter Turkish language model that maps free-form Turkish input (e.g. sesi yukselt) to a structured command label (e.g. volume up). It runs locally on CPU or GPU and requires no API.
The same architecture, when trained on knowledge or abstract syntax tasks, performs near chance. On the command agent task it reaches 87.5% live accuracy with only 302 training examples.
- Developed by: stunmuffin
- Model type: Decoder-only Transformer (GPT-style), intent classification
- Language: Turkish
- License: Apache 2.0
Architecture
- Tokenizer: 512 BPE (SentencePiece, Turkish)
- Context length: 64
- Embedding: 128
- Layers: 4
- Heads: 4
- FFN: 128 -> 512 -> 128
- Micro-FFN: 128 -> 256 -> 128 (gated, gate=0.75)
- Position encoding: RoPE
- Normalization: RMSNorm (pre-norm)
- Weight tying: yes
- Parameters: 1,121,920
Training
- Data: 302 generated Turkish examples (241 train / 30 val / 31 test)
- Format:
komut: <input> cikti: <label> - Labels: 16 commands +
yok(unknown) - Epochs: 50
- Batch size: 16
- Learning rate: 3e-4, cosine, 10% warmup
- Hardware: NVIDIA GTX 1080 Ti
- Training time: ~5 minutes
- Best val loss: 0.5536
Command Set
| Turkish intent (examples) | Output label | Action |
|---|---|---|
| CMD ac / komut istemi | open cmd | start cmd.exe |
| not defteri ac | open notepad | start notepad.exe |
| hesap makinesi ac | open calc | start calc.exe |
| tarayici ac | open browser | start chrome |
| dosya gezgini ac | open explorer | start explorer.exe |
| boya programi ac | open paint | start mspaint.exe |
| gorev yoneticisi ac | open taskmgr | start taskmgr.exe |
| sesi yukselt / ses ac | volume up | volume + |
| sesi kis | volume down | volume - |
| sesi kapat | volume mute | mute |
| bilgisayari kapat | shutdown | shutdown /s |
| yeniden baslat | restart | shutdown /r |
| ekrani kilitle | lock | LockWorkStation |
| ekran goruntusu al | screenshot | (placeholder) |
| masaustunu goster | show desktop | Win+D |
| uyku moduna al | sleep | suspend |
| (out of domain) | yok | do nothing |
Evaluation
Live demo (8 inputs):
| Input | Predicted | Correct? |
|---|---|---|
| ses ac | volume up | yes |
| cmd ac | open cmd | yes |
| sesi kis | volume down | yes |
| not defteri ac | open notepad | yes |
| note ac | open notepad | yes |
| bugun hava nasil | yok | yes |
| hava nasil | yok | yes |
| ses 20 | volume mute | no |
Live accuracy: 7/8 = 87.5%
Usage
Inference (label only)
import torch
import sentencepiece as spm
from model import TinyTurkGPTV27, TinyTurkV27Config
tok = spm.SentencePieceProcessor()
tok.load('tokenizer_v11_bpe_512.model')
config = TinyTurkV27Config(vocab_size=512, context_length=64)
model = TinyTurkGPTV27(config)
model.load_state_dict(torch.load('pytorch_model.bin', map_location='cpu'))
model.eval()
user_input = 'sesi yukselt'
prefix = f'komut: {user_input} cikti:'
prefix_ids = tok.encode(prefix, out_type=int)
ids = list(prefix_ids)
x = torch.tensor([ids], dtype=torch.long)
with torch.no_grad():
for _ in range(15):
logits, _ = model(x[:, -64:])
nid = torch.argmax(logits[0, -1, :]).item()
ids.append(nid)
x = torch.tensor([ids], dtype=torch.long)
output = tok.decode(ids[len(prefix_ids):]).strip()
print(output)
Prefix matcher
The model often emits label + noise, e.g. volume upen cmdownetic. Apply a prefix matcher:
OUTPUT_MAP = {
'open cmd': 'open_CMD',
'open notepad': 'open_NOTEPAD',
'volume up': 'volume_up',
'volume down': 'volume_down',
'volume mute': 'volume_mute',
'shutdown': 'shutdown',
'restart': 'restart',
'yok': 'unknown',
# ...
}
for key in sorted(OUTPUT_MAP, key=len, reverse=True):
if output.startswith(key):
return OUTPUT_MAP[key]
Voice Agent
A voice-controlled version of this agent is also available. Full pipeline:
Microphone -> Whisper (STT, Turkish) -> TinyTurk Agent -> Action
Architecture
| Component | Technology |
|---|---|
| Audio capture | sounddevice + WASAPI (48 kHz) |
| Resampling | librosa (48 kHz -> 16 kHz) |
| Speech-to-Text | OpenAI Whisper (small) |
| Intent model | this model (TinyTurk v2.7d Command Agent) |
| Action layer | subprocess |
All components run locally, no API, no cloud.
Live results (23 voice commands)
- 14/14 valid commands correctly recognized
- 5/5 out-of-domain inputs correctly rejected
- Confidence threshold 0.5 gives clean separation
Whisper configuration
Critical setting: an initial_prompt with Turkish command examples. Without it, Whisper hallucinates filler on short clips ("Se, se, se"). With it, recognition is exact.
Significance
To our knowledge, this is the first voice-controlled agent built on a 1M-parameter language model. No cloud, no API, runs on a single GTX 1080 Ti.
Try it
import subprocess
import sounddevice as sd
import librosa
import numpy as np
import whisper
import torch
import sentencepiece as spm
from model import TinyTurkGPTV27, TinyTurkV27Config
# 1) Record audio
DEVICE_ID = 63 # your microphone (find with: sd.query_devices())
SR = 48000
audio = sd.rec(int(4 * SR), samplerate=SR, channels=1,
dtype="float32", device=DEVICE_ID)
sd.wait()
# 2) Resample to 16 kHz
audio = librosa.resample(audio.flatten(), orig_sr=SR, target_sr=16000)
# 3) Whisper STT
whisper_model = whisper.load_model("small")
result = whisper_model.transcribe(
audio.astype(np.float32),
language="tr",
initial_prompt="sesi yükselt, sesi kıs, cmd aç, not defterini aç",
condition_on_previous_text=False,
temperature=0.0,
)
text = result["text"].strip()
print(f"Heard: {text!r}")
# 4) TinyTurk intent
tok = spm.SentencePieceProcessor()
tok.load("tokenizer_v11_bpe_512.model")
config = TinyTurkV27Config(vocab_size=512, context_length=64)
model = TinyTurkGPTV27(config)
model.load_state_dict(torch.load("pytorch_model.bin", map_location="cpu"))
model.eval()
prefix = f"komut: {text} çıktı:"
ids = tok.encode(prefix, out_type=int)
with torch.no_grad():
for _ in range(15):
logits, _ = model(torch.tensor([ids[-64:]], dtype=torch.long))
nid = torch.argmax(logits[0, -1, :]).item()
ids.append(nid)
output = tok.decode(ids[len(tok.encode(prefix, out_type=int)):]).strip()
print(f"Predicted: {output!r}")
Safety
- The deployment script disables destructive commands (
shutdown,restart,lock,sleep) and prints[TEST]instead. - In production: require user confirmation for destructive commands, set a confidence threshold, log every action, never run with admin privileges.
Known Limitations
- 16 commands only (not a general assistant)
- Single-turn (no multi-step plans)
- No parameter passing
- Prefix matching is a workaround
Scientific Context
This model is part of the TinyTurk series. The same 1M-parameter architecture was tested on:
| Task | Result |
|---|---|
| TurkishMMLU (knowledge) | near chance |
| BLiMP (abstract syntax) | near chance |
| Command agent | 87.5% live |
Conclusion: For tiny models, task selection matters more than model size. Narrow formal tasks (like intent classification) are well within reach of 1M parameters, while open-ended knowledge or reasoning tasks are not.
Files
| File | Content |
|---|---|
examples/train.txt |
241 training examples |
examples/val.txt |
30 validation examples |
examples/test.txt |
31 test examples |
Citation
@misc{tinyturk-v27d-agent,
title = {TinyTurk v2.7d - Command Agent},
author = {stunmuffin},
year = {2026},
howpublished = {https://huggingface.co/stunmuffin/tinyturk-v2.7d-agent}
}
Related
- Turkish baseline (k_hikaye): stunmuffin/tinyturk-v2.7d-k-hikaye-baseline
- English TinyStories: stunmuffin/tinyturk-v2.7d-tinystories-en
- Downloads last month
- 21