AI Engineering from Scratch 完整教學

1. 專案定位

AI Engineering from Scratch 是目前 GitHub 上最完整的開源 AI 工程課程之一(36K+ stars)。它解決了一個核心問題:大多數 AI 教材零散、片段,學了 fine-tuning 卻解釋不了 loss curve,接了 agent tool call 卻不知道 attention 機制在做什麼。

這門課程的設計理念是「脊柱式(spine)學習」——從線性代數(linear algebra)到自主 agent 系統(autonomous systems),20 個階段線性堆疊。每個演算法(algorithm)先用原始數學手寫實作,再用 PyTorch 等框架跑同樣功能。到框架登場時,你已知道底層在做什麼。

核心價值

痛點本課程解法
AI 教材零散不連貫20 phases 線性堆疊,從數學到 production
只會 call API 不懂底層Build It / Use It 雙軌制:先手寫再框架
學完只有筆記每堂課產出 artifact(prompt / skill / agent / MCP server)
只有 Python四語言:Python + TypeScript + Rust + Julia
不知道從哪開始/find-your-level placement quiz 自動定位

適用對象

背景建議起點預估時數
程式新手Phase 0(Setup & Tooling)~306 小時
會 Python,不懂 MLPhase 1(Math Foundations)~270 小時
懂 ML,不懂 deep learning (DL; 深度學習)Phase 3(Deep Learning Core)~200 小時
懂 DL,想學 LLM + agentPhase 10(LLMs from Scratch)~100 小時
資深工程師,只要 agent engineeringPhase 14(Agent Engineering)~60 小時

2. 安裝指南

系統需求

依賴版本說明
Python3.10+主要實作語言
Git任意clone 課程
pip / uv任意安裝 Python 依賴
Node.js(選用)18+npx skills add 安裝 skills
GPU(選用)CUDA 12+Phase 3+ 深度學習課程加速

安裝步驟

 1# Step 1: Clone repo
 2git clone https://github.com/rohitg00/ai-engineering-from-scratch.git
 3cd ai-engineering-from-scratch
 4
 5# Step 2: 建立虛擬環境 + 安裝依賴
 6uv venv .venv && source .venv/bin/activate
 7uv pip install -r requirements.txt
 8
 9# Step 3: 驗證——跑第一堂課
10python phases/01-math-foundations/01-linear-algebra-intuition/code/vectors.py

主要依賴清單(requirements.txt)

套件版本用途
numpy>=1.24數值計算基礎
torch>=2.0deep learning 框架
transformers>=4.30Hugging Face model hub
datasets>=2.14資料集載入
scikit-learn>=1.3傳統 ML
anthropic>=0.25Claude API
openai>=1.0OpenAI API
tiktoken>=0.5tokenizer
librosa>=0.10音訊處理
jupyter>=1.0互動筆記本

三種入門方式

  1. 純閱讀 — 開 aiengineeringfromscratch.com,不需 clone
  2. Clone + 跑 code — 上述安裝步驟
  3. AI Agent 引導(推薦) — 在 Claude Code / Cursor 中執行 /find-your-level

3. 核心架構解析

課程結構


