The spelled-out intro to language modeling: building makemore

Andrej Karpathy · Beginner ·🧠 Large Language Models ·3y ago

Key Takeaways

The video implements a bigram character-level language model using PyTorch and introduces torch.Tensor, while also covering the overall framework of language modeling, including model training, sampling, and loss evaluation.

Original Description

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: https://github.com/karpathy/makemore - jupyter notebook I built in this video: https://github.com/karpathy/nn-zero-to-hero/blob/master/lectures/makemore/makemore_part1_bigrams.ipynb - my website: https://karpathy.ai - my twitter: https://twitter.com/karpathy - (new) Neural Networks: Zero to Hero series Discord channel: https://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 https://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 https://pytorch.org/tutorials/beginner/basics/tensorqs_tutorial.html - Another PyTorch intro to Tensor https://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 smoothin
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

This video introduces the basics of language modeling by implementing a bigram character-level language model using PyTorch, covering the overall framework of language modeling, and introducing torch.Tensor. The video provides a foundation for further complexifying the model into a modern Transformer language model.

Key Takeaways
  1. Implement a bigram character-level language model using PyTorch
  2. Introduce torch.Tensor and its subtleties
  3. Cover the overall framework of language modeling
  4. Train the model using a training set
  5. Evaluate the model using a dev set and test set
  6. Tune the strength of smoothing using the dev set
💡 The video provides a foundation for understanding the basics of language modeling and how to implement a language model using PyTorch, which can be further complexified into a modern Transformer language model.

Related Reads

📰
Prompt Injection for API Teams: What It Is and How to Test for It
Learn to identify and test for prompt injection vulnerabilities in API teams to ensure model security
Dev.to · Hassann
📰
How to track new AI drops without the social media delay?
Stay updated on new AI drops without social media delay by following source-of-truth channels and setting up alerts with keywords
Reddit r/artificial
📰
The AI Crash Test: adversarial LLM testing you can audit in the Network tab
Learn to test LLMs with adversarial examples using a browser tool, ensuring model robustness and security
Dev.to · Erik Hill
📰
[Day 17] I analyzed 33,469 of my own AI conversations to audit how I actually use AI
Analyze your AI conversations to understand how you use AI and identify areas for improvement
Dev.to · PEPPERCORN
Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →