2. Feedforward Neural Networks

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/49

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 2:03 PM on 10/9/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

50 Terms

1
New cards

What is Feedforward Neural Network (FNN) and what its main goal?

  • FNN: maps inputs directly to outputs through a sequence of computational layers

    • information flows forward from input to output

    • Hidden layers learn intermediate representations

    • 2 important goals are expressiveness (what func the network can be represent) and trainability(how reliably it can learn them)


<ul><li><p><strong>FNN</strong>: maps inputs directly to outputs through a sequence of computational layers</p><ul><li><p>information flows <strong>forward</strong> from input to output</p></li><li><p>Hidden layers learn <strong>intermediate representations</strong></p></li><li><p>2 important goals are <strong>expressiveness</strong> (what func the network can be represent) and <strong>trainability</strong>(how reliably it can learn them)</p></li></ul></li></ul><p></p>
2
New cards

What is linear model and what its main limitation?

Linear model computes:

*form in pict

  • x = input

  • W = weights

  • b = bias

  • y(hat) = prediction

→ Linear model are simple and efficient but they cannot represent arbitrary nonlinear relationships


<p>Linear model computes:</p><p>*form in pict</p><ul><li><p>x = input</p></li><li><p>W = weights</p></li><li><p>b = bias</p></li><li><p>y(hat) = prediction </p></li></ul><p>→ Linear model are <strong>simple and efficient </strong>but they cannot represent arbitrary <strong>nonlinear relationships </strong></p><p></p>
3
New cards

What is linear decision boundary?

For binary classification, the equation:

*form in pict

→ defines a linear decision boundary

  • it separates classes using a straight line(in 2D) or a hyperplane(in higher dimensions)

  • Some datasets are linearly seperable, while other require more complex decisions regions


<p>For binary classification, the equation:</p><p>*form in pict</p><p>→ defines a <strong>linear decision boundary </strong></p><ul><li><p>it separates classes using a straight line(in 2D) or a hyperplane(in higher dimensions)</p></li><li><p>Some datasets are <strong>linearly seperable</strong>, while other require more complex decisions regions </p></li></ul><p></p>
4
New cards

What is XOR problem, and why can’t a single linear model solve it?

XOR output:

  • 1 when 2 binary inputs are different

  • 0 when they are the same


→ a single straight line cannot seperate 2 output classes

→ so, XOR demonstrates why neural networks need nonlinear computation


<p>XOR output:</p><ul><li><p> 1 when 2 binary inputs are different </p></li><li><p>0 when they are the same</p></li></ul><p></p><p>→ a single straight line cannot seperate 2 output classes</p><p>→ so, XOR demonstrates why neural networks need <strong>nonlinear computation</strong></p><p></p>
5
New cards

What is perceptron and how does it make predictions?

Perceptron: a trainable linear decision unit

  • it computes: *form in pict

    followed by decision function

    • each inputs contribute through a learned weight

    • Weighted inputs are combined

    • The bias shifts the decision boundary

    • Training changes w and b


<p><strong>Perceptron</strong>: a trainable linear decision unit</p><ul><li><p>it computes: *form in pict</p><p>followed by <strong>decision function </strong></p><ul><li><p>each inputs contribute through a learned weight</p></li><li><p>Weighted inputs are combined</p></li><li><p>The bias shifts the decision boundary </p></li><li><p>Training changes w and b</p></li></ul></li></ul><p></p>
6
New cards

How do weights and bias affect the decision boundary ?

  • weights, w, determine the boundary’s orientation

  • Bias, b, determine its position

  • Changing these parameters changes model’s decision rule

    → learning means changing these decision boundary


<ul><li><p><strong>weights</strong>, w, determine the boundary’s orientation</p></li><li><p><strong>Bias</strong>, b, determine its position</p></li><li><p>Changing these parameters changes model’s decision rule</p><p>→ learning means changing these decision boundary</p></li></ul><p></p>
7
New cards

Why is stacking multiple linear layers without activation functions insufficient?

*form in pict

  • Therefore, multiple linear or affine layers without nonlinear activations are equivalent to 1 affine transformation

  • Depth alone is not enough!!


