1. Home
  2. Explore
  3. Computer Science
  4. MIT 6.S191 Deep Learning Intro

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

MIT 6.S191 Deep Learning Intro

Deep Learning Fundamentals: Lecture Notes (MIT 6.S191)

Introduction to Deep Learning

Defining Key Concepts

Intelligence is the ability to process information to inform future decisions. The field of artificial intelligence (AI) focuses on building algorithms that perform this processing. Machine learning (ML) is a subset of AI that teaches algorithms how to perform a task without being explicitly programmed — instead, they learn from data. Deep learning is a subset of machine learning that automatically extracts the useful pieces of information needed to make predictions or decisions, learning a task directly from raw data.

Core idea: Deep learning algorithms develop a hierarchical representation of data. Low-level features (like edges and lines) are combined into mid-level features (like eyes, noses, mouths) and then into high-level features (like jawlines and full face structures). This eliminates the need for hand-engineered feature extraction.

Why Deep Learning Now?

Although the fundamental building blocks of neural networks and their training algorithms have existed for decades, several factors have made deep learning practical:

  • Data abundance: These algorithms require huge amounts of data to succeed, and we are living in the age of big data.

  • Massive parallelizability: Modern GPU architectures and hardware acceleration allow these algorithms to run efficiently at scale.

  • Open-source toolboxes: Frameworks like TensorFlow streamline the process of building and deploying models.


The Perceptron: Building Block of Neural Networks

Forward Propagation of Information

A single neuron, also called a perceptron, performs three steps:

  1. Take a set of inputs x1,x2,…,xMx_1, x_2, \dots, x_Mx1​,x2​,…,xM​, each with a corresponding weight w1,w2,…,wMw_1, w_2, \dots, w_Mw1​,w2​,…,wM​.

  2. Compute the weighted sum: z=∑i=1Mwixi+bz = \sum_{i=1}^{M} w_i x_i + bz=∑i=1M​wi​xi​+b, where bbb is the bias term. The bias shifts the activation function left or right independently of the inputs.

  3. Pass zzz through a nonlinear activation function ggg to produce the output y=g(z)y = g(z)y=g(z).

Using vector notation: let x=[x1,x2,…,xM]\mathbf{x} = [x_1, x_2, \dots, x_M]x=[x1​,x2​,…,xM​] and w=[w1,w2,…,wM]\mathbf{w} = [w_1, w_2, \dots, w_M]w=[w1​,w2​,…,wM​]. Then:

y=g(w⋅x+b)y = g(\mathbf{w} \cdot \mathbf{x} + b)y=g(w⋅x+b)

where w⋅x\mathbf{w} \cdot \mathbf{x}w⋅x is the dot product (element-wise multiplication and summation).

Activation Functions and Nonlinearity

The purpose of an activation function is to introduce nonlinearities into the network. This is critical because real-world data is almost always nonlinear. Without nonlinearities, stacking multiple layers simply produces another linear function — no matter how deep the network is. With nonlinearities, neural networks can approximate arbitrarily complex functions.

Common activation functions:

  • Sigmoid: Takes any real number and maps it to a value between 0 and 1. Often used for binary classification — output can represent a probability.

    g(z)=11+e−zg(z) = \frac{1}{1 + e^{-z}}g(z)=1+e−z1​
  • ReLU (Rectified Linear Unit): g(z)=max⁡(0,z)g(z) = \max(0, z)g(z)=max(0,z) — widely used in practice for hidden layers.

  • Tanh: Maps to (-1, 1).

For example, with a sigmoid activation:

  • If z>0z > 0z>0, output > 0.5

  • If z<0z < 0z<0, output < 0.5

  • If z=0z = 0z=0, output = 0.5

A simple two-input perceptron (weights 3 and -2, bias -1) creates a 2D line. Inputs on one side of the line produce output > 0.5, on the other side < 0.5. This makes the perceptron a linear binary classifier.

