KTO (Kahneman-Tversky Optimization): Pair Değil Tek-Yönlü Feedback'ten Alignment
KTO (Ethayarajh et al. 2024) — production deploy'da en çok karşılaşılan feedback: 'thumbs up' / 'thumbs down'. Pair değil. Klasik DPO bu data ile çalışmaz. KTO bu boşluğu doldurur: prospect theory (Kahneman-Tversky) ile utility function. Production'da continuous learning loop.
Şükrü Yusuf KAYA
28 dakikalık okuma
İleri1. KTO Dataset Format#
{ "prompt": "Ankara'nın nüfusu nedir?", "completion": "Yaklaşık 5.6 milyon (2024 verisi).", "label": true // true = thumbs-up (good), false = thumbs-down (bad) }
Pair gerek yok. Production'da:
- Kullanıcı response gördü, thumbs-up dedi →
label: true - Thumbs-down dedi →
label: false
Avantaj: Pair toplamak 5-10x daha pahalı (annotator iki cevap karşılaştırması) vs single label. KTO production-scale feedback için ideal.
2. KTO Loss — Prospect Theory'den#
Kahneman-Tversky'nin utility function (insan tercihinin asimetrik modellemesi):
- Gains: (α < 1, concave)
U(g) = g^α - Losses: (λ > 1, kayıp 2.25x kazanç kadar acı verir)
U(l) = -λ |l|^α
KTO'ya uyarlanmış:
L_KTO = -E_yes[w_yes · σ(β · r(x, y) - z_yes)] -E_no [w_no · σ(z_no - β · r(x, y))] r(x, y) = log(π_θ(y|x) / π_ref(y|x)) # DPO-style implicit reward z_yes, z_no = utility thresholds (KTO hyperparams) w_yes, w_no = sample weights (true/false ratio için balance)
Cookbook hyperparam: β=0.1, w_yes=w_no=1 (eğer dataset balanced ise).
python
# === KTO Lab — TRL KTOTrainer ===from trl import KTOConfig, KTOTrainerfrom datasets import Dataset # 1. Production thumbs data (örnek)production_data = [ {"prompt": "İstanbul nüfusu?", "completion": "Yaklaşık 15 milyon.", "label": True}, {"prompt": "İstanbul nüfusu?", "completion": "Bilmiyorum.", "label": False}, # ... 5000+ örnek]dataset = Dataset.from_list(production_data) # 2. Configcfg = KTOConfig( output_dir="llama-3.1-8b-kto", num_train_epochs=2, per_device_train_batch_size=4, gradient_accumulation_steps=4, learning_rate=5e-6, bf16=True, optim="paged_adamw_8bit", max_length=4096, max_prompt_length=2048, beta=0.1, desirable_weight=1.0, # w_yes undesirable_weight=1.0, # w_no logging_steps=5, report_to="wandb",) trainer = KTOTrainer(model=model, args=cfg, train_dataset=dataset, tokenizer=tok)trainer.train()KTO Lab — TRL
✅ Teslim
- Sentetik thumbs-up/down dataset üret. 2) KTO ile FT et. 3) Aynı modelde DPO ile karşılaştır. 4) Sonraki ders: 11.6 — DPO Family: SimPO, IPO, CPO, RPO.
Yorumlar & Soru-Cevap
(0)Yorum yazmak için giriş yap.
Yorumlar yükleniyor...
İlgili İçerikler
Part 0 — Engineering Foundations
Fine-Tuning Cookbook'a Hoş Geldin: Sistematik, Stage Taksonomisi ve Reproducibility Kontratı
Öğrenmeye BaşlaPart 0 — Engineering Foundations
Reproducibility Stack: Seeds, cuDNN Flags ve Deterministic CUDA — 'Sende Niye Çalışıyor Bende Çalışmıyor' Sorununu Bitir
Öğrenmeye BaşlaPart 0 — Engineering Foundations