Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Neural Network Forward Pass in NumPy

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Neural Network Forward Pass in NumPy. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Implement a simple neural network forward pass in NumPy.

Use fully connected layers, apply ReLU after every hidden layer, and apply numerically stable softmax to the final logits. The function receives X as a batch matrix, weights as matrices shaped (input_dim, output_dim), and biases as vectors. Return the output probabilities as a nested Python list with one row per input example.

Example: X = [[0, 0]], one zero-weight layer produces [[0.5, 0.5]]. A network with negative hidden activations must apply ReLU before the next layer.

Constraints

  • 1 <= number of input examples <= 1000
  • 1 <= number of layers <= 10
  • Each weight matrix has shape (previous_layer_width, current_layer_width)
  • Each bias vector has length equal to its layer's output width
  • The input and every layer contain at least one feature
  • All values are finite real numbers

Function Signature

def neural_network_forward(X, weights, biases):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output