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

Study methods

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

Deep Learning Intro

  • 26Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Logistic Regression as a Neuron

How can logistic regression be interpreted as a neural network?

26 questions

  1. 1

    How can logistic regression be interpreted as a neural network?

    Model answer

    Logistic regression can be interpreted as a single neuron with a linear part wTx+bw^T x + bwTx+b followed by a sigmoid activation function, making it a one-neuron neural network.

    Explanation

    The lecture defines a neuron as linear plus activation, and logistic regression fits that structure exactly, with the sigmoid as the activation.

  2. 2

    For a 64x64 color image, what is the size of the flattened input vector xxx?

    Model answer

    The flattened vector has dimension 64×64×3=12,28864\times64\times3 = 12,28864×64×3=12,288.

    Explanation

    Each pixel has three RGB values, so total numbers = height * width * channels.

  3. 3

    In logistic regression for cat detection, if the input vector xxx has shape n×1n\times1n×1, what are the shapes of www and bbb such that y^=σ(wTx+b)\hat{y} = \sigma(w^T x + b)y^​=σ(wTx+b) is a scalar?

    Model answer

    www is 1×n1\times n1×n (row vector), bbb is 1×11\times11×1 (scalar), so wTx+bw^T x + bwTx+b is a scalar.

    Explanation

    To get a scalar output, www must have dimensions 1×n1 \times n1×n and bbb a scalar.

  4. 4

    How many parameters (weights and biases) does a logistic regression model have for a 64x64 color image?

    Model answer

    12,288 weights (since input size is 12,288) and 1 bias, giving 12,289 total parameters.

    Explanation

    Number of weights equals input size, plus one bias.

  5. 5

    What is the formula for logistic regression’s loss function (binary cross-entropy) for a single example?

    Model answer

    L(y^,y)=−(ylog⁡y^+(1−y)log⁡(1−y^))L(\hat{y}, y) = -\left( y \log\hat{y} + (1-y)\log(1-\hat{y}) \right)L(y^​,y)=−(ylogy^​+(1−y)log(1−y^​))

    Explanation

    This loss is derived from maximum likelihood estimation and penalizes deviation between predicted probability and true label.

  6. 6

    Explain the two steps of the training process for logistic regression as described in the lecture.

    Model answer

    First, initialize parameters www and bbb. Then, repeatedly compute gradients of the loss and update parameters using gradient descent to minimize the loss.

    Explanation

    The process is: initialize, then loop over gradient descent steps until convergence.

  7. 7

    If you want to classify images into three classes (cat, lion, iguana) with the possibility of multiple animals in one image, what output activation should you use and why?

    Model answer

    Use three separate sigmoid neurons (one per class) because sigmoid outputs independent probabilities for each class, allowing multiple classes to be present.

    Explanation

    Sigmoid gives independent probabilities; the three outputs do not sum to 1, so multiple can be high simultaneously.

  8. 8

    What is the softmax function formula for class iii given three neurons with linear outputs z1,z2,z3z_1, z_2, z_3z1​,z2​,z3​?

    Model answer

    y^i=ezi∑k=13ezk\hat{y}_i = \frac{e^{z_i}}{\sum_{k=1}^{3} e^{z_k}}y^​i​=∑k=13​ezk​ezi​​

    Explanation

    Softmax converts the zzz values into a probability distribution that sums to 1.

  9. 9

    Why is a network with three sigmoid neurons not suitable when the labels are one-hot (only one class per image)?

    Model answer

    The sigmoid outputs can sum to more than 1, but the labels sum to 1; the network would need to learn to output probabilities that sum to 1, but sigmoid does not enforce that, leading to inconsistent predictions.

    Explanation

    For mutually exclusive classes, softmax is preferred because it naturally produces a valid probability distribution.

  10. 10

    How many parameters does the three-neuron sigmoid network (for three classes) have if the input dimension is nnn?

    Model answer

    Each neuron has nnn weights and 1 bias, so total parameters = 3n+33n + 33n+3.

    Explanation

    Three neurons, each with a weight vector of size nnn and a bias, hence 3n+33n+33n+3.

  11. 11

    Write the loss function for the three-neuron sigmoid multi-class network (assuming one-hot labels) and explain why it can be viewed as three separate logistic regressions.

    Model answer

    L=−∑k=13(yklog⁡y^k+(1−yk)log⁡(1−y^k))L = -\sum_{k=1}^{3} \left( y_k \log \hat{y}_k + (1-y_k) \log(1-\hat{y}_k) \right)L=−∑k=13​(yk​logy^​k​+(1−yk​)log(1−y^​k​)). The gradient for each neuron’s parameters depends only on that neuron’s output, so they can be trained independently.

    Explanation

    The loss is the sum of independent binary cross-entropy losses; derivatives for each neuron are unaffected by the others.

  12. 12

    For a regression task (e.g., predicting cat age), what changes would you make to the logistic regression model?

    Model answer

    Replace the sigmoid activation with a linear or ReLU activation (to allow outputs beyond 0-1) and change the loss to L2 loss or mean squared error.

    Explanation

    Age is a continuous positive value; linear activation (or ReLU to enforce non-negativity) and MSE loss are appropriate.

  13. 13

    In a neural network with one hidden layer of size 3 and an input of size nnn, what is the shape of the weight matrix W[1]W^{[1]}W[1] connecting the input to the hidden layer?

    Model answer

    W[1]W^{[1]}W[1] has shape 3×n3 \times n3×n (3 neurons in hidden layer, nnn input features).

    Explanation

    Each hidden neuron has nnn weights, so total weights form a 3×n3 \times n3×n matrix.

  14. 14

    Define the terms: input layer, hidden layer, output layer.

    Model answer

    Input layer: the first layer that receives raw data. Hidden layer: any layer between input and output; its neurons do not directly see inputs or outputs. Output layer: the final layer that produces the prediction.

    Explanation

    Hidden layers learn intermediate representations; output layer size equals number of classes or 1 for regression.

  15. 15

    Why are neural networks sometimes called 'black box' models?

    Model answer

    Because the internal representations learned by hidden layers (e.g., which features each neuron detects) are not easily interpretable by humans, even though the network may perform well.

    Explanation

    The learned features are often abstract and not directly understandable, leading to the black box characterization.

  16. 16

    For a neural network with input size nnn, hidden layer size hhh, and output size ooo, how many parameters are there if the network is fully connected?

    Model answer

    (n×h+h)(n \times h + h)(n×h+h) for the first layer plus (h×o+o)(h \times o + o)(h×o+o) for the second, total nh+h+ho+onh + h + ho + onh+h+ho+o.

    Explanation

    Each connection is a weight, each neuron has a bias. Count edges plus biases per layer.

  17. 17

    Write the forward propagation equations for a 3-layer neural network (input, hidden, output) with sigmoid activations, using matrix notation.

    Model answer

    Z[1]=W[1]X+b[1]Z^{[1]} = W^{[1]} X + b^{[1]}Z[1]=W[1]X+b[1], A[1]=σ(Z[1])A^{[1]} = \sigma(Z^{[1]})A[1]=σ(Z[1]), Z[2]=W[2]A[1]+b[2]Z^{[2]} = W^{[2]} A^{[1]} + b^{[2]}Z[2]=W[2]A[1]+b[2], A[2]=σ(Z[2])A^{[2]} = \sigma(Z^{[2]})A[2]=σ(Z[2]), Z[3]=W[3]A[2]+b[3]Z^{[3]} = W^{[3]} A^{[2]} + b^{[3]}Z[3]=W[3]A[2]+b[3], y^=σ(Z[3])\hat{y} = \sigma(Z^{[3]})y^​=σ(Z[3]).

    Explanation

    This shows matrix multiplications and element-wise sigmoid for each layer.

  18. 18

    Explain why broadcasting is needed when implementing forward propagation with a batch of mmm examples.

    Model answer

    When adding bias bbb, which has shape (nl,1)(n_l, 1)(nl​,1), to the matrix WXW XWX of shape (nl,m)(n_l, m)(nl​,m), broadcasting replicates the bias mmm times to match dimensions, enabling parallel computation without increasing parameters.

    Explanation

    Broadcasting allows element-wise addition between matrices of different shapes by repeating the smaller matrix.

  19. 19

    What are the shapes of Z[1]Z^{[1]}Z[1], W[1]W^{[1]}W[1], XXX, and b[1]b^{[1]}b[1] when processing a batch of mmm examples with nnn features and a hidden layer of size hhh?

    Model answer

    XXX: (n,m)(n, m)(n,m), W[1]W^{[1]}W[1]: (h,n)(h, n)(h,n), b[1]b^{[1]}b[1]: (h,1)(h, 1)(h,1), Z[1]Z^{[1]}Z[1]: (h,m)(h, m)(h,m).

    Explanation

    Matrix multiplication W[1]XW^{[1]}XW[1]X produces (h,m)(h, m)(h,m); adding bias broadcasts to the same shape.

  20. 20

    What is the key idea behind backpropagation?

    Model answer

    Backpropagation uses the chain rule of calculus to efficiently compute gradients of the loss with respect to all parameters by propagating errors from the output layer backward through the network.

    Explanation

    Gradients are computed layer by layer from output to input, reusing previously computed values to avoid redundant calculations.

  21. 21

    When computing the gradient ∂J∂W[2]\frac{\partial J}{\partial W^{[2]}}∂W[2]∂J​, why is it easier to start with ∂J∂Z[2]\frac{\partial J}{\partial Z^{[2]}}∂Z[2]∂J​?

    Model answer

    Because Z[2]Z^{[2]}Z[2] is directly related to W[2]W^{[2]}W[2] (Z[2]=W[2]A[1]+b[2]Z^{[2]} = W^{[2]} A^{[1]} + b^{[2]}Z[2]=W[2]A[1]+b[2]), and the derivative ∂Z[2]∂W[2]=A[1]T\frac{\partial Z^{[2]}}{\partial W^{[2]}} = A^{[1]T}∂W[2]∂Z[2]​=A[1]T is simple, while JJJ depends on W[2]W^{[2]}W[2] only through Z[2]Z^{[2]}Z[2].

    Explanation

    Chain rule: ∂J∂W[2]=∂J∂Z[2]∂Z[2]∂W[2]\frac{\partial J}{\partial W^{[2]}} = \frac{\partial J}{\partial Z^{[2]}} \frac{\partial Z^{[2]}}{\partial W^{[2]}}∂W[2]∂J​=∂Z[2]∂J​∂W[2]∂Z[2]​, and the latter is easy to compute.

  22. 22

    How does the derivative of the sigmoid function simplify calculations in backpropagation?

    Model answer

    The derivative of sigmoid is σ(z)(1−σ(z))\sigma(z)(1-\sigma(z))σ(z)(1−σ(z)), which can be expressed in terms of the activation a=σ(z)a = \sigma(z)a=σ(z): dσdz=a(1−a)\frac{d\sigma}{dz} = a(1-a)dzdσ​=a(1−a), making it easy to compute from forward pass values.

    Explanation

    This allows reuse of stored activations to compute gradients efficiently.

  23. 23

    Explain the practical difference between stochastic gradient descent (SGD) and batch gradient descent.

    Model answer

    SGD updates parameters after each single example, leading to noisy gradients but faster iterations. Batch gradient descent computes the gradient over the entire dataset, giving a more accurate direction but slower per iteration.

    Explanation

    The lecture notes that SGD gradient is noisier; batch gradient uses the average gradient over all examples.

  24. 24

    How would you choose the number of layers and neurons for a neural network in practice?

    Model answer

    Try several architectures, train them, and compare validation set accuracies; the best performing architecture is selected. Experience and problem complexity also guide choices (more complex problems often need deeper networks).

    Explanation

    Hyperparameter tuning via validation set is standard; heuristics suggest deeper networks for harder tasks.

  25. 25

    What does 'end-to-end learning' mean in the context of neural networks?

    Model answer

    End-to-end learning means training a neural network directly from raw input to desired output without manually engineered intermediate features; the network learns all necessary representations.

    Explanation

    The lecture contrasts this with hand-engineering features; the network learns from input-output pairs alone.

  26. 26

    For a dataset where each image contains at most one of three animal types (cat, lion, iguana), which output activation and loss function should be used?

    Model answer

    Use softmax activation (to produce a probability distribution summing to 1) and cross-entropy loss L=−∑k=13yklog⁡y^kL = -\sum_{k=1}^{3} y_k \log \hat{y}_kL=−∑k=13​yk​logy^​k​.

    Explanation

    Softmax enforces mutual exclusivity; cross-entropy is the standard loss for multi-class classification.

1 of 26
Question 1 of 26

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent