How the Build It / Use It Lesson Structure Promotes Deep Understanding Before Framework Adoption
The Build It / Use It approach forces learners to implement algorithms from raw mathematics using only standard libraries before touching production frameworks, ensuring they own the mental model of every gradient, matrix operation, and loss function.
Every lesson in the rohitg00/ai-engineering-from-scratch curriculum follows a six‑beat flow where the Build It / Use It split serves as the pedagogical spine. According to the repository's README.md (lines 220‑223), this structure requires students to first craft algorithms by hand—exposing the underlying mechanics usually hidden inside high‑level libraries—before refactoring the same logic with PyTorch, scikit‑learn, or TensorFlow. By the time learners import a framework, they can map every library call back to a handwritten step they have already debugged.
The Six-Beat Flow and the Core Split
The curriculum architecture is explicit about this sequence. The philosophy section in AGENTS.md (line 11) codifies the Build It / Use It pattern as the non‑negotiable design principle governing every module. This creates a consistent cadence across the repository:
- Build It – Implement the algorithm using only NumPy or pure Python, spelling out the linear algebra, calculus, or statistics explicitly.
- Use It – Re‑implement the identical functionality with a production framework.
- Compare – Line‑by‑line mapping between the hand‑crafted code and the library API.
This loop turns "black‑box" library calls into transparent wrappers because the learner already possesses a correct reference implementation.
Build It: Hand‑Crafted Implementation from First Principles
In the Build It phase, students write the closed‑form solution or iterative algorithm without shortcuts. This forces ownership of the mathematics behind gradients, matrix inversions, and backpropagation.
Consider the linear regression lesson found in phases/01-math-foundations/01-linear-algebra-intuition/code/vectors.py. The exercise requires implementing ordinary least squares manually:
import numpy as np
# 𝑦 = 𝑤·𝑥 + b
def fit_linear_regression(x, y):
X = np.column_stack((np.ones_like(x), x)) # add bias column
# Closed‑form solution: (XᵀX)⁻¹Xᵀy
w_hat = np.linalg.inv(X.T @ X) @ X.T @ y
return w_hat[1], w_hat[0] # slope, intercept
def predict(w, b, x):
return w * x + b
# Example usage
x = np.array([1, 2, 3, 4])
y = np.array([3, 5, 7, 9])
w, b = fit_linear_regression(x, y)
print(predict(w, b, np.array([5]))) # → 11.0
By manually constructing the design matrix X, computing the Moore‑Penrose pseudoinverse via (X.T @ X), and solving for parameters, the learner witnesses exactly how the model translates data into coefficients. There are no hidden defaults, no opaque solvers—just the raw NumPy operations that mirror the mathematical derivation.
Use It: Transparent Adoption of Production Frameworks
The Use It phase follows immediately in the same lesson. Students refactor their working solution using scikit‑learn, PyTorch, or another industry standard. Because they already debugged the NumPy version, they can audit the framework's behavior line‑by‑line.
The accompanying Use It implementation for the same linear regression exercise looks like this:
from sklearn.linear_model import LinearRegression
import numpy as np
x = np.array([1, 2, 3, 4]).reshape(-1, 1) # scikit expects 2‑D input
y = np.array([3, 5, 7, 9])
model = LinearRegression()
model.fit(x, y)
w, b = model.coef_[0], model.intercept_
print(model.predict(np.array([[5]]))) # → [[11.]]
The learner can now map each framework call to their handwritten code:
np.column_stackin the Build It phase corresponds toreshape(-1, 1)in the Use It phase—both manipulate array dimensions to accommodate the bias term.np.linalg.inv(X.T @ X) @ X.T @ ymaps directly toLinearRegression.fit, which executes the identical closed‑form solution under the hood.- The manual prediction
w * x + baligns withmodel.predict.
Why the Pedagogy Eliminates the "API Illusion"
The Build It / Use It structure works because it closes the common gap where developers can invoke model.fit() without understanding the optimization landscape. By building first, learners develop a mental model of the computation—seeing how loss surfaces, gradient flows, and weight updates interact. When they later use a library, each high‑level call becomes a verified abbreviation of their own code rather than a magical incantation.
This method is repeated across the curriculum, from hand‑coded backpropagation in phases/02-neural-networks/03-backpropagation/code/main.py (often implemented with raw Python loops) to the subsequent PyTorch autograd version. The consistency ensures that by the time learners reach production codebases, they can debug framework internals, customize loss functions, and recognize numerical instability issues that abstraction usually hides.
Summary
- The Build It / Use It split is the central spine of the six‑beat lesson flow defined in
README.md(lines 220‑223) and mandated byAGENTS.md(line 11). - Build It requires implementing algorithms via NumPy or pure Python, exposing gradients, matrix operations, and closed‑form solutions.
- Use It refactors the same logic with production frameworks, allowing line‑by‑line comparison against the handwritten reference.
- This loop transforms frameworks from opaque black boxes into transparent tools that learners can debug, customize, and optimize.
Frequently Asked Questions
What is the primary goal of the Build It / Use It lesson structure?
The primary goal is to ensure learners own the mental model of every algorithmic step before abstracting it away. By forcing a raw implementation first, the curriculum guarantees that students understand the underlying mathematics—such as matrix inversion in linear regression or chain‑rule differentiation in backpropagation—so they can critically evaluate and debug high‑level framework code later.
How does the repository enforce this pattern across different topics?
The repository enforces the pattern through explicit design principles in AGENTS.md (line 11), which declares that every lesson must follow the Build It / Use It spine. Course maintainers structure lesson folders (e.g., phases/01-math-foundations/01-linear-algebra-intuition/code/) to contain both a handwritten implementation (often in vectors.py or similar) and a framework‑based version (often in main.py), ensuring pedagogical consistency from linear algebra to transformer architectures.
Can experienced developers skip the Build It phase?
While experienced developers might be tempted to jump to the Use It phase, the curriculum advises against it. Even senior engineers benefit from spelling out the closed‑form solutions manually because it reveals numerical edge cases—such as singular matrices in (XᵀX)⁻¹—that are silently handled by library solvers. Understanding these edge cases is essential for production debugging and custom loss‑function design.
What frameworks are typically used in the Use It phase?
The Use It phase employs industry‑standard libraries such as PyTorch, scikit‑learn, and TensorFlow. The choice depends on the lesson domain: NumPy‑based algorithms transition to scikit‑learn for classical ML, while neural network lessons move from raw Python backpropagation to PyTorch autograd and nn.Module implementations.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →