Study notes for the 2026 edition of MIT 6.S191, Introduction to Deep Learning. Course materials

Lesson 1 — Introduction to Deep Learning

Matrix Multiplication Recap

If is and is , then is . Each column of supplies one coefficient for each column of , so the two inner dimensions must agree.

To find a column of , write . The product collects each as a column.

If is column of , then column of is the weighted sum

To find one entry of , take entry of that weighted sum. This gives the dot product of row of and column of because the entries come from row .

For example, if row 1 of is and column 2 of is , then .

Neurons and Single-Layer Networks

One Neuron

For an input row vector , neuron has a learned weight column vector with one weight per input feature. It uses the same weights and bias for every input example.

The neuron takes the dot product and adds its scalar bias to get the pre-activation . The activation function then produces the neuron’s output .

One Dense Layer

All neurons in a dense layer receive the same input . Stack their weight vectors as columns of . By the column view of matrix multiplication, entry of is the dot product . Adding the bias vector adds one bias per neuron.

With input features and neurons, has shape , has shape , and both and have shape .

With an elementwise activation like ReLU, is applied independently to each entry of . For example, three input features and two neurons give a weight matrix, two biases, and two output values. A network with this dense layer as its only trainable layer is a single-layer network.

Hidden Layers and Dimensional Changes

A hidden layer sits between the input and the final output. Its output vector contains the hidden activations, which become the input to the next layer.

Start with an input row vector of shape . A hidden layer with neurons has a weight matrix of shape and a bias vector of shape . Each column of the weight matrix contributes one entry to . After adding the biases and applying the activation, the hidden vector has shape .

The next layer now receives input values. If it has neurons, its own weight matrix has shape and its bias vector has shape . If this is the output layer, the final vector has shape .

For example, with four input features, three hidden neurons, and two output neurons, the vector widths are . The weight matrices have shapes and . The number of columns in one weight matrix equals the number of rows in the next.

Loss Evaluation

A loss function assigns a penalty to a network prediction given the true target . The choice of loss determines how much each kind of mistake matters during training.

Squared Error

If the target is and the network predicts , the signed error is . Absolute error gives a loss of , while squared error gives . A prediction of gives the same squared loss because it is also two units from the target. Doubling the size of a miss quadruples its squared loss.

Empirical Loss and Mean Squared Error

The empirical loss averages the per-example losses over the observed dataset. For training examples, with prediction and target for example , the mean is

For example, losses of , , and give an empirical loss of . When each loss is the squared error of a numeric prediction, this average is the mean squared error (MSE).

Cross-Entropy Loss

In single-label classification, the predicted probabilities sum to and each example has one correct class. If the model assigns probability to the correct class, its cross-entropy loss for that example is

For example, given probabilities with the third class correct, the loss is . Averaging these per-example losses gives the mean cross-entropy.

For binary classification, let be the predicted probability of class and be the true label, either or . The correct-class probability is when and when .

Why Take the Negative Log?

The minus sign makes higher probabilities for the correct class give lower losses. The loss is zero at and grows without bound as approaches zero. Any log base greater than works. Changing the base multiplies all losses by the same positive constant, and base gives the simple derivative .

The probabilities of the incorrect classes sum to . Adding those and subtracting the correct-class probability gives the linear score . With that score, increasing from 1% to 2% helps by the same amount as increasing it from 70% to 71%. Cross-entropy rewards the first improvement more because it doubles the probability of the correct class.

When the likelihood factors across examples, the probabilities assigned to their correct labels multiply. The logarithm turns this product into a sum, so minimizing mean cross-entropy is equivalent to maximizing the likelihood of the observed labels.

Gradient Descent and Backpropagation

Gradient descent updates one shared set of weights and biases to reduce the average training loss. A network with many nonlinear layers generally requires an iterative search. At each step, the negative gradient points in the direction of steepest local decrease.

Gradient Descent

Start with initial parameters and a learning rate . Each training step follows the same sequence.

  1. Run a forward pass to predict on the training examples used in this step.
  2. Compare the predictions with their targets and compute the mean loss .
  3. Use backpropagation to compute the gradient , which contains one partial derivative per weight and bias.
  4. Subtract the gradient multiplied by the learning rate, then repeat with the updated parameters.

Learning Rate

The learning rate scales the parameter update. In plain gradient descent, the same multiplies every weight and bias gradient. The gradients are computed at the current parameters, then all parameters are updated together. For example, starting with weights and a gradient of , a learning rate of gives

