data science / deep learning
Learn Deep Learning Free: Read One Training Loop Before Any Course
A complete PyTorch training loop is about twenty lines, runs on a laptop CPU in seconds, and contains every idea the big courses spend weeks on. This page walks through one, then ranks the free courses and books by how much they assume you already know.
Deep learning courses tend to open with history and notation, which hides how small the core is. A network is a stack of layers with adjustable numbers, a loss that scores its mistakes, and a loop that nudges the numbers to lower the score. Everything else (convolutions, transformers, GPUs, tricks for stability) elaborates on that loop. Read the loop first, and each course then has a place to hang its material. If you have not trained a classical model before, spend a few days with the machine learning guide first, because the evaluation habits there apply unchanged.
01 · THE LOOP
A neural network that separates two interleaved half-moons
The task is a toy dataset from scikit-learn: 1,000 points in two curved clusters that no straight line can separate. The network has two hidden layers of 16 units.
import torch, torch.nn as nn
from sklearn.datasets import make_moons
from sklearn.model_selection import train_test_split
torch.manual_seed(0)
X, y = make_moons(n_samples=1000, noise=0.2, random_state=0)
Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=0.2, random_state=0)
Xtr, Xte = torch.tensor(Xtr, dtype=torch.float32), torch.tensor(Xte, dtype=torch.float32)
ytr, yte = torch.tensor(ytr, dtype=torch.float32), torch.tensor(yte, dtype=torch.float32)
model = nn.Sequential(nn.Linear(2, 16), nn.ReLU(),
nn.Linear(16, 16), nn.ReLU(),
nn.Linear(16, 1))
print("parameters:", sum(p.numel() for p in model.parameters()))
loss_fn = nn.BCEWithLogitsLoss()
opt = torch.optim.Adam(model.parameters(), lr=0.01)
for epoch in range(1, 201):
opt.zero_grad()
loss = loss_fn(model(Xtr).squeeze(1), ytr)
loss.backward()
opt.step()
if epoch in (1, 50, 100, 200):
with torch.no_grad():
acc = ((model(Xte).squeeze(1) > 0).float() == yte).float().mean()
print(f"epoch {epoch:3d} train loss {loss.item():.3f} test acc {acc:.3f}")| Epoch | Train loss | Test accuracy |
|---|---|---|
| 1 | 0.699 | 0.540 |
| 50 | 0.223 | 0.910 |
| 100 | 0.113 | 0.930 |
| 200 | 0.084 | 0.955 |
The first line printed is parameters: 337. Check it by hand: the first layer has 2 x 16 weights plus 16 biases (48), the second 16 x 16 plus 16 (272), the last 16 x 1 plus 1 (17), and 48 + 272 + 17 is 337. Knowing how to count parameters is the first useful deep learning skill, because memory and training time scale with it. At epoch 1 the loss of 0.699 is close to ln 2 (about 0.693), which is what a model that guesses 50/50 scores; a first loss far from that usually means a bug. Your numbers will differ slightly across versions and hardware, but the shape of the curve should match.
02 · LINE BY LINE
What each line of the loop is doing
| Line | Concept | Where you will meet it |
|---|---|---|
nn.Linear(2, 16) | A layer: matrix multiply plus bias | Week 1 of every course |
nn.ReLU() | Nonlinearity; without it, stacked layers collapse into one linear map | Activation functions |
BCEWithLogitsLoss | The score of mistakes for two-class output | Loss functions, cross-entropy |
loss.backward() | Backpropagation: gradient of the loss for every parameter | Autograd, the chain rule |
opt.step() with Adam | The update that moves parameters downhill | Gradient descent, learning rate |
Test accuracy under no_grad() | Evaluation on data the model never trained on | Overfitting, validation |
03 · SETUP
What you need to run it, and when you need a GPU
Install PyTorch from the selector on its site. Its page states that the latest stable release requires Python 3.11 or later, and that on Windows it supports Python 3.10 to 3.14, so check your interpreter first. The example above needs no GPU. A GPU matters when you move to image or language models with millions of parameters. Kaggle's documentation says it provides free access to NVIDIA GPUs within a weekly quota (it listed 30 hours at the time of writing), which is enough for most of the course exercises below.
- PyTorch tutorials: Learn the Basics ↗The official sequence: tensors, datasets and data loaders, building the network, automatic differentiation, optimizing parameters, saving models.docs.pytorch.org
- Kaggle Learn: Intro to Deep Learning ↗A four-hour micro-course that uses TensorFlow and Keras on structured data, starting from a single neuron. Kaggle lists the cost as none.kaggle.com
- Keras developer guides ↗The official guides to the Sequential model, functional API and writing custom layers, if you choose Keras over PyTorch.keras.io
04 · CHOOSING A COURSE
Free courses and books, from least to most assumed
The order below reflects what each source states about its audience. Pick one from the top, finish it, then move down only if you need more theory.
| Source | Stated audience | Framework |
|---|---|---|
| fast.ai Practical Deep Learning | People with some coding experience | PyTorch, with the fastai and Hugging Face libraries |
| Karpathy, Zero to Hero | Basic Python and a vague memory of high-school calculus | Code from scratch, then PyTorch |
| Dive into Deep Learning | Teaches linear algebra and probability preliminaries before the models | PyTorch, NumPy/MXNet, JAX, TensorFlow |
| DeepLearning.AI specialization | Intermediate level | Python and TensorFlow |
| MIT 6.S191, Stanford CS231n | University courses; see each syllabus | Course-dependent |
- fast.ai: Practical Deep Learning for Coders ↗A free course for people with some coding experience, top-down: you train a model first and learn theory as you go. Part 1 is 9 lessons of around 90 minutes each, and the page describes it as recorded in 2022 and a Part 2 on Stable Diffusion, so expect library details to have moved on.course.fast.ai
- Andrej Karpathy: Neural Networks, Zero to Hero ↗Video lectures that build neural networks in code, from backpropagation (micrograd) through a character-level language model (makemore) toward GPT. The first lecture runs 1h57m.karpathy.ai
- Dive into Deep Learning ↗An interactive book with runnable code, math and discussion, implemented in PyTorch, NumPy/MXNet, JAX and TensorFlow, and used at hundreds of universities according to its site. Read free online; a Cambridge University Press edition is listed.d2l.ai
- MIT 6.S191: Introduction to Deep Learning ↗Lectures, slides and software labs. The site says new lectures, slides and labs are open-sourced each week during the spring offering; the 2026 edition has finished.introtodeeplearning.com
- Stanford CS231n: Deep Learning for Computer Vision ↗Course notes and assignments on image classification, convolutional networks and beyond; the site currently shows the Spring 2026 assignments.cs231n.github.io
- Deep Learning Specialization (Andrew Ng, Coursera) ↗A five-course series at intermediate level, about 3 months at 10 hours a week, using Python and TensorFlow. Coursera shows an Enroll for free button; check the page for what the free option includes.coursera.org
- Neural Networks and Deep Learning (Michael Nielsen) ↗A free online book that derives backpropagation carefully. Licensed CC BY-NC 3.0.neuralnetworksanddeeplearning.com
- Deep Learning (Goodfellow, Bengio, Courville) ↗The MIT Press textbook; its site states the online version is complete and will remain available for free. Reference-level, not a first read.deeplearningbook.org
- Hugging Face LLM Course ↗Chapters on Transformer models, using and fine-tuning pretrained models, and sharing them. A natural next step once the loop above is familiar.huggingface.co
- 3Blue1Brown: neural networks ↗Visual explanations of what the layers compute and how gradient descent works. Watch alongside, not instead of, writing code.3blue1brown.com
05 · TRY IT
Break the loop on purpose
nn.ReLU() layers and see how far test accuracy can climb with only linear layers. Set lr=1.0 and watch the loss. Raise the epochs to 5,000 and compare the training loss to test accuracy. Write one sentence for each result saying what you expected before you ran it.06 · FAQ
Frequently asked questions
Do I need a GPU to learn deep learning?
No. Small networks like the 337-parameter example train in seconds on a CPU. A GPU matters for large image and language models, and Kaggle documents free GPU access with a weekly quota that covers most course exercises.
Should I learn PyTorch or TensorFlow first?
PyTorch is the more common choice for new learning material: Dive into Deep Learning, fast.ai and Karpathy's course all use it. Kaggle's micro-course and the DeepLearning.AI specialization use TensorFlow and Keras, so choose by the course you plan to follow.
What math do I need for deep learning?
Basic calculus for derivatives and the chain rule, linear algebra for matrices, and some probability. Karpathy's course assumes only basic Python and a vague memory of high-school calculus, and Dive into Deep Learning teaches linear algebra and probability preliminaries before the models.
What is the best free deep learning course for beginners?
For coders, fast.ai and Karpathy's Zero to Hero are the most direct starts, and Dive into Deep Learning is the best free book. Kaggle's four-hour Intro to Deep Learning is a quick first taste.