<p>*form in pict</p><ul><li><p>Therefore, multiple linear or affine layers without nonlinear activations are equivalent to <strong>1 affine transformation </strong></p></li><li><p><strong>Depth alone is not enough!!</strong></p></li></ul><p></p>
8
New cards

What are hidden layers, and why are they useful?

Hidden layers: lie between input and output layers

  • Through transform representation step by step:

    x → h1 → h2 → y(hat)

  • Instead of predicting directly from input, the network learns intermediate features that help solve complex problems


<p><strong>Hidden layers: </strong>lie<strong> between input and output layers</strong></p><ul><li><p>Through transform representation step by step: </p><p>x → h1 → h2 → y(hat)</p></li><li><p>Instead of predicting directly from input, the network learns <strong>intermediate features</strong> that help solve complex problems </p></li></ul><p></p>
9
New cards

What is Multi-Layer Perceptron(MLP) and what are its 2 essential components?

MLP: combines linear transformations and nonlinear activation functions

For one hidden layer:

*form in pict

Its 2 essential components are:

  1. Linear Transformations → combine and transform features

  2. Nonlinear activations → allow complex nonlinear relationships


=> together, they create a more expressive function



<p><strong>MLP</strong>: combines linear transformations and nonlinear activation functions </p><p>For one hidden layer:</p><p>*form in pict</p><p>Its 2 essential components are:</p><ol><li><p><strong>Linear Transformations </strong>→ combine and transform features </p></li><li><p><strong>Nonlinear activations </strong>→ allow complex nonlinear relationships </p></li></ol><p></p><p>=&gt; together, they create a more expressive function </p><p></p><p></p>
10
New cards

Why do neural networks need nonlinear activation functions?

  • without nonlinear activation functions:

    Linear → Linear → Linear = Still linear

  • With nonlinear activations:

    Linear → Nonlinear → Linear = Can represent nonlinear functions

    => activation functions make depth meaningful by allowing network to learn complex patterns and decision boundaries


11
New cards

What is the Sigmoid activation function, and its properties?

*form in pict

  • Output range: (0,1)

  • Useful for interpreting outputs as probabilities

  • Saturates for very large positive or negative inputs

  • Saturation can cause small gradients, making learning difficult


<p>*form in pict</p><ul><li><p>Output range: <strong>(0,1)</strong></p></li><li><p>Useful for interpreting outputs as <strong>probabilities</strong></p></li><li><p>Saturates for very large positive or negative inputs</p></li><li><p>Saturation can cause <strong>small gradients</strong>, making learning difficult</p></li></ul><p></p>
12
New cards

What is the Tanh activation function, and its properties?

*form in pict

  • Output range: (-1,1)

  • Produces zero-centerd outputs

  • Like Sigmoid, it can suffer trom saturation


=> Main difference: Tanh is zero-centered, while Sigmoid outputs only positive values


<p>*form in pict</p><ul><li><p>Output range: <strong>(-1,1)</strong></p></li><li><p>Produces <strong>zero-centerd outputs </strong></p></li><li><p>Like Sigmoid, it can suffer trom <strong>saturation</strong></p></li></ul><p></p><p>=&gt; Main difference: <strong>Tanh is zero-centered</strong>, while <strong>Sigmoid outputs only positive values</strong></p><p></p>
13
New cards

What is ReLU and why is it widely used?

*form in pict

  • Negative inputs bcm 0

  • Positive inputs remain unchanged

  • Computation is simple and efficient

  • Positive activations avoid the same saturation behavior as Sigmoid and Tanh


→ ReLU is a standard activation in many DL networks



<p>*form in pict</p><ul><li><p>Negative inputs <strong>bcm 0</strong></p></li><li><p>Positive inputs remain <strong>unchanged</strong> </p></li><li><p>Computation is simple and efficient </p></li><li><p>Positive activations avoid the same saturation behavior as Sigmoid and Tanh</p></li></ul><p></p><p>→ <strong>ReLU is a standard activation </strong>in many DL networks </p><p></p><p></p>
14
New cards

What is theDying ReLU problem?

Dying ReLU occurs when a neuron remains in the negative-input region

  • Because ReLU outputs 0 for negative input, its gradient is also 0

  • As a result, the neuron may stop receiving gradients and fail to learn


15
New cards

What is Leaky ReLU and how does it differ from Dying ReLU?

*form in pict

  • Unlike standard ReLU, Leaky ReLU allows small nonzero gradient for negative inputs

  • This helps reduce the Dying ReLU problem while preserving a simple piecewise-linear structure


<p>*form in pict</p><ul><li><p>Unlike standard ReLU, Leaky ReLU allows <strong>small nonzero gradient for negative inputs</strong></p></li><li><p>This helps <strong>reduce the Dying ReLU problem</strong> while preserving a simple piecewise-linear structure</p></li></ul><p></p>
16
New cards

What is network depth, and what happens when depth increases?

Depth: number of sequential computational layers or stages

x → h1 → h2 → … → hL → y(hat)

Increasing depth provides:

  • More stages of transformation

  • More opportunities for intermediate representation

  • More complex function composition


<p><strong>Depth</strong>: number of sequential computational layers or stages</p><p>x → h1 → h2 → … → hL → y(hat)</p><p>Increasing depth provides:</p><ul><li><p>More stages of transformation</p></li><li><p>More opportunities for intermediate representation</p></li><li><p>More complex function composition</p></li></ul><p></p>
17
New cards

What is network width, and what happens when width increases?

Width: Number of hidden units or features within a layer

* From the picture

→ hidden representation has 512 features

  • Increasing width provides more parallel representational capacity within the same computational stage


<p><strong>Width</strong>: Number of hidden units or features within a layer</p><p>* From the picture</p><p>→ hidden representation has <strong>512 features</strong></p><ul><li><p>Increasing width provides more <strong>parallel representational capacity </strong>within the same computational stage</p></li></ul><p></p>
18
New cards

What is the difference between network depth and width?

  • Depth = more transformations

  • Width = More features


<ul><li><p>Depth = more transformations</p></li><li><p>Width = More features</p></li></ul><p></p>
19
New cards

What are hierarchical representations in deep learning?

Deep networks can gradually build complex features from simpler ones

  • For image recognition:

    Pixels → Edges → Shapes → Objects

    • Early layers learn simple features

    • Intermediate layers combined them

    • Later layers form task-relevant representations

  • Later layes operate on features learned by earlier layers


<p>Deep networks can gradually build <strong>complex features from simpler ones </strong></p><ul><li><p>For image recognition:</p><p><strong>Pixels → Edges → Shapes → Objects</strong></p><ul><li><p>Early layers learn simple features</p></li><li><p>Intermediate layers combined them</p></li><li><p>Later layers form task-relevant representations</p></li></ul></li><li><p>Later layes operate on features learned by earlier layers</p></li></ul><p></p>
20
New cards

Why can deep neural networks be viewed as compositions of functions?

  • Each layer performs a transformation, and its output becomes the input to the next layer

    *form in the picture

  • This allows complex functions to be constructed from simpler functions

  • Depth changes the structure of computation, not just the number of parameters


<ul><li><p>Each layer performs a transformation, and its output becomes the input to the next layer</p><p>*form in the picture</p></li><li><p>This allows <strong>complex functions to be constructed from simpler functions </strong></p></li><li><p>Depth changes the structure of computation, not just the number of parameters </p></li></ul><p></p>
21
New cards

What is Universal Approximation and what does it NOT guarantee?

Universal Approximation states that sufficiently large nonlinear neural network can approximate a broad class of functions

  • it demonstrates the network’s expressive power

  • However, it does NOT guarantee:

    • how large the network must be

    • Easy optimisation

    • Sufficient training data

    • Good generalisation to unseen data

=> Expressive ≠ Easy to Train


