#170From scratch — derive the parameter shapesEasyNeural Networks
From scratch — derive the parameter shapes
Background
Before you can initialise a network you must size its tensors. For the from-scratch binary net (batch rows = examples), the conventions are:
| Param | Shape | Role |
|---|---|---|
W1 | (input_size, hidden_size) | input → hidden |
b1 | (1, hidden_size) | hidden bias (broadcast over the batch) |
W2 | (hidden_size, 1) | hidden → single output |
b2 | (1, 1) | output bias |
The 1s are the batch-broadcast dimension; the single output column is because o = 1 for binary classification.
Problem statement
Implement init_shapes(input_size, hidden_size) returning the shapes of W1, b1, W2, b2.
Input
input_size—int, number of input features.hidden_size—int, number of hidden units.
Output
Returns a dict with keys "W1", "b1", "W2", "b2", each mapping to a shape tuple.
Examples
Example 1 — the XOR net (2 inputs, 4 hidden)
Input: input_size = 2, hidden_size = 4
Output: {"W1": (2, 4), "b1": (1, 4), "W2": (4, 1), "b2": (1, 1)}
Constraints
- Use the exact conventions in the table.
- Shapes are Python tuples.
Notes
- Getting these shapes right is the silent prerequisite for every matmul in the forward and backward passes — a transposed shape is the most common from-scratch bug.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •example: XOR net two inputs four hidden
- •reference: ten inputs thirty-two hidden
- •sample: single hidden unit