Premium problem64. Two-Layer MLP Forward Pass

Hard Locked

Compute the forward pass of a 2-layer MLP with a ReLU hidden activation: h = relu(x @ W1.T + b1), output = h @ W2.T + b2.

Input

x =
tensor([[ 1.0000, -1.0000],
        [ 0.5000,  2.0000]])
W1 =
tensor([[1., 0.],
        [0., 1.],
        [1., 1.]])
b1 = tensor([0., 0., 0.])
W2 = tensor([[ 1.0000, -1.0000,  0.5000]])
b2 = tensor([0.1000])

Output

tensor([[ 1.1000],
        [-0.1500]])

Premium problem

This one's part of Premium. Unlock the full PyTorch track plus every other premium problem on the site.

Implement solve(...)