$ run as a normal user# run as root (or with sudo)
What the course covers
Logistic regression training and cross-entropy loss in PyTorch.
- Softmax regression for multi-class problems, plus activation functions.
- Shallow and deep neural networks with
nn.Modulepatterns. - Training tricks: dropout, normalization, initialization and momentum.
- Convolutional neural networks, GPUs and transfer learning.
- A final CNN classification project.
| Module | Main focus |
|---|---|
| Module 1 · about 2 hours | Logistic Regression and Cross-Entropy Loss: why not MSE, maximum likelihood, loss surfaces |
| Module 2 · about 3 hours | Softmax Regression and Activation Functions: softmax, argmax, sigmoid, tanh, ReLU |
| Module 3 · about 3 hours | Shallow Neural Networks: hidden layers, non-linear boundaries, backpropagation |
| Module 4 · about 5 hours | Optimizing Deep Networks: nn.ModuleList, dropout, init, momentum, batch norm |
| Module 5 · about 6 hours | Convolutional Neural Networks: convolution, stride, padding, pooling, ResNet, GPU |
| Module 6 · about 2 hours | Final Project and Final Assessment: build and train a CNN |
Module 1: Logistic Regression and Cross-Entropy Loss
Logistic Regression and Cross-Entropy Loss: why not MSE, maximum likelihood, loss surfaces.
- Logistic regression makes a linear score, then passes it through the sigmoid.
- Cross-entropy loss is
-(y·log p + (1-y)·log(1-p)). It punishes confident wrong answers. - MSE is a weak choice for classification. It gives small gradients when the model is very wrong.
- Maximum likelihood leads to cross-entropy: we minimize the negative log likelihood.
- The training loop: forward pass, compute the loss,
backward(), then update.
Module 2: Softmax Regression and Activation Functions
Softmax Regression and Activation Functions: softmax, argmax, sigmoid, tanh, ReLU.
- Softmax turns scores into positive probabilities that add up to 1. argmax then returns the index of the highest one.
- Activation functions add non-linearity: sigmoid (0 to 1), tanh (-1 to 1), ReLU (max of 0 and x).
- Softmax with cross-entropy is the standard loss for multi-class problems.
Module 3: Shallow Neural Networks
Shallow Neural Networks: hidden layers, non-linear boundaries, backpropagation.
- A hidden layer plus an activation lets the model learn non-linear boundaries. The forward pass is: input, linear, activation, output.
- Backpropagation applies the chain rule backwards to get every gradient. Gradients must flow.
- A vanishing gradient means early layers get tiny updates, so deep sigmoid stacks learn slowly.
- More hidden units give more capacity. Too much capacity and the model overfits.
Module 4: Optimizing Deep Networks
Optimizing Deep Networks: nn.ModuleList, dropout, init, momentum, batch norm.
nn.ModuleListkeeps layers in a Python list. A loop inforward()applies them in order.- Dropout sets random activations to zero during training. It is a regularizer; it is off at test time.
- Weight initialization keeps signal variance stable. Batch normalization normalizes layer inputs, so training is faster and more stable.
- Momentum keeps a moving average of past gradients. It smooths the path and speeds up learning.
Module 5: Building Convolutional Neural Networks
Convolutional Neural Networks: convolution, stride, padding, pooling, ResNet, GPU.
- A convolution slides small filters over the image and builds feature maps.
- Stride is the step size of the filter. Padding keeps the border size. Pooling shrinks the map.
- A CNN often stacks: convolution, ReLU, pooling, then flatten, then linear layers.
- Residual connections skip a block, which helps very deep networks. Transfer learning with ResNet18 freezes old layers, then fine-tunes a new head.
- A GPU runs the same tensor code much faster. Move the model and data to the same device.
Module 6: Final Project and Final Assessment
Final Project and Final Assessment: build and train a CNN.
- The project is a full CNN classification pipeline: data, model, training, evaluation. Check every tensor shape: batch, channel, height, width.
- Evaluate on data the model did not train on. Compare training loss with validation loss.
Check yourself
Answer each question first, then open it to check the answer.
1Why is cross-entropy a better loss than MSE for classification? a) It needs no labels · b) It fits probabilities and punishes confident wrong answers · c) It always reaches zero · d) It works only for regression
b) It fits probabilities and punishes confident wrong answers. Cross-entropy comes from maximum likelihood and grows fast when a confident answer is wrong.
2What does the sigmoid output mean in logistic regression? a) A class name · b) The number of layers · c) A probability between 0 and 1 · d) A gradient value
c) A probability between 0 and 1. Sigmoid maps any score into the range 0 to 1, so we read it as a probability.
3What does softmax do to a vector of scores? a) Turns them into probabilities that add up to 1 · b) Sorts the rows of the batch · c) Removes only the negative scores · d) Averages the scores
a) Turns them into probabilities that add up to 1. Softmax makes positive values that sum to 1, one per class.
4Which function picks the predicted class from softmax outputs? a) sigmoid · b) mean · c) backward · d) argmax
d) argmax. argmax returns the index of the largest probability, which is the class.
5Which activation returns 0 for negative inputs and the input for positive inputs? a) Sigmoid · b) Tanh · c) ReLU · d) Softmax
c) ReLU. ReLU keeps positive values and turns negatives into 0.
6Why add a hidden layer with an activation function? a) To keep the model linear · b) To learn non-linear boundaries · c) To remove the loss function · d) To shrink the dataset
b) To learn non-linear boundaries. A linear model alone can only draw a straight boundary; the activation bends it.
7What is backpropagation? a) A way to load the data · b) A type of pooling · c) The chain rule applied backwards to get gradients · d) A data split
c) The chain rule applied backwards to get gradients. Backpropagation uses the chain rule from the loss back to each weight.
8What is a vanishing gradient? a) Early layers get very small gradients, so they learn slowly · b) The loss becomes zero at once · c) The dataset becomes empty · d) The learning rate is set to zero
a) Early layers get very small gradients, so they learn slowly. Many small sigmoid or tanh derivatives multiply, so early gradients shrink.
9What does dropout do during training? a) It deletes rows from the dataset · b) It removes a layer forever · c) It randomly sets some activations to zero · d) It stops the training loop
c) It randomly sets some activations to zero. Dropout masks random units, which stops the network from leaning on one path.
10What is batch normalization for? a) To count the batches · b) To normalize layer inputs and stabilize training · c) To normalize the labels · d) To shuffle the test set
b) To normalize layer inputs and stabilize training. Batch norm rescales the inputs of a layer, so training is faster and more stable.
11What does stride control in a convolution? a) How far the filter moves at each step · b) The number of classes · c) The learning rate · d) The batch size
a) How far the filter moves at each step. A stride of 2 moves the filter two pixels at a time, so the output map is smaller.
12Why fine-tune a pretrained ResNet18 instead of training from zero? a) It needs no data at all · b) It has no parameters · c) It works only on text · d) Its old layers already hold useful features, so training is faster
d) Its old layers already hold useful features, so training is faster. Transfer learning reuses learned features, so you need less data and time.
Study and exam tips
Link each loss to its task: MSE for regression, cross-entropy for classification.
- Keep the three activations straight: sigmoid, tanh and ReLU.
- Remember why dropout and batch norm exist: regularization and stable training.
- Learn the CNN order: convolution, activation, pooling, flatten, linear.