L14 | English F3 Student Learning Log

Persona: I'm a Form 3 (Grade 9) student and I only read English. I know basic Python (variables, for loops, lists) and school algebra up to quadratics. I learn from the official pages, the videos with captions, and the book. Kaggle notebook steps are written as a practice log that follows the official notebooks.

What I understood (in my own words)

  • As code grows, repeated parts should become classes and functions.
  • nn.Module remembers every trainable number in the model for me.
  • The optimizer wraps 'update parameters' and 'clear gradients' into one line each.
  • DataLoader cuts the data into batches and shuffles it every epoch.

Where I got stuck, and how I got unstuck

Where I got stuckHow I solved it
What is **kwargs?I wrote a tiny function that prints kwargs and saw it collects extra named arguments into a dictionary.
Why shuffle the data?If the data is sorted by class, the model sees only cats, then only dogs, and learns a lopsided pattern.

My answers to the exercises

Q1. How do Dataset and DataLoader divide the work?

Dataset handles single items: how many there are and what the i-th input and label are. DataLoader handles delivery: grouping into batches, shuffling each epoch, and feeding batches to the model.

Q2. Why call zero_grad() after every parameter update?

PyTorch adds new gradients onto the old ones by default. Without zeroing, gradients pile up and updates go wrong.

Q3. What do you gain by using nn.Module instead of managing parameters by hand?

nn.Module collects every sub-layer's parameters automatically, so parameters() returns them all without listing each one. It also makes moving to GPU, saving and loading easy, so code is shorter and nothing gets missed.

My Zettelkasten card

Card|Good code lets the next person understand it at a glance

This lesson had no new maths. It took last lesson's long code and tidied it into Module, Optimizer, Dataset and DataLoader. Afterwards the training loop was just a few lines, each saying one clear thing.

In a group project I was the one merging everyone's code. Everyone had put everything in one giant file with variables named a, b and temp, and changing one thing broke three others. We split it into three functions (load data, calculate, display results), and adding features became much easier. I also think splitting too finely means jumping across many files to understand anything, so the right level of layering matters.

My next step: rewrite my Titanic code from L05 as three parts: a Dataset, a model and a training loop.

🔗 Related notes to grow next: → Coding: 'One function, one job' → Teamwork: 'Clean structure is a gift to teammates' → Learning: 'Tidying code is understanding it a second time'


Back to lesson note:L14_反向傳播重構_202611041526

Built with LogoFlowershow