LESSON 37 OF 52 · CHAPTER 05

Modular Inference

import "...srp" as name, exported bindings, public pure function

ORIGINAL SOURCE

01-modular-inference.srp

import "_support/linear.srp" as linear;
import "_support/settings.srp" as settings;

bind scores = linear.predict([2.0, 1.0]);
print(settings.title);
print(scores);
print(argmax(scores), onehot(len(scores), argmax(scores)));
EXPECTED OUTPUT

stdout

Verified
Modular inference
[4.0, 1.0]
0 [1.0, 0.0]

UNDERSTAND THE CODE

Explanation & practice

What this example teaches

import "...srp" as name, exported bindings, public pure function

Expected behavior

Modular inference, [4.0, 1.0], 0 [1.0, 0.0]

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.

मॉड्यूल से अनुमान गणना

प्रोग्राम _support/linear.srp और _support/settings.srp आयात करता है। linear.predict दो इनपुट संख्याओं से दो स्कोर निकालता है। settings.title शीर्षक दिखाता है। argmax सबसे बड़े स्कोर का इंडेक्स और onehot एक संख्यात्मक वेक्टर बनाता है।

आउटपुट: पहले Modular inference, फिर [4.0, 1.0], और अंत में 0 [1.0, 0.0]।

अभ्यास: linear.predict का स्रोत पढ़ें: उसका आयात किया गया settings.gain कहाँ से आता है?

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 score vector is returned by linear.predict([2.0, 1.0]) in this example?इस उदाहरण में linear.predict([2.0, 1.0]) कौन-सा स्कोर वेक्टर देता है?

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

[4.0, 1.0] — The imported linear module computes the scores. The pinned fixture for this lesson prints [4.0, 1.0].[4.0, 1.0] — इम्पोर्ट किया गया linear मॉड्यूल स्कोर निकालता है। इस पाठ के सत्यापित आउटपुट में [4.0, 1.0] प्रिंट होता है।

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/05-modules/01-modular-inference.srp scarp exec examples/05-modules/01-modular-inference.srp

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

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