nn.Sequential for Quick Models
Chain layers without a custom class.
A Shortcut for Simple Nets
When data flows straight through layers in order, nn.Sequential lets you skip writing a full custom class.
List Your Layers in Order
You pass the layers as arguments, and Sequential runs them one after another. The order you list them is the order they execute.
model = nn.Sequential(
nn.Linear(4, 16),
nn.ReLU(),
nn.Linear(16, 3))All lessons in this course
- Subclass nn.Module: __init__ and forward
- Stacking Linear Layers
- nn.Sequential for Quick Models
- Inspect Parameters and Layer Shapes