Building AI from Scratch: A Complete Learning Path with 503 Lessons in This Open-Source Course

A 503-lesson open-source course teaching AI from first principles: hand-implement everything before using frameworks.
AI Engineering from Scratch is a free, open-source course with 503 lessons across 20 phases, covering everything from linear algebra to autonomous agents. Its core philosophy: implement every concept by hand before using any framework. Supporting Python, TypeScript, Rust, and Julia, the course has earned 46K+ GitHub stars and is used by top universities and companies alike.
Why Learning AI Feels Confusing: The Trap of Fragmented Learning
Many people follow a strikingly similar path when learning AI: pick a course, code along, feel like you've learned something for a week, then realize you can't actually explain what you just built. One developer shared this exact frustration on Reddit — he could fine-tune models but couldn't explain what the optimizer was doing; he could call attention layers but couldn't derive how they work.
The optimizer mentioned here is a core component in neural network training that determines how parameters are updated. The most basic Stochastic Gradient Descent (SGD) simply updates parameters in the opposite direction of the gradient with a fixed step size, but in practice faces challenges like learning rate selection and saddle point escape. The currently popular Adam optimizer combines momentum estimation with adaptive learning rates, maintaining independent update step sizes for each parameter. Other variants like AdaGrad, RMSProp, and AdamW each have their own use cases. Understanding how optimizers work helps developers diagnose common issues like training non-convergence and loss oscillation, rather than blindly trial-and-erroring through hyperparameters.
This exposes a core problem in current AI education: most courses teach tools, not what's happening under the hood. Outdated tutorials, courses that assume you already know Python, playlists that introduce dozens of tools without explaining how they connect — learners drown in fragmented content, never building a coherent mental model.

So the author made a decision: stop asking around and searching everywhere, and instead build the course he wished existed — AI Engineering from Scratch. The project has accumulated over 46,000 stars on GitHub.
Core Philosophy: Hand-Implement First, Then Use Frameworks
The most critical design philosophy of this build-AI-from-scratch course is: implement every important concept yourself before using any library.
The author established a clear learning trajectory: starting from linear algebra, all the way to autonomous agents. Along this path, learners need to:
- Derive and hand-write backpropagation from calculus
- Build a tokenizer from scratch
- Implement the attention mechanism from the ground up
- Write a complete agent loop
Backpropagation: The Cornerstone of Neural Network Training
Backpropagation is the core algorithm for neural network training, systematically formalized by Rumelhart, Hinton, and Williams in their 1986 paper. Its essence is the efficient application of calculus's chain rule on computation graphs — computing the partial derivatives (gradients) of the loss function with respect to each parameter layer by layer from output to input, guiding the direction and magnitude of parameter updates. Without backpropagation, training deep networks would be computationally infeasible, since perturbing each parameter individually to estimate gradients would scale linearly with the number of parameters, while backpropagation only requires one forward pass plus one backward pass to obtain all gradients. Understanding backpropagation also explains why vanishing and exploding gradients plague deep networks.
Tokenizer: The First Step in How Models Understand Language
The tokenizer is the first processing stage of large language models, responsible for splitting raw text into discrete units (tokens) that models can process. Early NLP used rule-based word-level segmentation, which performed poorly with out-of-vocabulary words and multilingual scenarios. Modern mainstream methods include BPE (Byte Pair Encoding), WordPiece, and SentencePiece. Taking BPE as an example, it starts at the character level, repeatedly merges the highest-frequency adjacent character pairs based on co-occurrence statistics, until reaching a preset vocabulary size. The GPT series uses BPE, while BERT uses WordPiece. Tokenization strategy directly affects vocabulary size, sequence length, and handling of rare words, so implementing a tokenizer by hand helps you understand the fundamental difference between the text a model "sees" and the text humans see.
Attention Mechanism: The Core Engine of Transformers
The attention mechanism was first proposed by Bahdanau et al. in 2014 to address the information bottleneck problem of long-range dependencies in sequence-to-sequence models. In 2017, Vaswani et al.'s paper "Attention Is All You Need" introduced the Transformer architecture, making self-attention the sole sequence modeling mechanism, completely replacing the dominance of RNNs and CNNs in NLP. Its core operation maps each position in the input sequence to three vectors — Query, Key, and Value — computes attention weights via dot products between Query and all Keys, then takes a weighted sum of Values, allowing each position to "see" information from all other positions in the sequence. Multi-head attention performs this operation in parallel across different subspaces, capturing different types of semantic dependencies.
Autonomous Agents: From Q&A to Autonomous Decision-Making
In the AI engineering context, autonomous agents refer to systems that can perceive their environment, formulate plans, invoke tools, and iteratively execute tasks. Unlike single-turn Q&A chatbots, agents possess loop-based decision-making capabilities: they observe the current state, choose an action (such as calling an API, executing code, or retrieving documents), observe the result, then decide the next step. A typical agent loop includes four phases: perception, reasoning, action, and feedback. Since 2023, frameworks like AutoGPT, LangChain Agents, and OpenAI Function Calling have brought this concept into the mainstream. Understanding the underlying logic of agent loops — essentially a finite state machine or planner with state management and tool-calling capabilities — is key to building reliable AI applications.
The benefit of this design is straightforward: by the time you encounter frameworks like PyTorch, you already know exactly what they're computing for you. Frameworks are no longer black boxes — they're accelerated wrappers around operations you already understand.
Why "Hand-Implementation" Matters More Than "Just Calling Libraries"
Calling libraries directly lets you quickly get a demo running, but it can't build transferable understanding. Only when you've written backpropagation yourself can you truly understand how gradients flow; only when you've implemented attention yourself can you read formulas in papers and quickly get up to speed with new architectures. This "first principles" approach to learning, while slower, builds a truly solid, explainable knowledge system.
This philosophy aligns with the teaching approach championed by Andrej Karpathy — his micrograd project implements a complete automatic differentiation engine in fewer than 200 lines of Python, precisely to prove that the core mechanisms of deep learning aren't mysterious, just obscured by complex framework APIs.
Course Scale and Structure: 503 Lessons Covering 20 Phases
After countless nights and weekends of work, this open-source AI course now contains:
- 503 lessons distributed across 20 phases
- Implementations in Python, TypeScript, Rust, and Julia
- Every single lesson ends with a runnable artifact — you build it, and you keep it
The multi-language implementation is a notable highlight. Writing the same concept in different languages helps learners strip away language syntax noise and see the skeleton of the algorithm itself. The choice of these four languages is also deliberate: Python is the lingua franca of AI with the most complete ecosystem; TypeScript facilitates deploying models to web and production environments; Rust provides memory safety and peak performance for low-level inference engine development; Julia has natural advantages in scientific computing and numerical simulation, with its multiple dispatch mechanism being well-suited for expressing mathematical operations. The "runnable artifact per lesson" design ensures immediate feedback, preventing the false achievement of "understood it but didn't build it."
Fully Open-Source, Runs Locally, Zero Paywalls
This course uses the MIT License, is completely free, runs locally, and has no paid content or chapters to unlock. In today's landscape saturated with subscription-based and membership-gated AI courses, this is particularly rare. Running locally means learners don't depend on cloud services, don't worry about data privacy, and can even complete all learning in offline environments — especially friendly for learners in regions with limited internet access. The author mentions that students from top universities, companies, and individual self-learners are already using these materials.
Visual Diagrams for Every Lesson
A major recent update to the course is the addition of visual diagrams for every single lesson. These are lightweight SVG illustrations created specifically for the concepts being taught, including:
- Branching commit graphs
- Highly readable attention heatmaps
- Q-learning gridworlds with policy arrows
- Diffusion model grids showing step-by-step denoising into images
Q-learning and Intuitive Understanding of Reinforcement Learning
Q-learning is a model-free reinforcement learning algorithm proposed by Watkins in 1989. Its core idea is to learn a Q-function (action-value function) that estimates the maximum cumulative reward achievable after taking a certain action in a given state. The algorithm approximates optimal Q-values through iterative Bellman equation updates: Q(s,a) ← Q(s,a) + α[r + γ·max Q(s',a') - Q(s,a)], where α is the learning rate and γ is the discount factor. Gridworld is Q-learning's most classic teaching environment — an agent moves through a grid, learning the optimal policy to avoid obstacles and reach the goal. Visualizing Q-value tables and policy arrows intuitively demonstrates how the algorithm converges from random exploration to optimal paths.
Diffusion Models: Generating Images from Noise
Diffusion models are the dominant architecture in current image generation, with DALL-E 2, Stable Diffusion, and Midjourney all built on this technology. The principle involves two processes: the forward diffusion process gradually adds Gaussian noise to an image, turning it into pure random noise after hundreds to thousands of steps; the reverse denoising process trains a neural network (typically a U-Net architecture) to predict and remove noise at each step, ultimately recovering a clear image from pure noise. Mathematically, this is closely related to stochastic differential equations and score matching. Compared to GANs, diffusion models offer more stable training and greater generation diversity, but slower inference (requiring multi-step iterative denoising). The "diffusion grids" visualization in the course shows exactly this step-by-step denoising process from chaos to clarity.
For a field as highly abstract as AI, the value of visualization cannot be overstated. A clear attention heatmap is often worth more than paragraphs of text — it lets you see at a glance which positions in the input sequence the model is "attending to" when generating a particular word; a dynamic Q-learning grid makes reinforcement learning policy updates intuitive and tangible. These illustrations aren't random images pulled from the internet — they're custom-made for specific concepts, precisely serving the teaching objectives.
Advice for AI Learners
If you're stuck bouncing between different courses and tools, never building a coherent understanding, this course offers a possible way out: start at Phase 0 and build all the way through.
The project's success — 46,000+ GitHub stars, usage feedback from universities and companies — validates a point to some degree: there's no shortage of content teaching "how to use tools." What's truly scarce is a systematic learning path that clearly explains the "why" underneath.
This also echoes a core finding in learning science: the generation effect — actively generating knowledge (such as deriving and writing code yourself) leads to deeper memory encoding and understanding than passively receiving knowledge (such as watching videos or reading documentation). When you hand-write an attention mechanism from scratch, your brain is forced to process every detail, forming neural connections far more robust than those from watching a tutorial video.
For serious AI learners, "build from scratch" resources like this deserve a place on your learning list. It may not get you running results within a week like crash courses do, but it builds the kind of understanding that carries you much further. In today's rapidly evolving AI landscape, true competitive advantage lies not in how many tools you know how to use, but in how quickly you can understand and master new tools and architectures when they appear — and that's exactly the capability that first-principles learning provides.
Project repository: https://github.com/rohitg00/ai-engineering-from-scratch Course website: https://aiengineeringfromscratch.com
Related articles

Deep Dive into Guava: Core Features and Practical Usage Guide
Deep dive into Google Guava's core features including immutable collections, Multimap, CacheBuilder local caching, ListenableFuture concurrency tools, and more to boost Java development efficiency.

How Open-Source Models Achieve Superior Retrieval Performance at 1% of GPT's Cost
Deep analysis of how open-source models match GPT-level retrieval performance at 1/100th the cost. Covers RAG cost optimization, embedding model fine-tuning, and deployment strategies.

Distilling Linus's Code Review Philosophy from 32,000 Emails
The linus-torvalds-skill project distills Linus Torvalds's code review style from 32,000 kernel mailing list emails into an AI Agent-callable skill, with open pipeline and multi-model experiments.