← Dashboard

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.

updated Nov 2026·a 12-minute read·code run on PyTorch 2.15 (CPU)

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.

moons.pyPyTorch 2.15, scikit-learn 1.9
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}")
Output from one run (CPU, seed 0)
EpochTrain lossTest accuracy
10.6990.540
500.2230.910
1000.1130.930
2000.0840.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

Code mapped to the ideas courses teach
LineConceptWhere you will meet it
nn.Linear(2, 16)A layer: matrix multiply plus biasWeek 1 of every course
nn.ReLU()Nonlinearity; without it, stacked layers collapse into one linear mapActivation functions
BCEWithLogitsLossThe score of mistakes for two-class outputLoss functions, cross-entropy
loss.backward()Backpropagation: gradient of the loss for every parameterAutograd, the chain rule
opt.step() with AdamThe update that moves parameters downhillGradient descent, learning rate
Test accuracy under no_grad()Evaluation on data the model never trained onOverfitting, validation
WATCHTraining loss falling is not the goal. Loss on the training data can keep dropping while test accuracy stalls or worsens; with 337 parameters and 800 training points that is a real risk if you train for thousands of epochs. Always report a number from data held out from training.

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.

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.

What each source assumes
SourceStated audienceFramework
fast.ai Practical Deep LearningPeople with some coding experiencePyTorch, with the fastai and Hugging Face libraries
Karpathy, Zero to HeroBasic Python and a vague memory of high-school calculusCode from scratch, then PyTorch
Dive into Deep LearningTeaches linear algebra and probability preliminaries before the modelsPyTorch, NumPy/MXNet, JAX, TensorFlow
DeepLearning.AI specializationIntermediate levelPython and TensorFlow
MIT 6.S191, Stanford CS231nUniversity courses; see each syllabusCourse-dependent

05 · TRY IT

Break the loop on purpose

TRY ITRun the script, then change one thing at a time. Remove both 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.