Forward pass, loss, backward e step
Le quattro operazioni di una singola iterazione di addestramento
Forward pass, loss, backward e step è una lezione Deep Learning Academy gratuita su CoddyKit. Questa è la lezione 1 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.
Four Moves, One Beat
Every training iteration is just four moves repeated: forward, loss, backward, step. Learn this rhythm and the whole training loop stops feeling mysterious. 🥁
Move One: Forward
The forward pass sends your input through the model so it produces a prediction. You just call the model on a batch of data and read the output.
pred = model(x)Logits, Not Answers Yet
The forward output is usually raw scores called logits, not clean labels. The loss function knows how to read these scores directly, so you leave them as is.
Move Two: Loss
Next you measure how wrong the prediction was. The loss compares your output to the true labels and boils the mistake down to one number.
loss = loss_fn(pred, y)Lower Loss, Better Model
A big loss means a poor prediction and a small one means a good prediction. Training has a single mission: drive this number steadily downward.
Move Three: Backward
Now you ask which way to nudge each weight. The backward pass uses autograd to compute every gradient and fill each parameter's .grad for you.
loss.backward()Gradients Are Directions
Each gradient tells you how the loss would change if you tweaked that one weight. They are the map the optimizer follows toward a better model.
Move Four: Step
Finally the optimizer applies those gradients, nudging every weight a little. This step is the moment the model actually learns from its mistake.
optimizer.step()Clear the Grads
Gradients pile up by default, so before the next backward you call zero_grad. Skip it and old gradients corrupt your next update.
optimizer.zero_grad()The Whole Move
Put the four moves together and you get one clean iteration. You will type this exact pattern in nearly every PyTorch project you build.
optimizer.zero_grad()
pred = model(x)
loss = loss_fn(pred, y)
loss.backward()
optimizer.step()Then Do It Again
Run these moves on batch after batch and the loss falls a little each time. Thousands of tiny updates are what turn random weights into real skill.
Quick Check
Which call actually computes the gradients for every weight?
Recap
One iteration is four moves: forward for a prediction, loss to measure error, backward for gradients, and step to update weights. Repeat to learn. 🎉
Domande Frequenti
La lezione «Forward pass, loss, backward e step» è gratuita?
Sì — il testo completo di «Forward pass, loss, backward e step» è 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 «Forward pass, loss, backward e step»?
Le quattro operazioni di una singola iterazione di addestramento 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 1 di 4.
Quanto tempo richiede la lezione «Forward pass, loss, backward e step»?
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
- Forward pass, loss, backward e step
- Scriva un ciclo di addestramento minimo
- Tenga traccia dell'accuratezza durante l'addestramento
- Modalità train ed eval