<p><strong>Universal Approximation</strong> states that sufficiently large nonlinear neural network can approximate a <strong>broad class of functions </strong></p><ul><li><p>it demonstrates the network’s <strong>expressive power</strong></p></li><li><p>However, it does NOT guarantee:</p><ul><li><p>how large the network must be</p></li><li><p>Easy optimisation</p></li><li><p>Sufficient training data</p></li><li><p>Good generalisation to unseen data</p></li></ul></li></ul><p>=&gt; <strong>Expressive ≠ Easy to Train</strong></p><p></p>
22
New cards

Why do the output layer and loss function depend on the prediction task?

Different task required different types of predictions and error measurements

  • 3 Common tasks:

    • Regression → Continuous value

    • Binary classification → Two classes

    • Multiclass classification → Multiple classes

  • For each task, we decide what the model outputs, how to interpret it, and how to measure its error

=> Task → Output → Loss


<p>Different task required different types of predictions and error measurements </p><ul><li><p>3 Common tasks:</p><ul><li><p><strong>Regression</strong> → Continuous value</p></li><li><p><strong>Binary classification</strong> → Two classes</p></li><li><p><strong>Multiclass classification</strong> → Multiple classes </p></li></ul></li><li><p>For each task, we decide what the model outputs, how to interpret it, and how to measure its error </p></li></ul><p>=&gt;  <strong>Task → Output → Loss</strong></p><p></p>
23
New cards

What is regression and what output does it require?

Regression: Predicts continuous numerical values

e.g:

  • House prices

  • Temperatures

  • Demand forecast


*typical output in pict

=> The final layer directly produces a continuous value, so no probability transformation is required


<p>Regression: Predicts <strong>continuous numerical values</strong></p><p>e.g:</p><ul><li><p>House prices</p></li><li><p>Temperatures</p></li><li><p>Demand forecast</p></li></ul><p></p><p>*typical output in pict</p><p>=&gt; The final layer directly produces a continuous value, so <strong>no probability transformation is required </strong></p><p></p>
24
New cards

What is Mean Squared Error (MSE) and why is it used for regression?

MSE: measures the average squared deifference between predictions and targets

*form in pict

  • Correct prediction→ 0 error

  • Large errors receive large penalties

  • Commonly used for continuous regression


=> Regression → Continuous Output → MSE


<p><strong>MSE</strong>: measures the average <strong>squared deifference between predictions and targets</strong></p><p>*form in pict</p><ul><li><p>Correct prediction→ 0 error</p></li><li><p>Large errors receive <strong>large penalties </strong></p></li><li><p>Commonly used for continuous regression </p></li></ul><p></p><p>=&gt; <strong>Regression → Continuous Output → MSE</strong></p><p></p>
25
New cards

What is binary classification and how does Sigmoid help?

Binary classification: predicts btw 2 classes, such as spam/not spam or disease/no disease

  • the model produces one raw score called a logit, *in pict

  • Sigmoid converts it into a probability:

    *in pict

  • The resulting probability lies between 0 and 1


<p><strong>Binary classification</strong>: predicts btw <strong>2 classes</strong>, such as spam/not spam or disease/no disease</p><ul><li><p>the model produces one raw score called a <strong>logit</strong>, *in pict</p></li><li><p>Sigmoid converts it into a probability:</p><p>*in pict</p></li><li><p>The resulting probability lies between <strong>0 and 1</strong></p></li></ul><p></p>
26
New cards

What is Binary Cross-Entropy(BCE) and how does it penalize predictions?

BCE: Measures prediction error for binary classification

*form in pict

  • correct, high-confidence prediction → low loss

  • Incorrect, high-confidence prediction → high loss

=> it encourages predicted probabilities to move toward the correct labels


<p><strong>BCE</strong>: Measures <strong>prediction error</strong> for binary classification </p><p>*form in pict</p><ul><li><p><strong>correct</strong>, high-confidence prediction → <strong>low loss</strong></p></li><li><p><strong>Incorrect</strong>, high-confidence prediction → <strong>high loss</strong></p></li></ul><p>=&gt; it encourages predicted probabilities to move toward the correct labels</p><p></p>
27
New cards

What is ‘nn.BCEWithLogitsLoss()’ and why is it preferred in PyTorch?

‘nn.BCEWithLogitsLoss()’ combines:

