Exploring GPT2 Under the Hood: A Deep Dive into Machine Learning Model Architecture
Get ready to dive into the inner workings of GPT-2, a large language model, as we dissect its anatomy, apply a virtual MRI to understand how it thinks, and perform AI brain surgery to unlock its secrets.
- 1. The speaker will provide a crash course on how machine learning models work for those in the AI engineering field without a machine learning degree.
- 2. They will be using gpt2, an early precursor to chat GPT, as an example and will go through an Excel spreadsheet that implements all of gpt2 small entirely in pure Excel functions.
- 3. The spreadsheet has over 150 tabs and over 124 million cells, each one representing a parameter in gpt2 small.
- 4. They will cover the anatomy of gpt2, how it thinks, and how to change its thinking through AI brain surgery.
- 5. Large language models, such as gpt2, are trained to complete sentences or fill in the blank of phrases.
- 6. This is done by breaking down sentences into subword units called tokens and then mapping each token onto numbers called embeddings.
- 7. These embeddings are many numbers, not just one, as shown in the simplified example.
- 8. Instead of simple arithmetic, more complex math such as multi-headed attention and multi-layer perceptron (neural network) is used.
- 9. The result is interpreted as a probability distribution to determine the next token.
- 10. The process involves inputting text, breaking it down into tokens, turning those tokens into numbers, performing number crunching, and then reversing the process to turn the numbers back into toke
- 11. In gpt2, tokenization is done using an algorithm that recognizes subword units in some cases, but not always.
- 12. For example, "funology" might be split into "fun" and "anology" while "reinjury" might be split into "rain" and "jury."
- 13. The next step is mapping each token to an embedding, which is a vector of many numbers.
- 14. This is done for every token in the vocabulary, resulting in a large matrix of embeddings.
- 15. The multi-headed attention mechanism allows the model to focus on different parts of the input when generating each token.
- 16. Each head in the multi-headed attention can have a different weighting, allowing the model to attend to different aspects of the input.
- 17. The output of the attention mechanism is then passed through a feedforward neural network (multi-layer perceptron) to generate the final output.
- 18. In gpt2, there are also residual connections inside every layer, allowing information to flow around and skip any part of the layers.
- 19. By taking a virtual MRI of the model, we can see how it thinks and which parts of the input it focuses on at each layer.
- 20. The researchers found that only four components out of the entire network were responsible for accurately predicting the next word in a sentence over seven days.
- 21. These components included the perceptron from layer zero, attention from layer 9, one head from layer 10, and attention from layer 10.
- 22. The researchers used this information to create a circuit that could predict the next word in a sentence with high accuracy over seven days.
- 23. By using an AI technique called sparse autoencoder, we can separate the residual stream into interpretable features and deduce what each feature is.
- 24. We can then turn up or down these features to amplify or suppress certain concepts in the model.
- 25. A team of researchers led by Joseph Bloom, Neil Nanda, and others are building out sparse autoencoder features for open-source models like gpt2 small.
- 26. By injecting a vector corresponding to a feature into the residual stream, we can steer the model to generate specific outputs.
- 27. For example, by turning on the Jedi feature, the model is more likely to generate text related to Jedi.
- 28. The speaker emphasizes the importance of understanding how large language models work in order to be a better AI engineer.
- 29. Knowing the behavior and limitations of tools, keeping up with the latest research, and being able to clear up misunderstandings when communicating with non-technical stakeholders are all importan
- 30. The speaker has launched a course on Maven for those who want to learn more about machine learning models and their inner workings.
Source: AI Engineer via YouTube
❓ What do you think? What are your thoughts on the ideas shared in this video? Feel free to share your thoughts in the comments!