Sovrapporre layer lineari
Dall'input, passando per i layer nascosti, fino all'output
Sovrapporre layer lineari è una lezione Deep Learning Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Deep Learning Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Deep Learning Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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 hiddenHidden 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 classesChaining 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. 🎯
Domande Frequenti
La lezione «Sovrapporre layer lineari» è gratuita?
Sì — il testo completo di «Sovrapporre layer lineari» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Deep Learning Academy, passa a CoddyKit PRO. Il corso Deep Learning Academy include 4 lezioni in totale.
Cosa imparerò in «Sovrapporre layer lineari»?
Dall'input, passando per i layer nascosti, fino all'output Eserciti Deep Learning Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Deep Learning Academy?
Non è richiesta alcuna esperienza precedente. Deep Learning Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.
Quanto tempo richiede la lezione «Sovrapporre layer lineari»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Deep Learning Academy?
Sì. Ogni lezione Deep Learning Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Estenda nn.Module: __init__ e forward
- Sovrapporre layer lineari
- nn.Sequential per modelli rapidi
- Ispezionare parametri e forme dei layer