Research knowledge library

UNDERSTAND THE MODEL. READ THE EVIDENCE.

Deep learning.
Make the charts make sense.

Ten chapters, three interactive labs, and eight companion tools. Begin with the question; learn what the evidence can and cannot tell you.

Try the loss-curve lab

Start with the question

Imagine helping a lab triage suspicious email. Define the input and the decision first: a binary label, or a queue for human review? A larger model cannot fix an unclear task.

AI is the broader field; machine learning learns from data; deep learning uses multilayer neural networks. Classification predicts categories, regression predicts numbers, and generative models produce content. Establish a simple baseline before adding complexity.

TRY THIS

Write one sentence: what data helps whom make which decision?

Read the source: Google ML Crash Course

Tensors and shapes

A tensor is a shaped container of numbers. One example with four features has shape [4]; a batch of 32 has shape [32, 4]. Equal numbers of elements do not imply equal meanings.

Image, text, and tabular conventions differ. PyTorch image operations often use [batch, channels, height, width]; text representations may use [batch, sequence, hidden]. Label every axis before transposing, flattening, or adding a batch dimension.

TRY THIS

Explain each axis of [16, 3, 224, 224] in plain language.

Read the source: PyTorch · Tensors

How training changes a model

One update has four parts: predict with a forward pass, measure loss, compute gradients with backpropagation, and update parameters with an optimizer. The learning rate controls the size of the update.

A batch is a group of examples; an epoch is one pass over training data. Neither is synonymous with an optimizer step. During validation, use evaluation mode and disable gradient recording. That does not create a data split or prevent leakage for you.

TRY THIS

Explain why validation loss should not drive backward updates.

training-step.py
# Core step; define model, loss_fn, optimizer, X, y, X_val, y_val first.
import torch

model.train()
optimizer.zero_grad()
prediction = model(X)
loss = loss_fn(prediction, y)
loss.backward()
optimizer.step()

# Separate validation: no parameter update.
model.eval()
with torch.no_grad():
    validation_loss = loss_fn(model(X_val), y_val)
Read the source: PyTorch · Optimization

Train, validation, and test

Training data fits parameters. Validation data supports model, threshold, and hyperparameter choices. Test data evaluates the selected approach. Repeatedly changing the model after inspecting test scores turns the test set into validation data.

Repeated observations from a person or chunks from one document may need grouped splitting. Forecasting generally requires time-aware evaluation. Fit scaling, imputation, and feature selection on training data, then apply them to other splits.

TRY THIS

Which rows in your data share a person, event, or document?

Read the source: scikit-learn · Common pitfalls

Reading training curves

Check whether the horizontal axis is epochs or steps, and whether both losses use the same definition and scale. Falling training loss means better fit to seen data; validation behavior helps assess generalization.

Training loss falling while validation loss rises is a reason to investigate overfitting. Both remaining high or oscillating has several possible causes. Curves guide checks; their shape alone does not establish a diagnosis.

TRY THIS

Switch scenarios below, locate minimum validation loss, and examine what follows.

READ THE CHANGE

One chart, four stories

Synthetic illustrations with a shared loss scale. No model is being trained here.

Training and validation lossThe dot follows your selected epoch on the validation curve.
Training and validation lossThe dot follows your selected epoch on the validation curve.. X: Epoch. Y: Loss.1.411.056.750.712.50.3518.25024EpochLoss
TrainingValidation
Training loss0.329
Validation loss0.387
Minimum validation epoch8

After the validation minimum, training improves while validation worsens. Check regularization, data coverage, and early stopping on validation data.

Read the values as a table
EpochTrain lossValidation loss
10.86020.8750
20.75630.7563
30.66630.6590
40.58820.5795
50.52060.5143
60.46190.4610
70.41110.4173
80.36700.3815
90.32880.3872
100.29570.3983
110.26700.4136
120.24210.4326
130.22050.4544
140.20180.4786
150.18560.5048
160.17150.5326
170.15930.5617
180.14880.5919
190.13960.6229
200.13170.6547
210.12480.6870
220.11880.7198
230.11370.7530
240.10920.7866
Read the source: Google · Interpreting loss curves