flowchart TB
    P0["Phase 0
Setup & Tooling
12 lessons"] --> P1["Phase 1
Math Foundations
23 lessons"] P1 --> P2["Phase 2
ML Fundamentals
19 lessons"] P2 --> P3["Phase 3
Deep Learning Core
14 lessons"] P3 --> P4["Phase 4
Computer Vision
29 lessons"] P3 --> P5["Phase 5
NLP
30 lessons"] P3 --> P6["Phase 6
Speech & Audio
18 lessons"] P3 --> P9["Phase 9
Reinforcement Learning
13 lessons"] P5 --> P7["Phase 7
Transformers
17 lessons"] P7 --> P8["Phase 8
Generative AI
16 lessons"] P7 --> P10["Phase 10
LLMs from Scratch
25 lessons"] P10 --> P11["Phase 11
LLM Engineering
18 lessons"] P10 --> P12["Phase 12
Multimodal AI
26 lessons"] P11 --> P13["Phase 13
Tools & Protocols
24 lessons"] P13 --> P14["Phase 14
Agent Engineering
43 lessons"] P14 --> P15["Phase 15
Autonomous Systems
23 lessons"] P15 --> P16["Phase 16
Multi-Agent & Swarms
26 lessons"] P14 --> P17["Phase 17
Infrastructure
29 lessons"] P15 --> P18["Phase 18
Ethics & Alignment
31 lessons"] P16 --> P19["Phase 19
Capstone Projects
86 lessons"] P17 --> P19 P18 --> P19

每堂課的結構(Lesson Template)


flowchart LR
    M["MOTTO
核心一句話"] --> Pr["PROBLEM
具體痛點"] Pr --> C["CONCEPT
圖表 + 直覺"] C --> B["BUILD IT
原始數學,無框架"] B --> U["USE IT
PyTorch / sklearn"] U --> S["SHIP IT
prompt / skill / agent / MCP"]

每個 lesson 資料夾統一結構:

1phases/<NN>-<phase-name>/<NN>-<lesson-name>/
2+-- code/          可執行實作(.py / .ts / .rs / .jl)
3+-- docs/
4|   +-- en.md      課程文字說明
5+-- outputs/       產出的 artifact(prompt-*.md / skill-*.md)

專案目錄總覽

目錄說明
phases/20 個 phase,共 503 lessons
scripts/9 個工具腳本(audit / catalog / link check / lesson run / skill install / scaffold)
site/Vercel 網站前端(含 134 interactive figures)
glossary/術語表 + AI 迷思破解
assets/banner / SVG 圖表
web/網站相關設定

工具腳本一覽

腳本說明
audit_lessons.py驗證 lesson 格式(目錄結構 / docs / code / quiz schema)
build_catalog.py掃描所有 phase + lesson → catalog.json
check_readme_counts.py驗證 README 中的數字與實際一致
install_skills.py安裝 388 skills + 99 prompts 到 AI agent 目錄
lesson_run.pysyntax-check 或實際執行所有 lesson code
link_check.py掃描所有 docs 中的連結是否有效
scaffold-lesson.sh建立新 lesson 骨架
scaffold_workbench.py將 Phase 14 Agent Workbench 移植到自己的 repo

4. 重點 Phase 詳解

Phase 0:Setup & Tooling(12 lessons)

涵蓋 dev environment、Git、GPU setup、API keys、Jupyter、Python environments、Docker、editor setup、data management、terminal、Linux for AI、debugging/profiling。

Phase 7:Transformers Deep Dive(17 lessons)

深入 attention mechanism(注意力機制)——從 scaled dot-product attention 到 multi-head attention,手寫 transformer block,再用 Hugging Face transformers 驗證。

Phase 10:LLMs from Scratch(25 lessons)

從 GPT-2 級別的 language model(語言模型)開始手寫:tokenizer → embedding → positional encoding → transformer → training loop → sampling → RLHF → DPO。

Phase 13:Tools & Protocols(24 lessons)

涵蓋 Model Context Protocol (MCP; 模型上下文協議) 從零開始建 MCP server,function calling,tool use patterns。

Phase 14:Agent Engineering(43 lessons,最大 phase)

核心 agent 工程:

  • Agent loop(ReAct 模式)
  • ReWOO(plan-and-execute)
  • Reflexion(verbal RL)
  • Tree of Thoughts / LATS
  • Tool use & function calling
  • Memory systems(MemGPT / mem0 / Voyager)
  • 主流框架比較(LangGraph / AutoGen / CrewAI / OpenAI Agents SDK / Claude Agent SDK)
  • Benchmarks(SWE-bench / GAIA / WebArena)
  • Agent Workbench capstone

Phase 16:Multi-Agent & Swarms(26 lessons)

多代理系統:swarm intelligence(群體智慧)、multi-agent communication、task decomposition、consensus mechanisms。


5. 應用場景

場景 A:AI 工程師系統性學習

想從「會 call API」升級到「理解底層」:從 Phase 1 Math Foundations 開始,手寫 backprop,手寫 tokenizer,手寫 attention。每堂課產出的 skill 直接用在工作中。

場景 B:Agent 工程師快速入門

已有 Python + ML 基礎,只想學 agent 工程:從 Phase 14 開始(~60 小時),涵蓋 agent loop、tool use、memory、主流 SDK 比較、benchmarking。

場景 C:團隊培訓 / 課堂教學

FORKING.md fork 整套課程,自訂進度。每堂課的 docs/en.md 可直接作為教材,outputs/ 中的 skill 可讓學員安裝到自己的 AI agent。

場景 D:安裝課程 Skills 到 AI Agent

1# 安裝全部 388 skills 到 Claude Code
2npx skills add rohitg00/ai-engineering-from-scratch
3
4# 只安裝 Phase 14(Agent Engineering)的 skills
5npx skills add rohitg00/ai-engineering-from-scratch --phase 14
6
7# 安裝單一 skill
8npx skills add rohitg00/ai-engineering-from-scratch --skill agent-loop

場景 E:在自己的 Repo 建立 Agent Workbench

1python3 scripts/scaffold_workbench.py path/to/your-repo
2# → AGENTS.md + schemas + init/verify/handoff scripts

6. 資安掃描報告

掃描結果:🟢 低風險

項目結果說明
subprocess 使用🟢 安全lesson_run.py 使用 subprocess.run() 搭配 10 秒 timeout,用於 syntax check / lesson 執行
網路連線🟢 合理link_check.py 使用 urlopen 檢查文件連結有效性,非惡意用途
API Key 處理🟡 注意requirements.txt 包含 anthropicopenai;部分 lesson code 需要 API key(環境變數載入,非硬編碼)
機密洩漏🟢 無掃描 scripts/ 無硬編碼 key / token / password
eval / exec🟢 無scripts 中不含 eval()exec()
pickle🟢 無不使用 pickle deserialization
供應鏈🟡 注意requirements.txt 含 18 個 PyPI 套件,均為主流大型套件(PyTorch / Hugging Face / scikit-learn),風險低

詳細分析

  1. lesson_run.py 的 subprocesssubprocess.run([sys.executable, "-c", ...], timeout=10) 用於 byte-compile 或執行 lesson code。timeout 設 10 秒,--execute 模式是 opt-in。安全。

  2. link_check.py 的 urlopen:檢查 docs 中的 URL 是否 404。有 skip-list(twitter/x/linkedin/instagram/medium),有 timeout。純驗證用途。

  3. API Key 風險:lesson code 中使用 anthropicopenai SDK 時需要 API key。課程本身不儲存 key,由學員自行設定環境變數。

結論

此專案為純教學課程,scripts 均為課程管理工具。主要風險在於學員執行 lesson code 時需自行管理 API key。適合在隔離的學習環境中使用。


7. FAQ

Q1:503 堂課全部完成了嗎?

專案仍在積極開發中(2026-06 持續有 commits)。核心 phases 已大致完整,但部分 lesson 可能缺少 code 或 docs。可用 python3 scripts/audit_lessons.py 檢查完成狀態。

Q2:需要 GPU 嗎?

Phase 0-2 不需要。Phase 3+ 的深度學習課程建議有 GPU(CUDA)。目前有 issue #294 反映缺少 Apple Silicon (MPS) 支援路徑。

Q3:只想學 agent 不想從頭學?

可以。直接從 Phase 14 開始(~60 小時)。或用 /find-your-level placement quiz 讓 AI 幫你定位。

Q4:TypeScript / Rust / Julia 版本都有嗎?

不是每堂課都有四語言版本。Python 是主要語言,TS / Rust / Julia 視 lesson 性質提供。

Q5:可以用來教課嗎?

可以。MIT License,FORKING.md 有 fork 指南。課程結構統一,適合改編。

Q6:skills 可以安裝到哪些 AI agent?

支援 Claude Code、Cursor、Codex、OpenClaw、Hermes,以及任何讀取 SKILL.md 的工具。


8. 進階技巧

8.1 用 audit 驗證 lesson 完整性

1# 全部 phase
2python3 scripts/audit_lessons.py
3
4# 只看 Phase 14
5python3 scripts/audit_lessons.py --phase 14
6
7# JSON 輸出(CI 用)
8python3 scripts/audit_lessons.py --json --strict

8.2 產生課程 catalog

1python3 scripts/build_catalog.py
2# → 產生 catalog.json,包含所有 phase / lesson / artifact 的完整清單

8.3 安裝 skills 到自訂路徑

 1# 預設 nested layout(推薦)
 2python3 scripts/install_skills.py ~/.claude/skills/ --type all
 3
 4# flat layout
 5python3 scripts/install_skills.py ~/.cursor/skills/ --layout flat
 6
 7# 只安裝 RAG 相關
 8python3 scripts/install_skills.py ~/.claude/skills/ --tag rag
 9
10# 預覽不寫入
11python3 scripts/install_skills.py ~/.claude/skills/ --dry-run

8.4 Smoke-check lesson code

1# 只做 syntax check(不需要 API key)
2python3 scripts/lesson_run.py
3
4# 實際執行(需要相關依賴 + API key)
5python3 scripts/lesson_run.py --execute --phase 1

8.5 搭配 Claude Code 的 placement quiz

1# 在 repo 內啟動 Claude Code
2cd ai-engineering-from-scratch
3claude
4
5# 使用內建 skill
6/find-your-level        # 10 題定位 quiz
7/check-understanding 7  # Phase 7 理解度測驗

9. 整合進其他工作流

作為團隊 AI 培訓教材

  1. Fork repo → 刪除不需要的 phases → 自訂學習路徑
  2. install_skills.py 把課程 skills 安裝到團隊共用的 agent 目錄
  3. scaffold_workbench.py 在團隊 repo 建立 Agent Workbench

作為 AI Agent Skills 源

課程的 388 skills + 99 prompts 可直接作為 AI agent 的知識庫:

1# 一次安裝全部
2npx skills add rohitg00/ai-engineering-from-scratch
3
4# 或用 Python script 精細控制
5python3 scripts/install_skills.py /path/to/skills --type all --layout skills

搭配 MCP Server 開發

Phase 13(Tools & Protocols)包含完整的 MCP server 開發教學。完成後的 MCP server artifact 可直接整合到 Claude Code 或其他 MCP-compatible client。

與 ROADMAP.md 追蹤進度

ROADMAP.md(51K 行)包含每堂課的完成狀態與路線圖。可作為學習進度追蹤的參考。


10. 重點摘要 Checklist

  • Clone repo + 安裝 Python 依賴
  • 跑第一堂課確認環境正常:python phases/01-.../01-.../code/vectors.py
  • /find-your-level 或手動選擇起始 Phase
  • 理解每堂課的 Build It / Use It / Ship It 三段式
  • 完成 Phase 後用 /check-understanding <N> 自我測驗
  • 累積的 outputs/ artifacts 用 install_skills.py 安裝到 agent
  • (進階)用 audit_lessons.py 驗證 lesson 完整性
  • (進階)用 scaffold_workbench.py 在自己 repo 建 Agent Workbench
  • (教學用)用 FORKING.md fork 課程自訂

11. 進一步閱讀