Important: In practice, neural networks have hundreds to millions of parameters operating in high-dimensional spaces, making visualization of internal states difficult.


Constructing Neural Networks

From Single Neuron to Multi-Output Layers

To create a multi-output neural network, add more perceptrons. Each perceptron in the next layer connects to every input from the previous layer with its own set of weights. These are called dense layers (or fully connected layers).

For a layer with NNN outputs, there are NNN weight vectors (one per neuron) and NNN bias terms. The forward pass computes zj=∑iwjixi+bjz_j = \sum_{i} w_{ji} x_i + b_jzj​=∑i​wji​xi​+bj​ for each neuron jjj, then applies the activation.

Single Hidden Layer Neural Network

A single hidden layer network has:

  • Input layer: raw data

  • Hidden layer: intermediate representation (not directly observable — learned by the network)

  • Output layer: final prediction

Each connection between layers has its own weight matrix: W1\mathbf{W}_1W1​ between input and hidden, W2\mathbf{W}_2W2​ between hidden and output. A hidden unit is itself a perceptron — it takes a weighted sum of all inputs, applies a nonlinearity, and passes the result to the next layer.

Deep Neural Networks

A deep neural network is simply a stack of multiple hidden layers. Each layer learns progressively higher-level representations. Implementation in TensorFlow typically uses tf.keras.Sequential to chain layers together.

Example conceptual code (from lecture slides):

model = tf.keras.Sequential([
    tf.keras.layers.Dense(128, activation='relu'),   # hidden layer 1
    tf.keras.layers.Dense(64, activation='relu'),    # hidden layer 2
    tf.keras.layers.Dense(2, activation='sigmoid')   # output layer (binary classification)
])

The Dense layer is built-in — no need to implement the perceptron manually.


Training Neural Networks

Loss Functions (Quantifying Error)

To train a network, we first need to tell it when it is wrong. A loss function (also called cost function or objective function) measures the discrepancy between the network's prediction and the true answer. For multiple examples, the total loss is the average of individual losses:

J(W)=1N∑i=1NL(y(i),y^(i))J(\mathbf{W}) = \frac{1}{N} \sum_{i=1}^{N} L(y^{(i)}, \hat{y}^{(i)})J(W)=N1​∑i=1N​L(y(i),y^​(i))

where y(i)y^{(i)}y(i) is the true label and y^(i)\hat{y}^{(i)}y^​(i) is the prediction for example iii.

Common loss functions:

  • Binary classification (yes/no): Softmax cross-entropy loss — compares the predicted probability distribution to the true distribution.

    L=−[ylog⁡(y^)+(1−y)log⁡(1−y^)]L = -\left[ y \log(\hat{y}) + (1 - y) \log(1 - \hat{y}) \right]L=−[ylog(y^​)+(1−y)log(1−y^​)]
  • Regression (continuous output): Mean squared error (MSE) — takes the squared difference between prediction and true value.

    L=(y−y^)2L = (y - \hat{y})^2L=(y−y^​)2

Gradient Descent

The goal is to find the set of weights W\mathbf{W}W that minimize the total loss J(W)J(\mathbf{W})J(W).

Gradient descent algorithm:

  1. Initialize weights randomly.

  2. Compute the gradient of the loss with respect to each weight: ∂J∂wi\frac{\partial J}{\partial w_i}∂wi​∂J​. The gradient points in the direction of steepest increase (maximum ascent).

  3. Update weights in the opposite direction of the gradient to move downhill (decrease the loss): $$ w_i := w_i - \alpha \frac{\partial J}{\partial w_i} $wherewherewhere\alpha$ is the learning rate — a scalar that controls step size.

This process repeats until convergence to a local minimum. In high-dimensional spaces, the loss landscape is complex with many local minima, plateaus, and saddle points.

Backpropagation

The challenge is computing the gradients ∂J∂wi\frac{\partial J}{\partial w_i}∂wi​∂J​ for all weights efficiently. Backpropagation uses the chain rule from calculus to propagate the error signal from the output backwards through the network.

