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 labStart 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.
Write one sentence: what data helps whom make which decision?
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.
Explain each axis of [16, 3, 224, 224] in plain language.
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.
Explain why validation loss should not drive backward updates.
# 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)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.
Which rows in your data share a person, event, or document?
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.
Switch scenarios below, locate minimum validation loss, and examine what follows.
One chart, four stories
Synthetic illustrations with a shared loss scale. No model is being trained here.
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
| Epoch | Train loss | Validation loss |
|---|---|---|
| 1 | 0.8602 | 0.8750 |
| 2 | 0.7563 | 0.7563 |
| 3 | 0.6663 | 0.6590 |
| 4 | 0.5882 | 0.5795 |
| 5 | 0.5206 | 0.5143 |
| 6 | 0.4619 | 0.4610 |
| 7 | 0.4111 | 0.4173 |
| 8 | 0.3670 | 0.3815 |
| 9 | 0.3288 | 0.3872 |
| 10 | 0.2957 | 0.3983 |
| 11 | 0.2670 | 0.4136 |
| 12 | 0.2421 | 0.4326 |
| 13 | 0.2205 | 0.4544 |
| 14 | 0.2018 | 0.4786 |
| 15 | 0.1856 | 0.5048 |
| 16 | 0.1715 | 0.5326 |
| 17 | 0.1593 | 0.5617 |
| 18 | 0.1488 | 0.5919 |
| 19 | 0.1396 | 0.6229 |
| 20 | 0.1317 | 0.6547 |
| 21 | 0.1248 | 0.6870 |
| 22 | 0.1188 | 0.7198 |
| 23 | 0.1137 | 0.7530 |
| 24 | 0.1092 | 0.7866 |
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.
If missing an event is costly, which error cell deserves attention?
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.
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.
| Actual / predicted | Positive (1) | Negative (0) |
|---|---|---|
| Positive (1) | 4TP | 2FN |
| Negative (0) | 2FP | 4TN |
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.
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.
Change one prediction drastically in the regression tool and compare MAE with RMSE.
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.
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.
| Token | We | read | papers | with | care |
|---|---|---|---|---|---|
| We | |||||
| read | |||||
| papers | |||||
| with | |||||
| care |
Query「papers」 / Key「read」 / Weight 0.183
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.
Apply the five questions to a figure in a paper you recently read.
Maintained by SecTools.tw · Updated November 27, 2026. Examples are educational; interactive charts use synthetic data.