This comprehensive 3-hour freeCodeCamp course covers the foundational knowledge needed to become an AI researcher, from mathematical foundations to implementing transformers.

Course Overview

The course is structured to build understanding from fundamentals:

  1. Mathematical Foundations
  2. Neural Network Basics
  3. PyTorch Implementation
  4. Transformer Architecture
  5. Large Language Models

Mathematical Foundations

Linear Algebra

  • Vectors and matrices
  • Matrix multiplication
  • Eigenvalues and eigenvectors
  • Why it matters: Neural networks are matrix operations

Calculus

  • Derivatives and gradients
  • Chain rule (crucial for backpropagation)
  • Partial derivatives
  • Optimization basics

Probability & Statistics

  • Probability distributions
  • Bayes’ theorem
  • Maximum likelihood estimation
  • Cross-entropy loss

Neural Network Fundamentals

The Perceptron

  • Weighted sum of inputs
  • Activation function
  • Learning through weight updates

Multi-Layer Networks

  • Hidden layers
  • Non-linear activations (ReLU, sigmoid, tanh)
  • Universal approximation theorem

Backpropagation

  • Forward pass: compute outputs
  • Loss calculation
  • Backward pass: compute gradients
  • Weight updates via gradient descent

Optimization

  • Stochastic Gradient Descent (SGD)
  • Momentum
  • Adam optimizer
  • Learning rate scheduling

PyTorch Essentials

Tensors

import torch
x = torch.tensor([1, 2, 3])
y = torch.randn(3, 4)  # Random tensor

Autograd

x = torch.tensor([2.0], requires_grad=True)
y = x ** 2
y.backward()
print(x.grad)  # dy/dx = 4

Building Models

import torch.nn as nn

class SimpleNet(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc1 = nn.Linear(784, 128)
        self.fc2 = nn.Linear(128, 10)

    def forward(self, x):
        x = torch.relu(self.fc1(x))
        return self.fc2(x)

Training Loop

for epoch in range(epochs):
    for batch in dataloader:
        optimizer.zero_grad()
        output = model(batch)
        loss = criterion(output, target)
        loss.backward()
        optimizer.step()

Transformer Architecture

Attention Mechanism

  • Query, Key, Value
  • Scaled dot-product attention
  • Why attention: captures relationships regardless of distance

Self-Attention

Attention(Q, K, V) = softmax(QK^T / √d_k) V

Multi-Head Attention

  • Multiple attention heads
  • Different representation subspaces
  • Concatenate and project

Transformer Block

  1. Multi-head self-attention
  2. Add & Normalize
  3. Feed-forward network
  4. Add & Normalize

Positional Encoding

  • Transformers have no inherent position sense
  • Add position information via sinusoidal encoding
  • Or learned positional embeddings

Large Language Models

Pre-training

  • Massive text corpora
  • Next token prediction
  • Self-supervised learning

Tokenization

  • BPE (Byte Pair Encoding)
  • WordPiece
  • SentencePiece

Scaling Laws

  • More parameters → better performance
  • More data → better performance
  • Compute-optimal training (Chinchilla)

Fine-tuning

  • Supervised fine-tuning (SFT)
  • RLHF (Reinforcement Learning from Human Feedback)
  • Instruction tuning

Research Skills

Reading Papers

  • Start with abstract and conclusion
  • Understand the problem being solved
  • Focus on methodology
  • Reproduce results

Experimentation

  • Hypothesis-driven research
  • Controlled experiments
  • Ablation studies
  • Statistical significance

Tools

  • Weights & Biases for tracking
  • Hugging Face for models
  • arXiv for papers
  • GitHub for code

Path Forward

  1. Master the fundamentals - Math and basic ML
  2. Implement from scratch - Build understanding
  3. Read papers - Stay current
  4. Reproduce results - Verify understanding
  5. Contribute - Open source, papers, discussions

这门全面的3小时freeCodeCamp课程涵盖成为AI研究员所需的基础知识,从数学基础到实现Transformer。

课程概述

课程结构从基础开始构建理解:

  1. 数学基础
  2. 神经网络基础
  3. PyTorch实现
  4. Transformer架构
  5. 大语言模型

数学基础

线性代数

  • 向量和矩阵
  • 矩阵乘法
  • 特征值和特征向量
  • 重要性:神经网络是矩阵运算

微积分

  • 导数和梯度
  • 链式法则(对反向传播至关重要)
  • 偏导数
  • 优化基础

概率与统计

  • 概率分布
  • 贝叶斯定理
  • 最大似然估计
  • 交叉熵损失

神经网络基础

感知机

  • 输入的加权和
  • 激活函数
  • 通过权重更新学习

多层网络

  • 隐藏层
  • 非线性激活(ReLU、sigmoid、tanh)
  • 通用近似定理

反向传播

  • 前向传播:计算输出
  • 损失计算
  • 反向传播:计算梯度
  • 通过梯度下降更新权重

优化

  • 随机梯度下降(SGD)
  • 动量
  • Adam优化器
  • 学习率调度

PyTorch基础

张量

import torch
x = torch.tensor([1, 2, 3])
y = torch.randn(3, 4)  # 随机张量

自动求导

x = torch.tensor([2.0], requires_grad=True)
y = x ** 2
y.backward()
print(x.grad)  # dy/dx = 4

构建模型

import torch.nn as nn

class SimpleNet(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc1 = nn.Linear(784, 128)
        self.fc2 = nn.Linear(128, 10)

    def forward(self, x):
        x = torch.relu(self.fc1(x))
        return self.fc2(x)

训练循环

for epoch in range(epochs):
    for batch in dataloader:
        optimizer.zero_grad()
        output = model(batch)
        loss = criterion(output, target)
        loss.backward()
        optimizer.step()

Transformer架构

注意力机制

  • Query、Key、Value
  • 缩放点积注意力
  • 为什么用注意力:无论距离都能捕获关系

自注意力

Attention(Q, K, V) = softmax(QK^T / √d_k) V

多头注意力

  • 多个注意力头
  • 不同的表示子空间
  • 拼接并投影

Transformer块

  1. 多头自注意力
  2. 加法和归一化
  3. 前馈网络
  4. 加法和归一化

位置编码

  • Transformer没有固有的位置感知
  • 通过正弦编码添加位置信息
  • 或学习的位置嵌入

大语言模型

预训练

  • 大规模文本语料库
  • 下一个token预测
  • 自监督学习

分词

  • BPE(字节对编码)
  • WordPiece
  • SentencePiece

缩放定律

  • 更多参数 → 更好性能
  • 更多数据 → 更好性能
  • 计算最优训练(Chinchilla)

微调

  • 监督微调(SFT)
  • RLHF(基于人类反馈的强化学习)
  • 指令调优

研究技能

阅读论文

  • 从摘要和结论开始
  • 理解要解决的问题
  • 关注方法论
  • 复现结果

实验

  • 假设驱动的研究
  • 对照实验
  • 消融研究
  • 统计显著性

工具

  • Weights & Biases用于跟踪
  • Hugging Face用于模型
  • arXiv用于论文
  • GitHub用于代码

前进路径

  1. 掌握基础 - 数学和基础ML
  2. 从零实现 - 建立理解
  3. 阅读论文 - 保持更新
  4. 复现结果 - 验证理解
  5. 贡献 - 开源、论文、讨论