GUIDED LAB 06 OF 06 · VERIFIED SCARP

Choose a class as a one-hot vector

वर्ग को one-hot वेक्टर में बदलें

The challenge · अभ्यास

The starter prints the winning class index. Instead, print a one-hot vector identifying the largest score among [1.0, 4.0, 2.0].

स्टार्टर विजेता वर्ग का index प्रिंट करता है। इसके बजाय [1.0, 4.0, 2.0] में सबसे बड़े स्कोर को दर्शाने वाला one-hot वेक्टर प्रिंट करें।

EDIT THIS STARTER

starter.srp

// Lab: output a one-hot vector rather than only its winning index.
bind scores = [1.0, 4.0, 2.0];
print(argmax(scores));
MATCH THIS VERIFIED OUTPUT

solution.stdout

Compiler fixture
[0.0, 1.0, 0.0]

Run and check your attempt locally

Copy starter.srp to attempt.srp in the same lab folder, edit it, and use the pinned Scarp compiler from the repository root. Keeping the same folder is important for imports and the bundled _support helper.

scarp verify labs/06-ai-foundations/attempt.srp scarp exec labs/06-ai-foundations/attempt.srp

Compare the printed output with the fixture shown above. No website execution, uploads or stored answers are involved.

Show hint · संकेत देखें

Combine len(scores), argmax(scores) and the onehot function supported by the pinned compiler.

पिन किए गए कंपाइलर के len(scores), argmax(scores) और onehot फ़ंक्शन को साथ इस्तेमाल करें।

Reveal tested solution · सत्यापित हल देखें
// Create a one-hot vector for the class with the highest score.
bind scores = [1.0, 4.0, 2.0];
print(onehot(len(scores), argmax(scores)));

The largest score is at index 1, so onehot(3, 1) returns [0.0, 1.0, 0.0].

सबसे बड़ा स्कोर index 1 पर है, इसलिए onehot(3, 1) का परिणाम [0.0, 1.0, 0.0] है।

Reference .srp on GitHub ↗

OPTIONAL · COMPILER-VERIFIED STRETCH

Rank candidates with temperature

टेम्परेचर से स्कोर रैंक करें

The starter prints only a two-way probability vector. Extend it to print a single-score log probability, then the top three original class indices after temperature-controlled softmax on [1.0, 4.0, 4.0, 2.0]. Keep equal-score indices in their original order.

स्टार्टर केवल दो बराबर स्कोर की संभावनाएँ दिखाता है। इसमें एक स्कोर की log probability और [1.0, 4.0, 4.0, 2.0] पर temperature-controlled softmax के बाद सर्वोच्च तीन मूल इंडेक्स प्रिंट करें। बराबर स्कोर का क्रम बनाए रखें।

EDIT A SECOND STARTER

stretch-starter.srp

// Extend this simple probability display with log-probability and top-three rankings.
print(softmax_temp([2.0, 2.0], 0.5));
MATCH EXACT COMPILER OUTPUT

stretch-solution.stdout

Compiler fixture
[0.5, 0.5]
[0.0]
[integer: 1, 2, 3]

Try it locally · स्वयं चलाएँ

Copy stretch-starter.srp to stretch-attempt.srp in the same lab folder. Edit only your copy; the original starter and fixture remain unchanged.

scarp verify labs/06-ai-foundations/stretch-attempt.srp scarp exec labs/06-ai-foundations/stretch-attempt.srp

Compare the exact stdout above. The website does not run Scarp, save attempts or award a score.

Show stretch hint · संकेत देखें

Use logsoftmax_temp([5.0], 2.0), then topk(softmax_temp(logits, 0.5), 3). The answer uses zero-based original indices.

logsoftmax_temp([5.0], 2.0) और फिर topk(softmax_temp(logits, 0.5), 3) इस्तेमाल करें। उत्तर में मूल शून्य-आधारित इंडेक्स दें।

Reveal tested stretch solution · सत्यापित हल देखें
// Temperature controls softmax concentration without random sampling.
print(softmax_temp([2.0, 2.0], 0.5));
print(logsoftmax_temp([5.0], 2.0));
bind logits = [1.0, 4.0, 4.0, 2.0];
print(topk(softmax_temp(logits, 0.5), 3));

Equal scores yield [0.5, 0.5] even at temperature 0.5; one logit gives [0.0] log probability. After scaling, the top indices are [integer: 1, 2, 3], with earlier index 1 before the tied index 2. This is deterministic ranking, not sampling.

बराबर स्कोर पर 0.5 तापमान में भी [0.5, 0.5] मिलता है; एक स्कोर की log probability [0.0] है। तापमान बदलने पर सर्वोच्च इंडेक्स [integer: 1, 2, 3] हैं, जिसमें समान स्कोर पर index 1 पहले आता है। यह निश्चित रैंकिंग है, random sampling नहीं।

View tested stretch solution ↗

The starter compiles but intentionally does not produce the goal. The reference solution and its output are verified on Linux, macOS and Windows against Scarp v0.0.6-alpha.3. Browse all labs ↗