All problems
MLP Forward Pass
Problem
Forward pass of a 2-layer MLP with ReLU hidden activation and linear output.
z1 = W1 @ x + b1 (shape: hidden) a1 = relu(z1) z2 = W2 @ a1 + b2 (shape: output)
Return z2 (the output layer pre-activation).
W1 is shape (hidden, input), W2 is shape (output, hidden).
Hint
Two matrix-vector products and a ReLU. Output is linear (no activation).
Test cases
case 1
in: [[1],[[0.5],[-0.5]],[0,0],[[1,1]],[0]]
expected: [0.5]
case 2
in: [[1,2],[[1,0],[0,1]],[0,0],[[1,1]],[0]]
expected: [3]
case 3
in: [[2,-1],[[1,1],[1,-1]],[0,0],[[2,0],[0,1]],[0,0]]
expected: [2,3]
Starter codePython
def mlp_forward(x, W1, b1, W2, b2):
# Your code here
pass3 test cases · run your code against them in the editor