The gap between theoretical AI knowledge and the practical skills needed to engineer robust, production-ready AI systems is wide. Many resources explain machine learning models, but few provide a comprehensive, hands-on path from foundational principles to deployable applications. This is the problem ai-engineering-from-scratch addresses.
With 54,808 stars on GitHub, rohitg00/ai-engineering-from-scratch is a widely recognized, community-backed resource. This star count shows the project's utility and the positive reception from thousands of developers working with AI system design. It points to a reliable, well-regarded, and active educational effort that meets the developer community's needs.
This article examines the project's educational philosophy, its pedagogical architecture, and how it helps developers build AI systems from first principles. You will learn to navigate its structured content for skill development, understand the curriculum's technical underpinnings, and find ways to contribute to this open-source initiative. This is not a superficial overview; we will explore the project's design decisions, walk through practical use cases, examine its verifiable tech stack, and guide you through local setup and contribution workflows.
The Core Philosophy: Explaining the Why
The core philosophy of ai-engineering-from-scratch is summarized in its tagline: "Learn it. Build it. Ship it for others." This guiding principle shapes the project's educational architecture and its approach to AI engineering. The project aims to clarify complex AI concepts by removing layers of abstraction, prompting developers to understand and implement systems from the ground up.
The maintainers chose not to create another high-level framework or library for rapid prototyping. Instead, they opted to solve the problem of foundational understanding. The project does not provide a pip install ai-engineering-toolkit for immediate production deployment. Rather, it teaches the fundamental algorithms, data structures, and design patterns needed to build such toolkits yourself, or to understand, debug, and optimize existing ones deeply. This trade-off prioritizes profound conceptual mastery over superficial implementation speed. The belief is that engineering skill in AI comes from an understanding of its underlying mechanics, allowing adaptability and innovation beyond what black-box library usage offers.
This "from scratch" approach is opinionated. It holds that a developer who has implemented a neural network's backpropagation algorithm manually, or coded a transformer's attention mechanism using only basic array operations, will possess a more robust and transferable skill set than one who only calls a library's fit() method. This design choice trades immediate satisfaction for long-term comprehension and problem-solving capability.
Compared to its closest resources, such as official documentation for popular frameworks (TensorFlow, PyTorch) or other online courses, ai-engineering-from-scratch stands out with its holistic, ground-up perspective. Other resources might offer deep dives into specific model architectures or framework features. This project, however, connects the entire engineering lifecycle: from setting up development environments and understanding data pipelines, through implementing core ML algorithms, to exploring advanced topics like generative AI and agents. It emphasizes building, testing, and ultimately shipping. It is a curriculum for the AI generalist, designed to cultivate engineers who can tackle diverse challenges rather than specialize early in a single tool or technique. The inclusion of topics like Rust and TypeScript, alongside Python, signals an expansive, full-stack engineering mindset for AI systems.
A Practical Use-Case Walkthrough
Consider a developer, skilled in general software engineering, who has used machine learning with high-level libraries. They can train a model, but their understanding fails when faced with performance bottlenecks, complex custom architectures, or the need to deploy on edge devices. They recognize a gap in their "from scratch" knowledge of how these systems truly work.
Their starting point: A developer needs to understand the workings of a self-attention mechanism within a transformer model, not just how to instantiate it from a library. They want to be able to modify, optimize, or rebuild parts of it for a specific, resource-constrained application where every computational detail matters.
Here is how they would use ai-engineering-from-scratch:
-
Clone the Repository: The first step is to get the project locally.
git clone https://github.com/rohitg00/ai-engineering-from-scratch.git cd ai-engineering-from-scratch ``` 2. **Explore Relevant Chapters**: Based on the project's structured `chapters/` directory, they would navigate to the section covering Generative AI and Transformers. A quick `ls chapters/` would reveal the available modules. Assuming the `07_generative_ai` chapter covers transformers: ```bash # Review available chapters to find the relevant one ls -F chapters/ # Change directory into the Generative AI chapter cd chapters/07_generative_ai/ ls -F # This might reveal a 'transformers/' directory or similar cd transformers/3. **Set Up the Environment**: Each chapter or major section often includes its own `requirements.txt` to ensure specific dependencies are met, maintaining environment isolation.python -m venv .venv_transformers source .venv_transformers/bin/activate pip install -r requirements.txt # Use the requirements in the transformers directory4. **Deep Dive into Attention Mechanisms**: The developer would then open the relevant Python scripts or Jupyter notebooks, such as `attention.py` or `multi_head_attention.ipynb`. They would find detailed explanations and step-by-step implementations of concepts like scaled dot-product attention, multi-head attention, and positional encoding. The code examples use NumPy or pure Python to illustrate the underlying linear algebra and logic without hiding complexity behind framework calls. 5. **Build and Experiment**: The developer can then take the core `self_attention` function provided in the chapter, modify its inputs, change parameters, or integrate it into a small, custom forward pass. They could, for instance, experiment with different scaling factors or mask implementations to see their direct effect on the output.# Example snippet from chapters/07_generative_ai/transformers/attention.py (conceptual) import numpy as np def scaled_dot_product_attention(query, key, value, mask=None): """ Calculates the scaled dot-product attention. Args: query, key, value: Input tensors. mask: Optional mask tensor for decoder self-attention. Returns: Output tensor and attention weights. """ d_k = query.shape[-1] scores = np.matmul(query, key.transpose(-2, -1)) / np.sqrt(d_k) if mask is not None: scores = scores + mask * -1e9 # Apply large negative number to masked positions attention_weights = np.softmax(scores, axis=-1) output = np.matmul(attention_weights, value) return output, attention_weights # Practical application: # Let's say we have dummy Q, K, V for a sequence of length 3, embedding dim 4 q_dummy = np.random.rand(1, 3, 4) k_dummy = np.random.rand(1, 3, 4) v_dummy = np.random.rand(1, 3, 4) # Example without mask output_no_mask, weights_no_mask = scaled_dot_product_attention(q_dummy, k_dummy, v_dummy) print("Output (no mask):\n", output_no_mask) print("Weights (no mask):\n", weights_no_mask) # Example with a simple look-ahead mask for decoder mask = np.array([[0, 1, 1], [0, 0, 1], [0, 0, 0]], dtype=bool) mask = mask[np.newaxis, np.newaxis, :, :] # Reshape for broadcasting output_masked, weights_masked = scaled_dot_product_attention(q_dummy, k_dummy, v_dummy, mask) print("\nOutput (masked):\n", output_masked) print("Weights (masked):\n", weights_masked)The developer gains an understanding of how scaled dot-product attention functions. They know what it does, how it is computed, the role of the scaling factor, and how masking influences the attention scores. This understanding allows them to debug transformer models more effectively, innovate on custom attention mechanisms for specific tasks, and explain these components in technical discussions. ## Under the Hood: The Actual Tech Stack The `ai-engineering-from-scratch` project is a comprehensive, code-driven curriculum. Its technical architecture delivers educational content and enables hands-on learning. The primary language powering the project's core content and examples is **Python**. This is evident throughout the `chapters/` directories, where most exercises, implementations, and theoretical explanations are presented in Python scripts (`.py`) and Jupyter notebooks (`.ipynb`). While Python is the backbone for machine learning and AI concepts, the project's topics also include **Rust** and **TypeScript**, indicating that aspects of AI engineering, such as performance-critical components or front-end integrations, are also covered. These languages likely appear in specific advanced chapters or examples where their strengths are relevant for AI development beyond pure model training. The project's content is structured internally, primarily within the `chapters/` directory. This directory is organized numerically and thematically, ensuring a logical progression through various AI engineering topics. Each sub-directory represents a distinct chapter, typically containing: * **Python scripts (.py)**: For core algorithm implementations, utility functions, and command-line examples. * **Jupyter notebooks (.ipynb)**: For interactive explanations, data visualization, and step-by-step walkthroughs that combine code, markdown, and output. * **Markdown files (.md)**: For detailed theoretical explanations, introductions, and summaries within a chapter. * **`requirements.txt`**: Often present within chapter subdirectories to manage specific Python dependencies for that module, preventing conflicts across different exercises that might require varying library versions. * **`assets/` folders**: For images, diagrams, or dataset snippets specific to a chapter. This file structure reflects a modular, easily navigable curriculum, allowing developers to focus on specific topics without being overwhelmed by the entire codebase. Given its nature as a learning resource, the project does not have a "deployment approach" in the traditional sense of a continuously running service. Instead, its "build" process focuses on ensuring the educational content is accessible and reproducible. The associated website, `https://aiengineeringfromscratch.com`, suggests that the project's content (Jupyter notebooks and Markdown files) might be rendered into a static website using tools like Sphinx, Jekyll, MkDocs, or a custom build script. This allows the content from the GitHub repository to be presented in a user-friendly, browsable web format. The `.github/workflows` directory likely contains GitHub Actions for continuous integration (testing code examples) and potentially continuous deployment (updating the website with new content). Here is a representative snapshot of the project's internal file and directory structure, illustrating its organized content architecture:ai-engineering-from-scratch/ ├── .github/ # CI/CD pipelines (e.g., GitHub Actions for testing notebooks) │ ├── workflows/ │ │ └── ci.yml │ └── ISSUE_TEMPLATE/ ├── chapters/ # The core educational modules │ ├── 01_basics/ # Fundamental programming & data science concepts │ │ ├── python_intro.py │ │ ├── data_structures.ipynb │ │ └── README.md │ ├── 02_machine_learning/ # Implementing ML algorithms from scratch │ │ ├── linear_regression.py │ │ ├── decision_trees.ipynb │ │ └── requirements.txt │ ├── 07_generative_ai/ # Advanced topics: LLMs, diffusion models, etc. │ │ ├── transformers/ # Deep dive into transformer architecture │ │ │ ├── attention.py │ │ │ ├── multi_head_attention.ipynb │ │ │ └── requirements.txt │ │ ├── llm_pretraining.md │ │ └── diffusion_models/ │ ├── 09_ai_agents/ # Building intelligent agents │ │ └── swarm_intelligence.py │ └── ... # Many more chapters covering CV, NLP, RL, etc. ├── docs/ # General documentation, contribution guidelines (e.g., CONTRIBUTING.md) ├── examples/ # Larger, more integrated projects applying learned concepts │ ├── chatbot_from_scratch/ │ └── image_classifier/ ├── assets/ # Global assets like images used across multiple chapters ├── LICENSE # MIT License ├── README.md # Project overview and entry point └── requirements.txt # Top-level development dependencies (e.g., for testing, linting)This structure defines learning paths and provides a framework for managing a large volume of interconnected educational material. ## Building or Extending It: A Practical Guide Getting `ai-engineering-from-scratch` running locally is straightforward, following standard practices for Python-based open-source projects. This setup allows you to explore the examples, run the code, and begin customizing or extending the material for your specific learning or project needs. To get started, follow these exact shell commands:# 1. Clone the repository from GitHub git clone https://github.com/rohitg00/ai-engineering-from-scratch.git # 2. Navigate into the cloned directory cd ai-engineering-from-scratch # 3. Create a dedicated Python virtual environment # This isolates project dependencies from your global Python installation. python -m venv .venv # 4. Activate the virtual environment # On macOS/Linux: source .venv/bin/activate # On Windows (Command Prompt): # .venv\Scripts\activate.bat # On Windows (PowerShell): # .venv\Scripts\Activate.ps1 # 5. Install the core project dependencies # The top-level requirements.txt handles common development tools and essential libraries. pip install -r requirements.txt # (Optional, but recommended) # Navigate to a specific chapter and install its unique dependencies. # For instance, if working on the Generative AI chapter with transformers: # cd chapters/07_generative_ai/transformers/ # pip install -r requirements.txt # cd ../../.. # Go back to root if you need to run other top-level commandsOnce activated, you can execute any Python script or run Jupyter notebooks within the project. For instance, to launch Jupyter Lab:jupyter lab### Extending and Customizing A common way to extend this project is by adding new exercises, modifying existing ones, or integrating a "from scratch" component into your own external project. For instance, imagine you want to explore a different activation function for a custom neural network implemented in one of the machine learning chapters. Here's an annotated code snippet demonstrating how you might add a new activation function, `LeakyReLU`, to a conceptual `neural_network.py` file found in `chapters/02_machine_learning/`:# File: chapters/02_machine_learning/neural_network.py (conceptual) import numpy as np # --- Existing Activation Functions (as found in the project) --- def sigmoid(x): return 1 / (1 + np.exp(-x)) def sigmoid_derivative(x): s = sigmoid(x) return s * (1 - s) def relu(x): return np.maximum(0, x) def relu_derivative(x): return (x > 0).astype(float) # --- Your Custom Extension: Adding LeakyReLU --- def leaky_relu(x, alpha=0.01): """ Implements the Leaky ReLU activation function. Args: x (np.array): Input array. alpha (float): Slope of the negative part. Returns: np.array: Output array after applying Leaky ReLU. """ return np.where(x > 0, x, x * alpha) def leaky_relu_derivative(x, alpha=0.01): """ Implements the derivative of Leaky ReLU. Args: x (np.array): Input array. alpha (float): Slope of the negative part. Returns: np.array: Derivative output array. """ return np.where(x > 0, 1, alpha) # You could then modify a 'build_model' function to use this: def build_model(input_size, hidden_layers, output_size, activation_func='relu'): # ... (model setup logic) if activation_func == 'leaky_relu': return leaky_relu, leaky_relu_derivative elif activation_func == 'relu': return relu, relu_derivative # ... (other activations)This customization allows you to immediately test and observe the effects of `LeakyReLU` within the existing neural network framework provided by the project, deepening your understanding through direct experimentation. ### A Gotcha: Environment Management Across Chapters One common problem for developers using `ai-engineering-from-scratch` is managing Python environments, especially when jumping between different chapters. While a top-level `requirements.txt` provides baseline dependencies, many individual `chapters/` subdirectories may contain their *own* `requirements.txt` files. These chapter-specific files often specify library versions needed for the examples to run correctly, or include additional libraries specific to that module (e.g., `opencv` for computer vision chapters, or specific `transformers` versions for generative AI). The issue is failing to install or activate the correct environment for the specific chapter you're working on. If you only use the root `requirements.txt`, you might encounter missing module errors or unexpected behavior due to version incompatibilities when running code in a specialized chapter. Always check for a `requirements.txt` within the immediate working directory of the chapter and install those dependencies after activating your virtual environment. It is often best practice to create a new virtual environment for each major chapter or area you focus on, preventing dependency issues and ensuring reproducibility for each learning module. ## Contributing to the Project: The Open-Source PR Process Contributing to `ai-engineering-from-scratch` is a way to reinforce your learning, share your expertise, and improve a widely used educational resource. The project, like many open-source initiatives, follows a clear process to ensure contributions are well-integrated and maintain high quality. ### Step 0: Issue or Direct PR? Before writing any code, determine if your contribution warrants an initial issue: * **Open an Issue FIRST**: If you are proposing a structural change to the curriculum (e.g., adding a new chapter or major section like "Quantum Machine Learning"), suggesting a refactor of an existing module, or identifying a complex bug that might require discussion on its root cause or solution. This allows maintainers to provide feedback, align on scope, and prevent duplicated effort. * **Go Straight to a PR**: For smaller, self-contained improvements. This includes fixing typos, correcting grammatical errors in explanations, updating broken links, clarifying sentences, fixing minor bugs in code examples, updating outdated library calls, or improving code style (e.g., PEP 8 compliance). These changes are usually straightforward and do not require extensive discussion. ### Step 1: Fork, Clone, Install Once you have decided on your approach, the standard GitHub workflow begins:# 1. Fork the repository on GitHub (visit rohitg00/ai-engineering-from-scratch and click 'Fork') # 2. Clone your forked repository to your local machine git clone https://github.com/YOUR_GITHUB_USERNAME/ai-engineering-from-scratch.git cd ai-engineering-from-scratch # 3. Add the original repository as an 'upstream' remote git remote add upstream https://github.com/rohitg00/ai-engineering-from-scratch.git # 4. Create and activate a virtual environment python -m venv .venv source .venv/bin/activate # 5. Install all development dependencies (from root and relevant chapter) pip install -r requirements.txt # If contributing to a specific chapter, navigate there and install its requirements too # cd chapters/0x_chapter_name/ # pip install -r requirements.txt # cd ../../ # Return to root### Step 2: Locate, Edit, and Adhere to Conventions Navigate to the specific file you intend to modify. Whether it is a Python script, a Jupyter notebook, or a Markdown explanation, consistency is key: * **Python Code**: Adhere to PEP 8 for style. Ensure clear variable names, concise functions, and meaningful comments where necessary. Avoid introducing new, unneeded dependencies. * **Jupyter Notebooks**: Maintain a clean flow. Ensure cells are run in order, outputs are clear and relevant, and explanations are coherent. Avoid excessive or large data outputs that bloat the notebook. * **Markdown Explanations**: Use consistent heading levels, clear language, and correct grammar. If linking to external resources, ensure they are authoritative and up-to-date. * **Mathematical Notations**: If present, ensure LaTeX or equivalent rendering is correct. * **Testing**: If your change involves code, ensure existing tests pass, and consider adding new tests for new functionality or bug fixes if applicable (though this may be more relevant for significant code contributions). ### Step 3: Quality Bar for Contributions Maintainers expect contributions to be: * **Accurate**: All code and explanations must be technically correct. * **Clear and Concise**: Explanations should be easy to understand for the target audience. * **Reproducible**: Code examples should run without errors in the specified environment. * **Well-formatted**: Adhering to the project's established style guides (e.g., PEP 8 for Python). * **Additive or Corrective**: Contributions should either fix a problem, clarify content, or introduce new, well-justified educational material that aligns with the "from scratch" philosophy. Contributions that introduce excessive complexity, rely on overly abstract libraries, or deviate from the core pedagogical approach might be rejected. ### Step 4: Open a Pull Request Once your changes are thoroughly tested locally and meet the quality bar: 1. **Commit your changes**: Write clear, descriptive commit messages.git add . git commit -m "feat: add LeakyReLU activation to neural network chapter" # Use conventional commits if applicable2. **Push to your forked repository**:git push origin main -
Open a Pull Request: On GitHub, navigate to your forked repository and click the "Compare & pull request" button.
- Title Convention: Use a descriptive title, often following conventional commit guidelines (e.g.,
fix:,feat:,docs:). Example:feat: Add LeakyReLU to neural_network.pyorfix: Correct typo in Transformer chapter. - Description Checklist: The PR description should clearly articulate:
- What problem your PR solves or what new feature it introduces.
- How you solved it (briefly describe changes).
- Any relevant context or considerations.
- Reference any associated issues (e.g.,
Closes #123).
- Screenshot/Demo: If your change has a visual component (e.g., a plot in a notebook), include screenshots.
- Title Convention: Use a descriptive title, often following conventional commit guidelines (e.g.,
After opening the PR, maintainers will review your submission. They may request changes, provide feedback, or merge it directly. Be responsive to comments and willing to iterate on your contribution. Once merged, your contribution becomes part of this resource, benefiting thousands of aspiring AI engineers worldwide.
Wrapping Up
ai-engineering-from-scratch is a powerful example of structured, hands-on learning in the complex domain of AI. Its "learn it, build it, ship it" ethos addresses a critical need in the industry for engineers who understand AI systems from their foundational components to their deployment.
Here are three actionable takeaways for developers:
- Master Fundamentals for True Flexibility: The project's "from scratch" methodology is a blueprint for understanding AI algorithms and architectures. Implement core components yourself; this deepens your insight, enabling you to debug, optimize, and innovate beyond what high-level libraries alone can provide.
- Use its Pedagogical Architecture: Navigate the
chapters/directory as a structured curriculum. Each module builds upon previous knowledge, making it an ideal resource for systematically closing knowledge gaps in specific AI subfields, from basic ML to advanced agents and generative models. - Contribute to Accelerate Your Learning: Engaging with the project through contributions—whether correcting a typo or adding a new exercise—is a way to solidify your understanding and connect with a community of like-minded AI engineers. It is an opportunity to apply what you have learned and gain open-source experience.
This project is a comprehensive educational journey for the modern AI engineer. We invite you to explore ai-engineering-from-scratch further on Fossy.dev at https://fossy.dev/rohitg00/ai-engineering-from-scratch. Discover its depth, contribute to its growth, and empower your AI engineering capabilities.






