Neural Network Forward Pass

Hard
machine-learning Google NVIDIA DeepMind

Implement a forward pass through a simple 2-layer neural network (input -> hidden -> output) with ReLU activation on the hidden layer and sigmoid on the output.

Weights and biases are provided as lists. The network has arbitrary input size, hidden size, and single output.

Example

# 2 inputs, 2 hidden neurons, 1 output
W1 = [[0.1, 0.2], [0.3, 0.4]]  # hidden_size x input_size
b1 = [0.1, 0.1]
W2 = [[0.5, 0.6]]  # output_size x hidden_size
b2 = [0.1]
forward_pass([1.0, 2.0], W1, b1, W2, b2)
# => sigmoid(W2 @ relu(W1 @ x + b1) + b2)

Test Cases

Python Editor

Output

Click "Run" to see results...