Sigmoid + Binary Cross-Entropy

  • it:

    • accepts raw logits

    • Internally performs the necessary calculations

    • Provides better numerical stability

  • Therefore, you should not manually apply Sigmoid before passing logits to this loss function


28
New cards

What is multiclass classification and how does Softmax work?

Multiclass classification predicts among K classes

  • The model produce K logits, one for each class

  • e.g: z = [2.1,-0.4,0.8]

    Softmax converts them into class probabilities:

    *form in pict

  • The probabilities sum to 1, and higher logits correspond to higher probabilities


<p>Multiclass classification predicts among <strong>K classes</strong></p><ul><li><p>The model produce <strong>K logits,</strong> one for each class</p></li><li><p>e.g: z = [2.1,-0.4,0.8]</p><p>Softmax converts them into class probabilities:</p><p>*form in pict</p></li><li><p>The probabilities sum to <strong>1</strong>, and higher logits correspond to higher probabilities </p></li></ul><p></p>
29
New cards

How do regression, binary classification, and multiclass classification differ in output and loss?

  • Regression use prediction directly

  • Binary classification interprets logit through Sigmoid

  • Multiclass classification use Softmax probabilities


<ul><li><p><strong>Regression</strong> use prediction directly</p></li><li><p><strong>Binary classification</strong> interprets logit through Sigmoid</p></li><li><p><strong>Multiclass classification</strong> use Softmax probabilities</p></li></ul><p></p>
30
New cards

Why is weight initialisation important before training begins?

Every weight needs an initial value before training

Initialisation affects:

  • Activation magnitude

  • Gradient magnitude

  • Whether neuron can learn different features

  • Stability of signals across layers

Poor initialisation can make training difficult even with a good architecture


31
New cards

Why shouldn’t all hidden-layer weights be initialised to 0?

Initialising all hidden neurons identically creates a symmetry problem

Identical neurons:

  1. Receive identical inputs

  2. Produce identical outputs

  3. Receive identical gradients

  4. Remain identical after updates

→ Therefore, random initialisation breaks symmetry, allowing different neurons to learn different features


32
New cards

What happens when initial weights are too small or too large?

Weight too small:

  • Activation may shrinks across layers

  • Information can gradually disappear


Weight too large:

  • Activation may grow rapidly

  • Computation may become unstable


→ Good initialisation maintains a useful signal scale throughout the network


33
New cards

What is the difference between Xavier and He initialization?

Xavier/Glorot initialization:

  • Designed to preserve signal scale

  • Commonly associated with Sigmoid and Tanh networks


He/Kaiming initialization:

  • Account for the behaviour of ReLU-like activations

  • Commonly used in ReLU-based networks


→ initialisation should reflect both layer size and activation function


34
New cards

Why can gradients become unstable when travelling through deep networks?

  • Backpropagation repeatedly applies the chain rule

  • The gradient for an early parameter depends on products of many local derivatives

  • If this derivatives repeatedly have magnitude that are too small or too large, the gradients may vanish or explode

  • This affects whether useful learning signals reach earlier layers


<ul><li><p>Backpropagation repeatedly applies the <strong>chain rule</strong></p></li><li><p>The gradient for an early parameter depends on products of many local derivatives </p></li><li><p>If this derivatives repeatedly have magnitude that are too small or too large, the gradients may <strong>vanish or explode </strong></p></li><li><p>This affects whether useful learning signals reach earlier layers</p></li></ul><p></p>
35
New cards

What are vanishing gradient and why do they make learning difficult?

Vanishing gradients: occur when gradients become extremely small during backpropagation

  • For example: 0.5×0.5×0.5×… → 0

  • Consequences:

    • Earlier layers received tiny ingredients

    • Parameter updates become very small

    • Learning in early layers becomes ineffective


36
New cards

What are exploding gradient and how do they affect training?

Exploding gradient: occur when gradient become extremely large

  • For example: 2×2×2×… → Very large

  • Consequences:

    • Parameter updates become unstable

    • Loss may oscillate

    • Training may diverge


37
New cards

What is the difference between underfitting and overfitting?

Underfitting:

  • Training performance is poor

  • Validation performance is also poor

  • The model has not learned the underlying relationship adequately


