Syntax was never the hard part. You can write a loop, import a library, and still open someone else’s training script and feel like you are reading a language you only know from phrasebooks. That feeling is about grammar in the useful sense: the unwritten rules of how shapes line up, how notation is written, and how the parts of a program are expected to follow one another. You can learn those rules by reading and editing real work, without a single fill-in-the-blank exercise.
The grammar is shapes, notation, and idioms
Three kinds of rule keep showing up. Shapes say what a tensor is allowed to be at each step, so a batch of thirty-two grayscale images is not the same object as thirty-two flat vectors, and mixing them up produces the error messages you will see most often. Notation says how the field writes things down: a loss as a sum over examples, a gradient with a subscript, an expectation with a subscript and a distribution. Idioms say which order the pieces appear in, because almost every training script is the same five moves with different nouns.
Once you can see those three layers, a new repository stops being an intimidating wall of unfamiliar code and becomes a document with a structure you already recognise.
Read working code like a sentence
Take a script that definitely runs and read it aloud as if it were prose. Find the subject, which is the data and its shape. Find the verb, which is the model call. Find the object, which is the loss. Then find the clause that changes something, usually the optimiser step. If you can retell the script in five sentences, you have parsed it.
- Where does the batched input get its shape, and what is that shape?
- Which line produces a number that training tries to reduce?
- What is updated, and what is only read?
- Which parts are bookkeeping for logging rather than learning?
Doing this on three small scripts teaches more about the field’s grammar than rewriting a tutorial from memory, because real code contains the shortcuts, dead ends, and odd names that tutorials hide.
Change one rule at a time
Grammar becomes usable when you manipulate it. Pick a script you understand and alter exactly one thing, then read the consequence as feedback on your mental model.
- Change a shape: double the batch size and predict which error appears if the data pipeline is wrong.
- Change a sign or a scale: divide the learning rate by ten and watch the loss curve before you trust the number.
- Change an order: move the optimiser step and see what breaks, which teaches you why the order exists.
- Change a name: rename a variable to what it actually holds, and reread the file.
Each change is a grammar experiment. You are not drilling rules; you are testing them against a program that answers back.
Keep a notebook of what broke
Every error message you decode is a rule you now own. Write the message, the cause in one line, and the shape or notation mistake behind it. After a few weeks the notebook becomes a personal grammar of the subject, written in the terms you actually think in, and it will answer questions that no textbook chapter covers.
Read, parse, change, record. That loop covers the same ground as a drill sheet, except you finish it able to read unfamiliar code, which is the only test that matters.