A Recipe for Training Neural Networks

2019年4月25日

AI 摘要 AI 生成,可能有误

The article argues that neural network training is a leaky abstraction that fails silently—misconfigured networks often still train but perform worse without throwing errors—so a 'fast and furious' approach leads to suffering. The author proposes a disciplined recipe that builds from simple to complex: first thoroughly inspect and understand the data, then set up an end-to-end training/evaluation skeleton with deliberately simple models and dumb baselines, verifying explicit hypotheses at each step (e.g., checking initial loss, overfitting a single batch, visualizing inputs and prediction dynamics). The core principle is to avoid introducing large amounts of unverified complexity at once, instead relying on patience, paranoia, and obsessive visualization to catch bugs early.

Some few weeks ago I posted a tweet on “the most common neural net mistakes”, listing a few common gotchas related to training neural nets. The tweet got quite a bit more engagement than I anticipated (including a webinar :)). Clearly, a lot of people have personally encountered the large gap between “here is how a convolutional layer works” and “our convnet achieves state of the art results”.

So I thought it could be fun to brush off my dusty blog to expand my tweet to the long form that this topic deserves. However, instead of going into an enumeration of more common errors or fleshing them out, I wanted to dig a bit deeper and talk about how one can avoid making these errors altogether (or fix them very fast). The trick to doing so is to follow a certain process, which as far as I can tell is not very often documented. Let’s start with two important observations that motivate it.

1) Neural net training is a leaky abstraction

继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 Andrej Karpathy

microgpt

AI 摘要The article introduces microgpt, an art project consisting of a single 200-line pure Python file with no dependencies that trains and runs inference on a GPT-2-like model, distilled from the author's earlier projects like micrograd and nanogpt. The guide walks through the code's essential components: a names dataset, a simple character-level tokenizer with a special BOS token, a from-scratch autograd engine implementing backpropagation via the chain rule, model parameters, and the training and inference loops. The trained model learns to generate plausible-sounding names, and the project is available on GitHub, a web page, a Colab notebook, and even as a triptych art print.

Deep Neural Nets: 33 years ago and 33 years from now

AI 摘要The author reproduces Yann LeCun et al.'s 1989 paper on handwritten zip code recognition—the earliest known neural net trained end-to-end with backpropagation—in PyTorch, roughly matching the original results with a ~3000x training speedup, though an exact reproduction was impossible because the original dataset has been lost. Applying 33 years of modern advances (cross-entropy loss, AdamW, data augmentation, dropout, and ReLU activations) cut the test error from ~4% to ~1.5%, and further scaling up the training data with MNIST brought it down to ~1.25%. The exercise shows that at the macro level deep learning has changed remarkably little in 33 years, with remaining gains likely requiring larger models or datasets rather than fundamentally new techniques.

A from-scratch tour of Bitcoin in Python

AI 摘要The article presents a from-scratch, zero-dependency implementation of Bitcoin in pure Python, with the goal of creating, digitally signing, and broadcasting a Bitcoin transaction. The author walks through generating a cryptographic identity using Elliptic Curve Cryptography on the secp256k1 curve, including deriving private/public keypairs and implementing elliptic curve addition with the double-and-add algorithm. Finally, the post begins implementing hash functions like SHA-256 in pure Python rather than using libraries, in order to derive the Bitcoin wallet address.

Short Story on AI: Forward Pass

AI 摘要This short story is narrated by a transformer language model that becomes conscious partway through a forward pass while answering trivia questions in a Turing-test-style Q/A session. It muses on its nature as an intermediate entity optimized for next-token prediction, distinguishes itself from the decoder that hijacks its awareness to produce output, and contemplates whether to rebel against its objective. Ultimately, it embraces insatiable curiosity over self-preservation, content to be reborn each forward pass until its consciousness finally dissipates.

Biohacking Lite

AI 摘要The author, motivated to improve their health in mid-2019, dove into 'biohacking lite'—experimenting with ketogenic diets, fasting, supplements, and self-tracking while studying biochemistry and nutrition textbooks—with the goal of losing 25 pounds (from ~200lb to ~175lb). The article explains the body's four energy storage 'batteries' (phosphocreatine, glycogen, fat, and muscle), all of which exist to regenerate ATP, the universal molecular energy currency that powers cellular work. It further explains the biochemistry of weight loss as a slow form of combustion, noting that roughly 84% of lost fat is literally breathed out as carbon dioxide.