Bird
Raised Fist0
ML Pythonml~12 mins

Forward propagation in ML Python - Model Pipeline Trace

Choose your learning style10 modes available
Model Pipeline - Forward propagation

Forward propagation is the process where input data moves through a neural network layer by layer to produce an output prediction.

Data Flow - 3 Stages
1Input Layer
1 sample x 3 features→Receive raw input features→1 sample x 3 features
[0.5, 0.1, 0.4]
↓
2Hidden Layer
1 sample x 3 features→Multiply inputs by weights, add bias, apply activation (ReLU)→1 sample x 4 neurons
[0.7, 0.0, 1.2, 0.3]
↓
3Output Layer
1 sample x 4 neurons→Multiply by weights, add bias, apply activation (sigmoid)→1 sample x 1 output
[0.85]
Training Trace - Epoch by Epoch
Loss
0.7 |****
0.6 |*** 
0.5 |**  
0.4 |*   
0.3 |    
0.2 |    
     1 2 3 4 5 Epochs
EpochLoss ↓Accuracy ↑Observation
10.650.55Initial random weights, loss high, accuracy low
20.480.70Weights updated, loss decreased, accuracy improved
30.350.82Model learning well, loss continues to drop
40.280.88Good convergence, accuracy nearing high values
50.220.92Training stabilizing with low loss and high accuracy
Prediction Trace - 3 Layers
Layer 1: Input Layer
Layer 2: Hidden Layer (Weights * Input + Bias, ReLU)
Layer 3: Output Layer (Weights * Hidden + Bias, Sigmoid)
Model Quiz - 3 Questions
Test your understanding
What is the main purpose of the activation function in forward propagation?
ATo shuffle the input features randomly
BTo add non-linearity so the model can learn complex patterns
CTo reduce the size of the input data
DTo convert outputs into integer values
Key Insight
Forward propagation transforms input data through weighted sums and activation functions to produce predictions. Activation functions like ReLU and sigmoid help the model learn complex patterns and output probabilities.

Practice

(1/5)
1. What is the main purpose of forward propagation in a neural network?
easy
A. To pass input data through the network to get predictions
B. To update the weights using gradients
C. To split data into training and testing sets
D. To initialize the weights randomly

Solution

  1. Step 1: Understand forward propagation role

    Forward propagation is the process where input data moves through the network layers to produce output predictions.
  2. Step 2: Differentiate from other processes

    Updating weights and splitting data are separate steps, not part of forward propagation.
  3. Final Answer:

    To pass input data through the network to get predictions -> Option A
  4. Quick Check:

    Forward propagation = prediction step [OK]
Hint: Forward propagation = input to output prediction [OK]
Common Mistakes:
  • Confusing forward propagation with training steps
  • Thinking it updates weights
  • Mixing it with data preparation
2. Which of the following is the correct formula for calculating the output of a neuron during forward propagation?
easy
A. output = input / weight - bias
B. output = weight + input * bias
C. output = activation(input - weight + bias)
D. output = activation(weight * input + bias)

Solution

  1. Step 1: Recall neuron output formula

    The neuron output is calculated by multiplying input by weight, adding bias, then applying activation.
  2. Step 2: Match formula to options

    output = activation(weight * input + bias) correctly shows output = activation(weight * input + bias).
  3. Final Answer:

    output = activation(weight * input + bias) -> Option D
  4. Quick Check:

    Neuron output = weighted sum + bias, then activation [OK]
Hint: Neuron output = activation(weight x input + bias) [OK]
Common Mistakes:
  • Mixing order of operations
  • Forgetting to apply activation function
  • Using addition instead of multiplication for weights
3. Given a single neuron with weight = 0.5, bias = 1, input = 4, and activation function f(x) = x (identity), what is the output after forward propagation?
medium
A. 3.5
B. 3.0
C. 4.0
D. 2.0

Solution

  1. Step 1: Calculate weighted sum

    Weighted sum = weight * input + bias = 0.5 * 4 + 1 = 2 + 1 = 3.
  2. Step 2: Apply activation function

    Activation is identity, so output = 3.
  3. Final Answer:

    3.0 -> Option B
  4. Quick Check:

    Output = 0.5x4 + 1 = 3.0 [OK]
Hint: Multiply weight and input, add bias, then activate [OK]
Common Mistakes:
  • Adding weight and input instead of multiplying
  • Forgetting bias
  • Misapplying activation function
4. Consider this Python code for forward propagation of a single neuron:
def forward(input, weight, bias):
    return input * weight + bias

output = forward(3, 2, 1)
print(output)
What is the error in this code if the activation function is missing?
medium
A. The code misses applying the activation function, so output is not transformed
B. The multiplication operator is wrong, should be '+' instead of '*'
C. The bias should be multiplied, not added
D. The function should return input + weight + bias instead

Solution

  1. Step 1: Analyze the function output

    The function returns weighted sum without applying any activation function.
  2. Step 2: Understand activation role

    Activation function adds non-linearity; missing it means output is raw sum, which is incomplete forward propagation.
  3. Final Answer:

    The code misses applying the activation function, so output is not transformed -> Option A
  4. Quick Check:

    Activation missing = incomplete forward propagation [OK]
Hint: Always apply activation after weighted sum [OK]
Common Mistakes:
  • Thinking bias should be multiplied
  • Confusing operators
  • Ignoring activation importance
5. You have a 2-layer neural network where the first layer outputs [2, 3] and the second layer has weights [[1, -1], [0, 2]] and biases [0, 1]. Using ReLU activation f(x) = max(0, x), what is the output of the second layer after forward propagation?
hard
A. [3, 4]
B. [2, 5]
C. [0, 7]
D. [1, 6]

Solution

  1. Step 1: Calculate weighted sums for second layer

    Multiply first layer output by weights and add biases: For first neuron: (2*1) + (3*0) + 0 = 2 + 0 + 0 = 2 For second neuron: (2*(-1)) + (3*2) + 1 = -2 + 6 + 1 = 5
  2. Step 2: Apply ReLU activation

    ReLU outputs max(0, x): First neuron: max(0, 2) = 2 Second neuron: max(0, 5) = 5
  3. Step 3: Re-check calculations for correctness

    Re-examining weights and biases: Weights matrix: [[1, -1], [0, 2]] means first output neuron weights: [1, -1] Second output neuron weights: [0, 2] Input vector: [2, 3] Calculations: Neuron 1: 2*1 + 3*(-1) + 0 = 2 - 3 + 0 = -1 Neuron 2: 2*0 + 3*2 + 1 = 0 + 6 + 1 = 7 Apply ReLU: Neuron 1: max(0, -1) = 0 Neuron 2: max(0, 7) = 7
  4. Final Answer:

    [0, 7] -> Option C
  5. Quick Check:

    Weighted sum + bias, then ReLU = [0, 7] [OK]
Hint: Multiply inputs by weights, add bias, apply ReLU [OK]
Common Mistakes:
  • Mixing weight matrix rows and columns
  • Forgetting to add bias
  • Applying activation before weighted sum
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard