0Pricing
Deep Learning Academy · Lesson

Stacking Linear Layers

From input through hidden to output.

Stacking Linear Layers is a free Deep Learning Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Deep Learning Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

One Layer, One Transform

A single nn.Linear layer maps inputs to outputs with a weighted sum plus a bias. It reshapes data from one size to another.

layer = nn.Linear(in_features=4, out_features=8)

Input to Hidden

Your first layer takes the raw input features and projects them into a hidden space, often a larger or smaller width.

self.fc1 = nn.Linear(4, 16)   # 4 inputs -> 16 hidden

Hidden to Output

A later layer maps the hidden features down to your final output size, like the number of classes you want to predict.

self.fc2 = nn.Linear(16, 3)   # 16 hidden -> 3 classes

Chaining Sizes

Each layer's out_features must equal the next layer's in_features. These matching dimensions form a clean pipeline.

Add a Nonlinearity Between

Stacking bare linear layers stays linear, so place an activation like ReLU between them to unlock real depth.

x = F.relu(self.fc1(x))
x = self.fc2(x)

Width Versus Depth

More neurons per layer means more width; more layers means more depth. Both add capacity in different ways.

The Hidden Dimension Choice

Picking the hidden size is a design call. Bigger learns more patterns but costs memory and risks overfitting.

Data Flows Top to Bottom

In forward, the input passes through layer one, then the activation, then layer two. Each step transforms the tensor in turn.

def forward(self, x):
    x = F.relu(self.fc1(x))
    return self.fc2(x)

A Two-Layer MLP

Input, hidden, output with a nonlinearity is the classic multilayer perceptron. It is the workhorse of feedforward nets.

Parameters Grow With Layers

Every linear layer adds its own weights and bias. Stacking more layers steadily grows the model's parameter count.

Start Small, Then Grow

Begin with one hidden layer and expand only if needed. A lean stack trains fast and is easy to debug. 🌱

Quick Check

Recall what must sit between two linear layers to make stacking worthwhile.

Recap

Stack nn.Linear layers so each output size feeds the next input size, with an activation between them. That builds a real MLP. 🎯

Frequently asked questions

Is the “Stacking Linear Layers” lesson free?

Yes — the full text of “Stacking Linear Layers” is free to read here on the web, and the Deep Learning Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Deep Learning Academy course, upgrade to CoddyKit PRO.

What will I learn in “Stacking Linear Layers”?

From input through hidden to output. You practise Deep Learning Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Deep Learning Academy?

No prior experience is required. Deep Learning Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Stacking Linear Layers” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Deep Learning Academy lesson?

Yes. Every Deep Learning Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Subclass nn.Module: __init__ and forward
  2. Stacking Linear Layers
  3. nn.Sequential for Quick Models
  4. Inspect Parameters and Layer Shapes
← Back to Deep Learning Academy