How the 'Build It / Use It' Method Teaches AI Algorithms from Scratch in the AI Engineering Curriculum

The 'Build It / Use It' method requires learners to implement algorithms from raw mathematics using only standard libraries, then reimplement the identical logic using production frameworks like PyTorch to reveal how abstraction layers map to first principles.

The rohitg00/ai-engineering-from-scratch repository structures its entire curriculum around this dual-phase teaching methodology. Every lesson follows a six-beat rhythm—MOTTO → PROBLEM → CONCEPT → BUILD ITUSE ITSHIP IT—that ensures you understand the mathematical core of an algorithm before encountering the conveniences of modern ML libraries.

The Six-Beat Lesson Flow

The curriculum organizes content into a strict pedagogical sequence defined in the repository’s README.md and reiterated in AGENTS.md. This flow ensures conceptual mastery precedes tool adoption:

  1. MOTTO – A guiding principle for the lesson
  2. PROBLEM – The specific challenge being solved
  3. CONCEPT – Theoretical foundations and mathematical notation
  4. BUILD IT – Framework-free implementation from scratch
  5. USE IT – Reimplementation using production-grade libraries
  6. SHIP IT – Export of a reusable artifact (prompt, skill, agent, or MCP server)

The Build It / Use It split forms the spine of every lesson, creating a controlled environment where you can trace exactly how high-level API calls correspond to low-level mathematical operations.

Build It: Framework-Free Implementation

The Build It phase demands that you implement core algorithms using only the language’s standard library or minimal numeric dependencies like NumPy. This code lives in phases/<phase-id>/<lesson-id>/code/ and is deliberately constructed without PyTorch, JAX, or scikit-learn abstractions.

First-Principles Coding

In this phase, you write the raw mathematics directly. For example, when implementing a perceptron, you manually handle the dot product, bias addition, and weight updates. Since no black-box API hides the internals, you can inspect every gradient, trace every variable through the computation graph, and debug edge cases at the tensor level. This approach guarantees that you understand the control flow and mathematical mechanics before any framework obscures them.

Use It: Production Framework Integration

The Use It phase takes the exact same algorithmic skeleton and wraps it with the target production framework. The implementation is placed alongside the framework-free version in the same lesson folder, often in a separate file like model_torch.py or perceptron_torch.py.

Transparency Through Contrast

By re-using the identical mathematical logic, you see precisely how the library abstracts operations. What was manual tensor handling in NumPy becomes torch.nn.Linear and torch.optim.SGD. The contrast makes the library’s behavior transparent, transforming "magic" API calls into understandable pipelines. You observe that loss.backward() in PyTorch performs the same mathematical operations you coded manually in the Build It phase, just with automatic differentiation handling the chain rule.

Ship It: Exporting Reusable Artifacts

The final beat, SHIP IT, requires exporting a concrete artifact from the lesson’s outputs/ directory. This might be a model card, a reusable prompt template, an AI agent configuration, or an MCP server definition. The artifact demonstrates a runnable outcome that bridges the gap between educational code and production deployment, reinforcing the learning loop by forcing you to package your understanding into a reusable format.

Concrete Example: The Perceptron Implementation

Phase 3, Lesson 01 demonstrates the Build It / Use It methodology through a simple perceptron. Both implementations reside in phases/03-deep-learning-core/01-the-perceptron/code/, allowing direct comparison of the framework-free and production-ready versions.

Pure NumPy Implementation

The Build It version in perceptron_numpy.py uses only NumPy to implement the perceptron learning rule:


# phases/03-deep-learning-core/01-the-perceptron/code/perceptron_numpy.py

import numpy as np

class Perceptron:
    def __init__(self, n_features):
        self.w = np.zeros(n_features + 1)   # bias as last weight

    def predict(self, X):
        Xb = np.hstack([X, np.ones((X.shape[0], 1))])   # add bias term

        return np.where(Xb @ self.w > 0, 1, 0)

    def fit(self, X, y, lr=0.1, epochs=10):
        Xb = np.hstack([X, np.ones((X.shape[0], 1))])
        for _ in range(epochs):
            for xi, yi in zip(Xb, y):
                if self.predict(xi[:‑1].reshape(1, -1)) != yi:
                    self.w += lr * (yi - self.predict(xi[:‑1].reshape(1, -1))) * xi