For a fixed learning rate, a larger gradient produces a larger step. A smaller rate can keep a steep gradient from sending the parameters too far. On a flat stretch with a small gradient, a larger rate can help make progress. A gradient can also be small near a minimum, where a large step can overshoot if the slope changes quickly. The step size depends on both the rate and the gradient, and the curvature of the loss determines how quickly that gradient changes as we move.

The global minimum is the lowest loss over all possible parameters. On the nonconvex loss surfaces of deep networks, gradient descent can reach a local minimum or a saddle point. At a point with zero gradient, the update is zero for any learning rate. Choosing a rate helps the optimizer make steady progress, and plain gradient descent offers no general guarantee of reaching the global minimum.

Mini-Batch SGD

In mini-batch stochastic gradient descent (SGD), each step uses a batch of training examples. Compute their losses at the same current parameters , average the losses, and backpropagate once. The gradient of the mean loss equals the mean of the individual gradients.

The average is computed separately for each weight and bias. For example, if two examples give weight gradients and , the batch gradient is . With a learning rate of , subtract from the weights in one update for the batch.

A randomly sampled mini-batch provides an estimate of the full training-set gradient. With , each update uses one example. Using the entire training set for every update gives full-batch gradient descent.

Backpropagation and the Chain Rule

For one neuron with a scalar input , the forward pass computes , then , then the loss . A change in affects , which affects , which affects . The chain rule multiplies the derivatives along that path.

The bias gradient shares the first two factors. Since , the result is

Backpropagation applies this rule from the loss back through the network, reusing derivatives already computed for later layers. When an activation feeds several neurons, their contributions to its gradient add together.

Worked Example

Take , , , a ReLU activation, and a target of . The forward pass gives , , and squared loss .

The derivative of squared loss with respect to the prediction is . Since , the ReLU derivative is . The chain rule gives a weight gradient of and a bias gradient of .

With a learning rate of , the update gives and . The next forward pass predicts , bringing the loss down from to .

Overfitting

Overfitting happens when a model learns patterns specific to the training examples, including noise, and performs worse on new examples. Generalization is how well the model predicts on examples it has never seen.

Imagine fitting a curve to points scattered around a U-shaped trend.

  • Underfitting. A straight line misses the curved trend, so errors tend to be high on both training and validation data.
  • Good fit. A smooth curve captures the overall U shape and predicts well on similar new examples.
  • Overfitting. A highly flexible curve bends to follow individual training points. It can score well on those points and make worse predictions between them.

To detect overfitting, track the same loss on the training set and on a separate validation set whose examples are held out from weight updates. If training loss falls from 0.30 to 0.10 while validation loss rises from 0.35 to 0.55, the later model fits the training examples better but generalizes worse on the validation set.

Regularization

Regularization changes how a model is trained to help it generalize. It can reduce overfitting, but too much regularization can make the model miss useful patterns and underfit. Compare validation loss to see which strength works best on held-out examples.

Dropout

During training, dropout randomly sets some activations in a layer to zero before passing the vector to the next layer. Each activation has a probability of being dropped. With , about half are dropped on average. A fresh random mask on each training pass encourages the network to make useful predictions with different subsets of activations.

In inverted dropout, let be for a dropped activation and for a kept one. Scale the kept activations by so that each activation has the same expected value across random masks.

For example, with , activations , and mask , the next layer receives on that training pass. During validation and inference, dropout is disabled and the full activation vector passes through at its original scale.

Early Stopping

Early stopping uses validation loss to decide which version of the model to keep. In the lecture figure, the green training-loss curve keeps falling, while the blue curve starts rising after its lowest point. The later weights fit the training examples better and make worse predictions on the held-out examples. The blue curve, labeled “Testing” in the slide, serves as the validation curve because it guides when to stop.

For example, split 1,000 labeled images into three groups before training.

  • 800 training images provide the examples and targets used to compute gradients and update the weights.
  • 100 validation images measure how well the model predicts labels for images held out from weight updates. Use their loss to choose which checkpoint to keep.
  • 100 test images measure final performance after choosing the checkpoint.

A checkpoint is a saved version of the model weights. During training, check validation loss at regular intervals and save the weights whenever that loss improves. A common rule is to stop after several checks without improvement and restore the checkpoint with the lowest validation loss. The number of checks to wait is called patience.