Reading a confusion matrix

Identify the positive class and axis convention first. Here, rows are actual labels and columns are predictions. TP detects a positive, FP is a false alarm, FN is a miss, and TN correctly rejects a negative. Other tools may order axes differently.

Precision asks how many predicted positives are real. Recall asks how many real positives were found. F1 combines the two without directly using TN. Check class counts and error costs, especially with imbalance.

TRY THIS

If missing an event is costly, which error cell deserves attention?

Read the source: scikit-learn · Precision

ROC, PR, and ranking

ROC plots false-positive rate against recall; PR plots recall against precision. Changing the threshold changes decisions, not the score ranking, so AUC for fixed scores stays unchanged.

For rare positives, PR helps reveal false-alarm burden. Its baseline depends on prevalence, which matters when comparing AP across datasets. High AUC does not establish a useful operating threshold.

TRY THIS

Predict what happens to recall at threshold 0.8 instead of 0.5, then check the matrix.

Synthetic teaching data: 12 examples, six positives. The model scores stay fixed; only the decision threshold changes.

ROCAcross thresholds; the dot is your current choice.
ROCAcross thresholds; the dot is your current choice.. X: False positive rate. Y: True positive rate.100.750.250.50.50.250.7501False positive rateTrue positive rate
ROCChance reference
Precision–RecallThe reference line is the positive-class prevalence.
Precision–RecallThe reference line is the positive-class prevalence.. X: Recall. Y: Precision.100.750.250.50.50.250.7501RecallPrecision
PRPositive prevalence
ROC AUC0.667
Average precision (AP)0.709
Precision0.667
Recall0.667
F10.667
Rows = actual; columns = predicted. Positive class = 1.
Actual / predictedPositive (1)Negative (0)
Positive (1)4TP2FN
Negative (0)2FP4TN

Score ≥ threshold predicts positive. Moving the threshold changes the dot and confusion matrix, not AUC or AP. AP uses recall increments weighted by precision, not trapezoidal PR area. PR points are connected as a visual guide. With only one true class, ROC AUC is undefined; with no positives, AP is undefined. Choose thresholds on validation data, then evaluate once on held-out test data.

Read the source: scikit-learn · Precision–Recall

Regression plots and residuals

In an actual-versus-predicted plot, the diagonal represents exact predictions. Examine both deviations and coverage: a close fit in a narrow range says little about unobserved conditions.

Residuals here are actual minus predicted. Curves or widening spreads suggest checks for missed structure or changing error scale. MAE summarizes absolute error; RMSE emphasizes larger errors. R² can be negative.

TRY THIS

Change one prediction drastically in the regression tool and compare MAE with RMSE.

Open residual plot tool Read the source: scikit-learn · R²

Reading attention heatmaps

Identify keys on the horizontal axis and queries on the vertical axis. Attention weights are typically normalized over keys; a row describes one query's distribution in a particular head and layer.

Heads, layers, masks, and color scales change the picture. A dark cell indicates a larger weight, not proof of semantic understanding or a complete causal explanation. The display below is synthetic, not a recorded model trace.

TRY THIS

Describe a cell using query, key, and weight, without saying the model knows.

Read one cell carefully

Synthetic attention weights. Each row sums to 1. Darker cells have larger weights; the mask prevents looking ahead.

Query ↓ / Key →
TokenWereadpaperswithcare
We
read
papers
with
care

Query「papers」 / Key「read」 / Weight 0.183

Read the source: Vaswani et al. · Attention Is All You Need

Report an experiment someone can inspect

Keep dataset versions, split rules, seeds, model settings, and selection criteria. Report a baseline, variation across runs, and failure cases. A single best run cannot establish stability.

For any chart, ask: on which data, in which units, against what comparison, with how much variation, and with what missing context? Those questions help choose the next experiment.

TRY THIS

Apply the five questions to a figure in a paper you recently read.

Read the source: Google · Deep Learning Tuning Playbook

Maintained by SecTools.tw · Updated November 27, 2026. Examples are educational; interactive charts use synthetic data.