Overfitting:

  • Training performance is very good

  • Validation performance is much worse

  • The model learn training-specific patterns that do not generalise well


<p><strong>Underfitting</strong>:</p><ul><li><p>Training performance is <strong>poor</strong></p></li><li><p>Validation performance is also <strong>poor</strong></p></li><li><p>The model has <strong>not learned</strong> the underlying relationship adequately</p></li></ul><p></p><p><strong>Overfitting</strong>:</p><ul><li><p>Training performance is <strong>very good</strong></p></li><li><p>Validation performance is <strong>much worse</strong></p></li><li><p>The model learn training-specific patterns that <strong>do not generalise well </strong></p></li></ul><p></p>
38
New cards

How does model capacity affect generalisation?

Increasing model capacity generally allows the model to fit training data better

However:

  • Training error often decreases

  • Validation error may decrease initially then increase

  • Excessive capacity can make overfitting easier

The goal is not simply no training error but good performance on unseen data


39
New cards

What is regularisation and why is it needed?

Regularisation: Modify training to discourage and desirable solutions

The goals are to:

  • Reduce overfitting

  • Improve generalisation

  • Encourage robust representations


Common methods include:

  • Weight decay

  • Dropout

  • Early stopping


40
New cards

What is weight decay and how does it help regularisation?

Weight decay: Discourage excessively large parameter values

  • L2-regularization intuition:

    *form in pict

  • This encourages less extreme perimeter configurations

  • Some modern optimisers implement weight decay differently from a direct L2 penalty


<p><strong>Weight decay:</strong> Discourage <strong>excessively large parameter values</strong></p><ul><li><p>L2-regularization intuition:</p><p>*form in pict</p></li><li><p>This encourages less extreme perimeter configurations</p></li><li><p>Some modern optimisers implement weight decay differently from a direct L2 penalty </p></li></ul><p></p>
41
New cards

What is dropout and how does it differ between training and inference?

Dropout: randomly sets some hidden activations to zero during training.

  • This prevents the model from depending on the same neurons every time.

  • Training: Random subsets of neurons are disabled, effectively training different subnetworks.

  • Inference: The full network is used.

→ Dropout helps reduce overfitting.

<p><strong>Dropout:</strong> randomly sets some hidden activations to <strong>zero during training</strong>.</p><ul><li><p>This prevents the model from depending on the same neurons every time.</p></li><li><p><strong>Training:</strong> Random subsets of neurons are disabled, effectively training different subnetworks.</p></li><li><p><strong>Inference:</strong> The full network is used.</p></li></ul><p>→ Dropout helps reduce overfitting.</p>
42
New cards

What is early stopping, and why is it useful?

Early stopping: monitors validation performance during training.

  • Training loss may continue decreasing even after validation loss stops improving.

  • Continuing too long may cause overfitting.

  • Early stopping prevents training far beyond the point where validation performance is useful.


<p><strong>Early stopping: </strong>monitors <strong>validation performance</strong> during training.</p><ul><li><p>Training loss may continue decreasing even after validation loss stops improving.</p></li><li><p>Continuing too long may cause <strong>overfitting</strong>.</p></li><li><p>Early stopping prevents training far beyond the point where validation performance is useful.</p></li></ul><p></p>
43
New cards

What should we examine when analyzing training and validation curves?

Examine:

  1. Training loss → how well the model fits training data

  2. Validation loss → how well it performs on held-out data

  3. Gap between curves → possible generalization problems

  4. Trends → whether either curve is improving or becoming unstable


=> these patterns help diagnose training problems


<p>Examine:</p><ol><li><p><strong>Training loss </strong>→ how well the model fits training data</p></li><li><p><strong>Validation loss</strong> → how well it performs on held-out data</p></li><li><p><strong>Gap between curves </strong>→ possible generalization problems</p></li><li><p><strong>Trends</strong> → whether either curve is improving or becoming unstable </p></li></ol><p></p><p>=&gt; these patterns help diagnose training problems </p><p></p>
44
New cards

