LESSON 44 OF 52 · CHAPTER 06

Classification Loss

Scalar categorical loss and selecting maximum score index

ORIGINAL SOURCE

03-classification-loss.srp

// Stable categorical loss from logits without a softmax vector.
bind logits = [4.0];
bind label = 0;
print(crossentropy(logits, label));
print(logprob(logits, label));
// For multiple classes, select a class by its original index:
print(argmax([1.0, 4.0, 2.0]));
EXPECTED OUTPUT

stdout

Verified
0.0
-0.0
1

UNDERSTAND THE CODE

Explanation & practice

What this example teaches

Scalar categorical loss and selecting maximum score index

Expected behavior

0.0, -0.0, 1

Practice: Read the source before looking at the output. Predict the values and their order, then use the pinned compiler to execute this lesson and compare the exact fixture. Identify which operation produces the result.

वर्गीकरण लॉस

crossentropy(logits, label) और logprob(logits, label) को एक वर्ग की संख्याओं पर चलाया गया है। argmax([1.0, 4.0, 2.0]) बड़े स्कोर का इंडेक्स लौटाता है। ये अंकगणितीय उदाहरण हैं, न कि प्रशिक्षित वर्गीकरण मॉडल।

आउटपुट: 0.0, -0.0 और 1 तीन पंक्तियों में। -0.0 का स्वरूप भी stdout फ़िक्स्चर का हिस्सा है।

अभ्यास: argmax का परिणाम 4.0 के बजाय 1 क्यों है?

Explanations are sourced from the project's English chapter guide and हिन्दी अध्याय. The Scarp program and output are unchanged.

SOURCE-BACKED SELF-CHECK · स्रोत-आधारित अभ्यास

Quick checkpoint / त्वरित अभ्यास

Which index does argmax([1.0, 4.0, 2.0]) print?argmax([1.0, 4.0, 2.0]) कौन-सा index प्रिंट करता है?

Reveal the source-backed answer / सही उत्तर देखें

1 — The maximum value is 4.0, which is at zero-based index 1. The fixture prints 1.1 — सबसे बड़ा मान 4.0 है, जो शून्य-आधारित index 1 पर है। इसलिए आउटपुट 1 है.

This question checks understanding of a recorded compiler output. It does not run Scarp in the browser. यह प्रश्न सत्यापित आउटपुट पर आधारित है; ब्राउज़र में Scarp नहीं चलता।

TRY IT LOCALLY

Verify, then execute

Use the pinned compiler from the course root. Keep any imported _support files next to the source.

scarp verify examples/06-ai-foundations/03-classification-loss.srp scarp exec examples/06-ai-foundations/03-classification-loss.srp

The website does not run code. Read the CLI guide ↗

Pinned compiler: Scarp v0.0.6-alpha.3 · ceff07d9014f. No simulated output.