Spent the (long) weekend learning about LLMs and developments in deep learning; sharing the raw notes below.
Overview of LLMs and GPT
A beginner-friendly guide to generative language models
A Generative Language Models, or “LM,” for short, is a piece of software takes as input a text prompt and then tries to predict what text should come next. If this sounds like autocomplete, you’re right: most autocomplete features are built with language models.
You can think of language models as sophisticated pattern-matching machines. Given a very large training dataset (say, millions of public web documents), LMs learn patterns in language, from low-level grammatical rules to common expressions to high-level concepts, like how to produce fluid-sounding conversation.
In this way, generative language models are like the ultimate improviser: given any text prompt, they can produce dozens of plausible responses on the fly that aren’t prewritten. This versatility means that a single model can power a near-infinite number of language applications
However, it’s exactly this versatility that makes it tricky to build applications with LMs. A model that can say anything can say anything. That introduces lots of challenges, like how to build an app with a consistent user experience that gives sensible, interesting responses and that handles sensitive topics.
The first thing to explain is that what ChatGPT is always fundamentally trying to do is to produce a “reasonable continuation” of whatever text it’s got so far, where by “reasonable” we mean “what one might expect someone to write after seeing what people have written on billions of webpages, etc.”
ChatGPT effectively does something like this, except that (as I’ll explain) it doesn’t look at literal text; it looks for things that in a certain sense “match in meaning”. But the end result is that it produces a ranked list of words that might follow, together with “probabilities”
At each step it gets a list of words with probabilities. But which one should it actually pick to add to the essay (or whatever) that it’s writing? One might think it should be the “highest-ranked” word (i.e. the one to which the highest “probability” was assigned). But this is where a bit of voodoo begins to creep in. Because for some reason—that maybe one day we’ll have a scientific-style understanding of—if we always pick the highest-ranked word, we’ll typically get a very “flat” essay, that never seems to “show any creativity” (and even sometimes repeats word for word). But if sometimes (at random) we pick lower-ranked words, we get a “more interesting” essay.
There’s a particular so-called “temperature” parameter that determines how often lower-ranked words will be used, and for essay generation, it turns out that a “temperature” of 0.8 seems best. (It’s worth emphasizing that there’s no “theory” being used here; it’s just a matter of what’s been found to work in practice.
ChatGPT is precisely a so-called “large language model” (LLM) that’s been built to do a good job of estimating those probabilities.
Any model you use has some particular underlying structure—then a certain set of “knobs you can turn” (i.e. parameters you can set) to fit your data. And in the case of ChatGPT, lots of such “knobs” are used—actually, 175 billion of them.
Eight Things to Know about Large Language Models
The widespread public deployment of large language models (LLMs) in recent months has prompted a wave of new attention and engagement from advocates, policymakers, and scholars from many fields. This attention is a timely response to the many urgent questions that this technology raises, but it can sometimes miss important considerations. This paper surveys the evidence for eight potentially surprising such points:
LLMs predictably get more capable with increasing investment, even without targeted innovation.
Many important LLM behaviors emerge unpredictably as a byproduct of increasing investment.
LLMs often appear to learn and use representations of the outside world.
There are no reliable techniques for steering the behavior of LLMs.
Experts are not yet able to interpret the inner workings of LLMs.
Human performance on a task isn't an upper bound on LLM performance.
LLMs need not express the values of their creators nor the values encoded in web text.
Brief interactions with LLMs are often misleading.
Overview of Neural Networks and Machine Learning
Neural Network, Machine Learning and Weights
The most popular—and successful—current approach [to Train models] uses neural nets. Invented—in a form remarkably close to their use today— in the 1940s, neural nets can be thought of as simple idealizations of how brains seem to work
In human brains, there are about 100 billion neurons (nerve cells), each capable of producing an electrical pulse up to perhaps a thousand times a second. The neurons are connected in a complicated net, with each neuron having tree-like branches allowing it to pass electrical signals to perhaps thousands of other neurons. And in a rough approximation, whether any given neuron produces an electrical pulse at a given moment depends on what pulses it’s received from other neurons—with different connections contributing with different “weights”.
What makes neural nets so useful (presumably also in brains) is that not only can they in principle do all sorts of tasks, but they can be incrementally “trained from examples” to do those tasks.
When we make a neural net to distinguish cats from dogs we don’t effectively have to write a program that (say) explicitly finds whiskers; instead we just show lots of examples of what’s a cat and what’s a dog, and then have the network “machine learn” from these how to distinguish them.
Essentially what we’re always trying to do is to find weights that make the neural net successfully reproduce the examples we’ve given.
At each stage in this “training” the weights in the network are progressively adjusted—and we see that eventually we get a network that successfully reproduces the function we want. So how do we adjust the weights? The basic idea is at each stage to see “how far away we are” from getting the function we want—and then to update the weights in such a way as to get closer.
To find out “how far away we are” we compute what’s usually called a “loss function” (or sometimes “cost function”). Here we’re using a simple (L2) loss function that’s just the sum of the squares of the differences between the values we get, and the true values. And what we see is that as our training process progresses, the loss function progressively decreases (following a certain “learning curve” that’s different for different tasks)—until we reach a point where the network (at least to a good approximation) successfully reproduces the function we wan
The last essential piece to explain is how the weights are adjusted to reduce the loss function. As we’ve said, the loss function gives us a “distance” between the values we’ve got, and the true values. But the “values we’ve got” are determined at each stage by the current version of neural net—and by the weights in it. But now imagine that the weights are variables—say _wi_. We want to find out how to adjust the values of these variables to minimize the loss that depends on them.
In the end the whole process of training can be characterized by seeing how the loss progressively decreases
One can think of an embedding as a way to try to represent the “essence” of something by an array of numbers—with the property that “nearby things” are represented by nearby numbers.
(vs convolutional neural networks)
ChatGPT it’s a giant neural net—currently a version of the so-called GPT-3 network with 175 billion weights. In many ways this is a neural net very much like the other ones we’ve discussed. But it’s a neural net that’s particularly set up for dealing with language. And its most notable feature is a piece of neural net architecture called a “transformer”.
In the first neural nets before transformers, every neuron at any given layer was basically connected (at least with some weight) to every neuron on the layer before. But this kind of fully connected network is (presumably) overkill if one’s working with data that has particular, known structure. And thus, for example, in the early stages of dealing with images, it’s typical to use so-called[convolutional neural nets (“convnets”) in which neurons are effectively laid out on a grid analogous to the pixels in the image—and connected only to neurons nearby on the grid.
The idea of transformers is to do something at least somewhat similar for sequences of tokens that make up a piece of text. But instead of just defining a fixed region in the sequence over which there can be connections, transformers instead introduce the notion of “attention”—and the idea of “paying attention” more to some parts of the sequence than others.
Attentional Neural Network Models
Long range language models basically produce probabilistic distribution of various words (articles)
Deeping learning in the past done using Recurrent neural network (RNN) which is super useful when dealing with sequential data; it was missing long context that goes way beyond the current problem/scenario.
There was other way to build models called Convolution neural networks (CNN); they are positional and they are useful when data in random (no sequence) -- creates patterns / filters
In between, there were LSTMs that solved the memory problem but it was not enough.
Then researchers introduced something called transformers (which gives self attention to model), which will refer to things that are similar and is much more natural that position.
Attention refers to content; reference similar things in the past, when you retreive similar thing you can produce more context. (And basically had no memory limits?)
Convolution neural networks will still allow you to something similar but you have to know the exact position
Attention fundamentals + intuition of attention
Transformers put RNNs on steroids and solve the limitations of RNNs; continous stream, parallelisation, long memory
Self attention: Attending to the most important parts of an input. Identify important parts on input and extract the values/features from the subject.
Attention weighting: Where to attent do (Using cosine similarities)