nn-zero-to-hero README

The project's README from github.com/karpathy/nn-zero-to-hero. As one markdown file: README.md.

Neural Networks: Zero to Hero

A course on neural networks that starts all the way at the basics. The course is a series of YouTube videos where we code and train neural networks together. The Jupyter notebooks we build in the videos are then captured here inside the lectures directory. Every lecture also has a set of exercises included in the video description. (This may grow into something more respectable).


Lecture 1: The spelled-out intro to neural networks and backpropagation: building micrograd

Backpropagation and training of neural networks. Assumes basic knowledge of Python and a vague recollection of calculus from high school.


Lecture 2: The spelled-out intro to language modeling: building makemore

We implement a bigram character-level language model, which we will further complexify in followup videos into a modern Transformer language model, like GPT. In this video, the focus is on (1) introducing torch.Tensor and its subtleties and use in efficiently evaluating neural networks and (2) the overall framework of language modeling that includes model training, sampling, and the evaluation of a loss (e.g. the negative log likelihood for classification).


Lecture 3: Building makemore Part 2: MLP

We implement a multilayer perceptron (MLP) character-level language model. In this video we also introduce many basics of machine learning (e.g. model training, learning rate tuning, hyperparameters, evaluation, train/dev/test splits, under/overfitting, etc.).


Lecture 4: Building makemore Part 3: Activations & Gradients, BatchNorm

We dive into some of the internals of MLPs with multiple layers and scrutinize the statistics of the forward pass activations, backward pass gradients, and some of the pitfalls when they are improperly scaled. We also look at the typical diagnostic tools and visualizations you'd want to use to understand the health of your deep network. We learn why training deep neural nets can be fragile and introduce the first modern innovation that made doing so much easier: Batch Normalization. Residual connections and the Adam optimizer remain notable todos for later video.


Lecture 5: Building makemore Part 4: Becoming a Backprop Ninja

We take the 2-layer MLP (with BatchNorm) from the previous video and backpropagate through it manually without using PyTorch autograd's loss.backward(). That is, we backprop through the cross entropy loss, 2nd linear layer, tanh, batchnorm, 1st linear layer, and the embedding table. Along the way, we get an intuitive understanding about how gradients flow backwards through the compute graph and on the level of efficient Tensors, not just individual scalars like in micrograd. This helps build competence and intuition around how neural nets are optimized and sets you up to more confidently innovate on and debug modern neural networks.

I recommend you work through the exercise yourself but work with it in tandem and whenever you are stuck unpause the video and see me give away the answer. This video is not super intended to be simply watched. The exercise is here as a Google Colab. Good luck :)


Lecture 6: Building makemore Part 5: Building WaveNet

We take the 2-layer MLP from previous video and make it deeper with a tree-like structure, arriving at a convolutional neural network architecture similar to the WaveNet (2016) from DeepMind. In the WaveNet paper, the same hierarchical architecture is implemented more efficiently using causal dilated convolutions (not yet covered). Along the way we get a better sense of torch.nn and what it is and how it works under the hood, and what a typical deep learning development process looks like (a lot of reading of documentation, keeping track of multidimensional tensor shapes, moving between jupyter notebooks and repository code, ...).


Lecture 7: Let's build GPT: from scratch, in code, spelled out.

We build a Generatively Pretrained Transformer (GPT), following the paper "Attention is All You Need" and OpenAI's GPT-2 / GPT-3. We talk about connections to ChatGPT, which has taken the world by storm. We watch GitHub Copilot, itself a GPT, help us write a GPT (meta :D!) . I recommend people watch the earlier makemore videos to get comfortable with the autoregressive language modeling framework and basics of tensors and PyTorch nn, which we take for granted in this video.


Lecture 8: Let's build the GPT Tokenizer

The Tokenizer is a necessary and pervasive component of Large Language Models (LLMs), where it translates between strings and tokens (text chunks). Tokenizers are a completely separate stage of the LLM pipeline: they have their own training sets, training algorithms (Byte Pair Encoding), and after training implement two fundamental functions: encode() from strings to tokens, and decode() back from tokens to strings. In this lecture we build from scratch the Tokenizer used in the GPT series from OpenAI. In the process, we will see that a lot of weird behaviors and problems of LLMs actually trace back to tokenization. We'll go through a number of these issues, discuss why tokenization is at fault, and why someone out there ideally finds a way to delete this stage entirely.


Ongoing...

License

MIT

nn-zero-to-hero (karpathy/nn-zero-to-hero)

Searching Database…

这是什么?这是Andrej Karpathy开设的一门课程,从最基础的知识讲起,教授神经网络。课程以一系列YouTube讲座为主,配有Jupyter笔记本,视频中会现场编写代码。
这是编程库还是视频课程?这主要是一门视频课程。仓库里只是存放了每节课中构建的Jupyter笔记本,放在'lectures'目录下,另外还有视频简介中的练习题。
我该怎么开始学这些课程?从第1讲开始(构建用于理解反向传播基础的'micrograd'),观看对应的YouTube视频,并跟着lectures文件夹中的Jupyter笔记本一起操作。
开始之前我需要先具备什么基础吗?第1讲只要求具备基本的Python知识,以及对高中微积分有些模糊的印象。后面的课程会基于PyTorch(torch.Tensor、torch.nn)展开,这些内容会逐步引入。
这门课程已经完结了吗?还没有。课程仍在制作中,后续还会增加更多讲座(标注为'Ongoing...')。另外,残差连接和Adam优化器等一些主题已明确列为之后的待办事项。
这门课程适合谁?适合想从基本原理理解神经网络以及GPT等大语言模型,而不只是调用高级库的有志深度学习从业者。
这门课程是怎么安排的?课程循序渐进:先用micrograd讲解反向传播基础,然后用'makemore'分四个部分逐步搭建出MLP和WaveNet风格的字符级语言模型,接着从零构建GPT,最后构建OpenAI模型所使用的GPT分词器。
makemore是什么?这是一个字符级语言模型项目,贯穿多节课程。它从简单的bigram模型逐步演进到MLP,再到WaveNet风格的卷积架构,用于生成新的文本序列。
这门课程会讲解如何从零构建GPT本身吗?会的。第7讲参照《Attention is All You Need》论文以及OpenAI的GPT-2/GPT-3,从零构建生成式预训练Transformer(GPT);第8讲则使用字节对编码(Byte Pair Encoding)构建GPT分词器。
有练习题可以做吗?有的。每节课的视频简介中都附有一组练习题,第5讲还专门提供了一个Google Colab练习笔记本。
Creator
karpathy
Size
<0.1 MB
Stars
24.9K
Updated
CommitFeb 20
Age
4y
Commits · 90 Days