islewison Hacker News • Recommends
On “Markov Chains are the Original Language Models”
1.7M subscribers • 6 videos on Hallway
Intermediate. Assumes working knowledge.
1.3M views4 years ago2 recommendations
AI and machine learningTransformers and LLMsNeural networks and deep learningPython
Andrej Karpathy builds a character-level bigram language model from scratch using PyTorch, explaining tensors, training, and loss evaluation.
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). Links: - makemore on github: github.com/karpathy/makemore - jupyter notebook I built in this video: github.com/karpathy/nn-zero-to-hero/blob/master/lectures/mak… - my website: karpathy.ai - my twitter: twitter.com/karpathy - (new) Neural Networks: Zero to Hero series Discord channel: discord.gg/3zy8kqD9Cp , for people who'd like to chat more and go beyond youtube comments Useful links for practice: - Python + Numpy tutorial from CS231n cs231n.github.io/python-numpy-tutorial/ . We use torch.tensor instead of numpy.array in this video. Their design (e.g. broadcasting, data types, etc.) is so similar that practicing one is basically practicing the other, just be careful with some of the APIs - how various functions are named, what arguments they take, etc. - these details can vary. - PyTorch tutorial on Tensor pytorch.org/tutorials/beginner/basics/tensorqs_tutorial.html - Another PyTorch intro to Tensor pytorch.org/tutorials/beginner/nlp/pytorch_tutorial.html Exercises: E01: train a trigram language model, i.e. take two characters as an input to predict the 3rd one. Feel free to use either counting or a neural net. Evaluate the loss; Did it improve over a bigram model? E02: split up the dataset randomly into 80% train set, 10% dev set, 10% test set. Train the bigram and trigram models only on the training set. Evaluate them on dev and test splits. What can you see? E03: use the dev set to tune the strength of smoothing (or regularization) for the trigram model - i.e. try many possibilities and see which one works best based on the dev set loss. What patterns can you see in the train and dev set loss as you tune this strength? Take the best setting of the smoothing and evaluate on the test set once and at the end. How good of a loss do you achieve? E04: we saw that our 1-hot vectors merely select a row of W, so producing these vectors explicitly feels wasteful. Can you delete our use of F.one_hot in favor of simply indexing into rows of W? E05: look up and use F.cross_entropy instead. You should achieve the same result. Can you think of why we'd prefer to use F.cross_entropy instead? E06: meta-exercise! Think of a fun/interesting exercise and complete it. Chapters: intro reading and exploring the dataset exploring the bigrams in the dataset counting bigrams in a python dictionary counting bigrams in a 2D torch tensor ("training the model") visuaWhat people say. Engineers point newcomers here for an invaluable, step-by-step introduction to how language models work under the hood.
islewison Hacker News • Recommends
On “Markov Chains are the Original Language Models”
georgehillon Hacker News • Recommends
On “Show HN: Next-token prediction in JavaScript”
chrsigon Hacker News • Mentions
On “GPT in 500 Lines of SQL”
caprockon Hacker News • Mentions
On “The n-gram Language Model”