Çok Sınıflı Problemler için Çapraz Entropi
Neden softmax yerine ham logitler beklediği.
Çok Sınıflı Problemler için Çapraz Entropi, CoddyKit'te ücretsiz bir Deep Learning Academy dersidir. Bu, 4 dersinin 3. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Deep Learning Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Deep Learning Academy kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
More Than Two Choices
When your model must pick one label from many, like a digit 0 through 9, you use cross-entropy, the standard multiclass classification loss. 🔢
One Logit Per Class
For C classes, your network outputs a vector of C raw scores called logits, one per possible class, for every sample in the batch.
Softmax Turns Scores Into Odds
Softmax exponentiates each logit and normalizes them so they sum to 1, turning raw scores into a clean probability distribution.
import torch
probs = torch.softmax(logits, dim=1)The Loss for Many Classes
PyTorch bundles softmax and the loss into nn.CrossEntropyLoss. It scores how much probability your model put on the correct class.
import torch.nn as nn
loss_fn = nn.CrossEntropyLoss()Pass Raw Logits Directly
This is the key rule: feed CrossEntropyLoss the raw logits, never a softmax output. It applies log-softmax internally for you.
loss = loss_fn(logits, labels)Why Not Softmax First
Applying softmax yourself, then this loss, squashes the values twice. That double pass distorts gradients and quietly wrecks training.
Labels Are Class Indices
Your targets are plain integer indices, like 3 for class three, not one-hot vectors. PyTorch handles the lookup for you.
labels = torch.tensor([3, 0, 7])Mind the Output Shape
Logits have shape batch by classes, while labels have shape batch only. A shape mismatch here is the most common cross-entropy error.
It Is Built From Two Pieces
Under the hood, CrossEntropyLoss equals log-softmax followed by negative log-likelihood. Fusing them keeps the math numerically stable.
Predict With Argmax
To get the final answer, take the argmax over the logits. The largest score is the predicted class, no softmax needed.
preds = logits.argmax(dim=1)Smooth Labels for Generalization
Setting label_smoothing nudges targets slightly away from a hard 1, which discourages overconfidence and often improves test accuracy.
loss_fn = nn.CrossEntropyLoss(label_smoothing=0.1)Quick Check
You are using nn.CrossEntropyLoss for 10 classes. What should the model's final output be?
Recap: One Winner Per Sample
For multiclass tasks you feed raw logits and integer labels to CrossEntropyLoss, which softmaxes internally and scores the right class. Argmax gives the prediction. 🏆
Sıkça Sorulan Sorular
“Çok Sınıflı Problemler için Çapraz Entropi” dersi ücretsiz mi?
Evet — “Çok Sınıflı Problemler için Çapraz Entropi” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Deep Learning Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Deep Learning Academy kursu toplamda 4 dersten oluşur.
“Çok Sınıflı Problemler için Çapraz Entropi” dersinde ne öğreneceğim?
Neden softmax yerine ham logitler beklediği. Deep Learning Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Deep Learning Academy öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Deep Learning Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 3. dersidir.
“Çok Sınıflı Problemler için Çapraz Entropi” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Deep Learning Academy dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Deep Learning Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Regresyon için MSE ve MAE
- Logitlerle İkili Çapraz Entropi
- Çok Sınıflı Problemler için Çapraz Entropi
- Dengesiz Veriler için Sınıf Ağırlıkları