📘
Build with nn.Sequential
EasyPyTorch Modeling
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:
input_size=784, hidden_size=128, output_size=10
Output:
{'num_layers': 3, 'output_shape': [1, 10], 'has_relu': True}Reasoning:
3 modules: Linear, ReLU, Linear. Output is (1, 10)
Constraints:
- Use nn.Sequential
- Include nn.Linear and nn.ReLU
- Network: Linear → ReLU → Linear
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.