AI from Scratch in C

From Perceptrons to Large Language Models

Nearly every book that teaches machine learning teaches it in Python, and nearly every one of them reaches for a framework within the first fifty pages. The cost of that is that the machinery disappears, and you end up learning which function to call and in what order while the part where the thing actually learns stays behind an abstraction you never open. This book takes the other route, deriving every gradient on the page and then writing it out as arithmetic you can read, so that there is nowhere for the mechanism to hide.

C turned out to be the right language for that, because C hands you arrays of floats and loops over them and very little besides, which keeps the distance between the mathematics and the code short and stops anything from happening on your behalf that you did not ask for. It also runs on whatever you already own, whether that is a laptop, a Raspberry Pi, a low power RISC-V board or a microcontroller with a few hundred kilobytes of memory, and nothing in the book needs a GPU or takes longer than a few seconds to finish.

The chapters below are free to read.

Contents