This implementation follows the Build It principle: raw math, explicit bias handling via np.hstack, and manual weight updates with no deep-learning framework.

PyTorch Implementation

The Use It version in perceptron_torch.py replicates the same logic using PyTorch’s abstractions:


# phases/03-deep-learning-core/01-the-perceptron/code/perceptron_torch.py

import torch
import torch.nn as nn

class PerceptronTorch(nn.Module):
    def __init__(self, n_features):
        super().__init__()
        self.linear = nn.Linear(n_features, 1)   # bias built‑in

    def forward(self, x):
        return (self.linear(x) > 0).float()

    def fit(self, X, y, lr=0.1, epochs=10):
        optimizer = torch.optim.SGD(self.parameters(), lr=lr)
        criterion = nn.BCEWithLogitsLoss()
        X = torch.tensor(X, dtype=torch.float32)
        y = torch.tensor(y, dtype=torch.float32).unsqueeze(1)
        for _ in range(epochs):
            optimizer.zero_grad()
            logits = self.linear(X)
            loss = criterion(logits, y)
            loss.backward()
            optimizer.step()

Here, the nn.Linear layer handles the weight matrix and bias automatically, while optimizer.step() performs the weight update you coded manually in the NumPy version. Running python -m unittest discover from the lesson directory verifies that both implementations produce identical predictions on the same dataset, cementing the conceptual link between raw implementation and library abstraction.

Summary

  • The 'Build It / Use It' method is a dual-phase teaching approach where you first implement algorithms from mathematical first principles, then map them to production frameworks.
  • Build It code lives in phases/<phase-id>/<lesson-id>/code/ and uses only standard libraries or NumPy to force understanding of raw mechanics.
  • Use It implementations sit alongside the raw versions, using PyTorch, JAX, or scikit-learn to demonstrate how frameworks abstract the same mathematical operations.
  • The SHIP IT phase exports reusable artifacts to outputs/, bridging the gap between learning and production deployment.
  • This methodology is explicitly defined in the repository’s README.md and AGENTS.md files, governing all 503 lessons in the curriculum.

Frequently Asked Questions

What is the 'Build It / Use It' method in AI education?

The 'Build It / Use It' method is a pedagogical pattern where learners first construct algorithms from scratch using only basic numerical libraries, then reconstruct the same algorithm using industry-standard frameworks like PyTorch. This approach ensures you understand the mathematical foundations before relying on high-level abstractions, making debugging and architecture decisions more informed.

Why implement algorithms from scratch before using frameworks?

Implementing from scratch in the Build It phase removes the "black box" effect of ML libraries. When you manually code the weight updates, activation functions, and loss gradients in phases/<phase-id>/<lesson-id>/code/, you develop an intuition for how data flows through the model. This first-principles knowledge becomes essential when you need to debug convergence issues or customize architectures in the Use It phase.

How does the six-beat flow structure the learning experience?

The six-beat flow (MOTTO → PROBLEM → CONCEPT → BUILD IT → USE IT → SHIP IT) creates a consistent narrative arc across all lessons. According to the README.md and AGENTS.md files in the rohitg00/ai-engineering-from-scratch repository, this structure ensures that you encounter the theory, manual implementation, framework implementation, and final artifact generation in a repeatable pattern that reinforces retention through multiple modalities of engagement.

Where are the lesson implementations stored in the repository?

Lesson implementations are organized under phases/<phase-id>/<lesson-id>/code/, where each lesson contains paired files for the Build It (framework-free) and Use It (framework) implementations. For example, the perceptron lesson stores the NumPy version in phases/03-deep-learning-core/01-the-perceptron/code/perceptron_numpy.py and the PyTorch version in phases/03-deep-learning-core/01-the-perceptron/code/perceptron_torch.py. Final artifacts are exported to the corresponding outputs/ directory within each lesson folder.

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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →