Build with nn.Sequential
Problem Statement
Build a neural network using the nn.Sequential container.
Background
nn.Sequential is a convenient container for building simple feed-forward networks. Modules are added in order, and each module's output is automatically passed as input to the next.
Your Task
Write a function build_sequential_net(input_size, hidden_size, output_size) that builds a two-layer network with a ReLU activation between them and returns a dictionary describing it.
Output Format
Return a dictionary with keys: "num_layers" (int), "output_shape" (list — shape for a single sample), "has_relu" (boolean).
Example
input_size=784, hidden_size=128, output_size=10
{'num_layers': 3, 'output_shape': [1, 10], 'has_relu': True}- Inputs:
input_sizeis the length of one flattened sample,hidden_sizeis the width of the middle representation, andoutput_sizeis the number of scores produced. - Stage 1 (affine): a single sample is a row . Multiplying by a weight matrix and adding a bias gives , a row ( learnable numbers).
- Stage 2 (activation): each entry becomes . Negatives turn into , the shape stays , and nothing here is learned, yet it still counts as a stage.
- Stage 3 (affine): with of size , so is ( learnable numbers).
- Output: three stages gives
'num_layers': 3; the final row gives'output_shape': [1, 10](the leading is the single sample); the rectifier stage is present, so'has_relu': True. - Notice that
hidden_sizenever shows up in the result: still yields 3 stages and shape . Only the last dimension tracksoutput_size.
Constraints
- Use nn.Sequential
- Include nn.Linear and nn.ReLU
- Network: Linear → ReLU → Linear