How can training curves reveal healthy training, underfitting, overfitting, or optimization failure?

These are useful diagnostic patterns, not absolute rules.

<p><span>These are useful diagnostic patterns, not absolute rules.</span></p>
45
New cards

What actions can improve different training problems?

  • Healthy training: Continue or monitor

  • Underfitting: Consider more model capacity or better optimisation

  • Overfitting: Use regularisation or early stopping

  • Optimisation failure: Check learning rate, initialisation, and gradients

=> Training curve help distinguish architecture, optimisation, and generalisation problems

46
New cards

How is an MLP implemented in PyTorch, and what does each layer do?

  • fc1 transforms 784 → 256 features.

  • fc2 transforms 256 → 128 features.

  • fc3 transforms 128 → 10 output logits.

  • F.relu() adds nonlinearity after the first two layers.


<ul><li><p><span>fc1 transforms <strong>784 → 256</strong> features.</span></p></li><li><p><span>fc2 transforms <strong>256 → 128</strong> features.</span></p></li><li><p><span>fc3 transforms <strong>128 → 10</strong> output logits.</span></p></li><li><p><span>F.relu() adds nonlinearity after the first two layers.</span></p></li></ul><p></p>
47
New cards

How do tensor shapes changes through this MLP?

For batch size B:

[B,784] → [B,256] → [B,128] → [B,10]

  • Linear layers change the feature dimension

  • ReLU preserves the tensor shape

  • The final dimension corresponds to the 10 classes

=> an important skill is predicting the tensor shape after every layer


<p>For batch size B:</p><p>[B,784] → [B,256] → [B,128] → [B,10]</p><ul><li><p>Linear layers change the <strong>feature dimension</strong></p></li><li><p>ReLU preserves the <strong>tensor shape</strong></p></li><li><p>The final dimension corresponds to the <strong>10 classes</strong></p></li></ul><p>=&gt; an important skill is predicting the tensor shape after every layer</p><p></p>
48
New cards

Why is Softmax not required before ‘nn.CrossEntropyLoss()’?

  • The model returns 10 raw logits per example.

  • ‘CrossEntropyLoss’ internally performs the necessary normalization and loss calculation.

  • Therefore, adding Softmax before it is unnecessary.

  • The loss transforms the logits of shape [B, 10] into a scalar loss by default.

=> [B,10] → CrossEntropyLoss → Scalar Loss

<ul><li><p>The model returns <strong>10 raw logits per example</strong>.</p></li><li><p>‘CrossEntropyLoss’ internally performs the necessary normalization and loss calculation.</p></li><li><p>Therefore, adding Softmax before it is <strong>unnecessary</strong>.</p></li><li><p>The loss transforms the logits of shape [B, 10] into a scalar loss by default.</p></li></ul><p>=&gt;<strong> [B,10] → CrossEntropyLoss → Scalar Loss</strong></p>
49
New cards

How does the MLP connect to the PyTorch training loop?

  • The training principle remains the same as Lecture 1:

Clear gradients → Forward pass → Loss → Backward pass → Update

  • The difference is that model(x) now represents a multi-layer nonlinear function, and backpropagation automatically computes gradients through its differentiable layers.


<ul><li><p>The training principle remains the same as Lecture 1:</p></li></ul><p><strong>Clear gradients → Forward pass → Loss → Backward pass → Update</strong></p><ul><li><p>The difference is that model(x) now represents a <strong>multi-layer nonlinear function</strong>, and backpropagation automatically computes gradients through its differentiable layers.</p></li></ul><p></p>
50
New cards

What makes a Multi-Layer Perceptron powerful, trainable, and able to generalize?

A useful MLP needs three qualities:

1. Expressiveness

Depth + Width + Nonlinearity

These provide nonlinear decision boundaries, intermediate representations, hierarchical computation, and high functional capacity.

2. Trainability

Initialization + Stable Gradients + Optimization

These help the network learn reliably.

3. Generalization

Appropriate Capacity + Regularization + Validation

These help the model perform well on unseen data.

Core idea: A successful neural network must be expressive enough to represent useful functions, trainable enough to learn them, and regularized enough to generalize.