For a simple network with one hidden neuron and one output:

  • Gradient of loss with respect to w2w_2w2​ (weight between hidden and output):

    ∂J∂w2=∂J∂y⋅∂y∂w2\frac{\partial J}{\partial w_2} = \frac{\partial J}{\partial y} \cdot \frac{\partial y}{\partial w_2}∂w2​∂J​=∂y∂J​⋅∂w2​∂y​
  • Gradient of loss with respect to w1w_1w1​ (weight between input and hidden) requires further chain rule application:

    ∂J∂w1=∂J∂y⋅∂y∂z⋅∂z∂w1\frac{\partial J}{\partial w_1} = \frac{\partial J}{\partial y} \cdot \frac{\partial y}{\partial z} \cdot \frac{\partial z}{\partial w_1}∂w1​∂J​=∂y∂J​⋅∂z∂y​⋅∂w1​∂z​

This pattern continues — the chain rule is applied layer by layer from output back to input. Modern deep learning frameworks use automatic differentiation to perform backpropagation automatically, but understanding the underlying calculus is important.


Advanced Training Techniques

Learning Rate and Optimization

Setting the learning rate α\alphaα is critical:

  • Too small: Converges slowly and may get stuck in local minima.

  • Too large: Can overshoot the minimum and diverge.

Adaptive learning rates adjust the learning rate during training based on the landscape. Common optimizers:

  • SGD (Stochastic Gradient Descent): Vanilla gradient descent with fixed learning rate.

  • Adam, RMSprop, Adagrad: Adaptive methods that increase or decrease the learning rate depending on progress.

These are all available in TensorFlow and can be selected based on the problem.

Mini-Batch Gradient Descent

Computing the gradient over the entire dataset (full batch gradient descent) is computationally expensive for large datasets. Stochastic gradient descent uses a single randomly chosen data point per iteration — fast but noisy. Mini-batch gradient descent uses a mini-batch of BBB samples (e.g., 32, 64, 128) — a middle ground that is both efficient and accurate enough.

  • Advantage: More accurate gradient estimates than single-point SGD.

  • Advantage: Allows larger learning rates (more trust in the gradient).

  • Advantage: Massively parallelizable on GPUs — different batches can be split across devices.

The gradient estimate for a mini-batch is the average of the gradients for each sample in the batch.

Regularization: Preventing Overfitting

Overfitting occurs when a model memorizes the training data instead of learning generalizable patterns. The model performs well on training data but poorly on unseen test data.

Underfitting occurs when the model is too simple to capture the data's complexity.

Regularization techniques discourage complex, memorized representations.

Dropout

During training, randomly set some hidden neuron activations to zero with a given probability (e.g., 0.5). This forces the network to:

  • Build multiple independent pathways for making predictions.

  • Avoid relying on any single neuron (breaking memorization channels).

  • Generalize better to unseen data.

Each iteration samples a different random subset of neurons to drop.

Early Stopping

Monitor both training loss and test/validation loss during training. Initially both decrease. Eventually, the test loss starts to increase (inflection point) — the network has begun to overfit the training data. Stop training at that point to obtain the best generalization.


Summary of Key Concepts

  1. Perceptron (single neuron): Takes inputs, multiplies by weights, adds bias, passes through a nonlinear activation function.

  2. Stacking layers: Composition of perceptrons creates deep hierarchical representations.

  3. Training: Loss functions quantify error; backpropagation computes gradients via the chain rule; gradient descent updates weights to minimize loss.

  4. Practical considerations:

    • Mini-batching balances computational cost and gradient accuracy.

    • Adaptive learning rates improve convergence.

    • Regularization (dropout, early stopping) prevents overfitting and improves generalization.

These fundamentals provide the foundation for all modern deep learning applications — from computer vision and sequential modeling to generative models and reinforcement learning, which are covered in subsequent lectures of this course.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent