PIXELBANKv9.1.0
Menu

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:
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 locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Build with nn.Sequential - Easy | PixelBank