what does it mean for a computer to understand language is it just knowing the definition and the meaning of each word well no we all know that it's deeper than that take the sentence the stolen painting was found by a tree now obviously we know that the tree didn't find the painting but that's because you understand the context here if a computer only had Sur level understanding of words it's possible that it could interpret it in a different way human language is an absurdly complicated and deep topic so it should come to as no surprise
that we have a hard time getting computers to understand it by now I'm sure you're familiar with chat GPT it's this mindboggling allpurpose chatbot that pretty much seems to know everything it sort of represents a shift in the way we interact with computer it's now possible for us to have meaningful conversations in English with our computer but how did we get here things like chat gbt are certainly not built overnight behind chat gbt is a neural network architecture called a Transformer this series is sort of a precursor to the one and three blue one Brown
in which you can actually learn the inner mechanisms behind a Transformer if you haven't already do check it out after this one it's an amazing watch but to me it's just as interesting to see what happened prior to the Transformer you know what was built up in order to reach what we have today so let's take a step back as I take you through a journey across the history of natural language [Music] processing the idea of computers being able to understand language or natural language processing commonly called NLP is with many different kinds of problems
to solve there's speech which could involve converting text to speech or converting speech to text called automatic speech recognition there's language modeling which could consist of machine translation or just translating between languages text summarization or question answering and the last category I'll call grounding which means incorporating other human senses so for example converting text to images in the first part of the series will focus on language modeling what we're building up to is the Transformer model the architecture behind the large language models you see floating around today later on we'll examine other topics like image
generation or inference algorithms but before we get to chat gbt let's examine one of the early language models engram models let's say I was trying to create some model to generate text say write me an email to me at least it's not actually that clear what we're even modeling over for example let's say I'm trying to create a model that can detect handwritten digits in this case it's fairly easy to create a metric for how good the model is we can just check how many digits it was able to classify so we make the goal
or the objective to maximize the number of correct answers but with text gener ation what even is the objective to this a lot of things were tried but eventually the best early results came with next word prediction here's how it works let's call our model P Theta and Define a number K which I'll call the context window what P Theta gives me is a probability distribution across all words given the past K words all this means is that if I feed in some previous words say the sky is and I examine some next word say
blue P Theta gives me the probability that blue appears given that the sky is has already appeared the actual hard part though is Computing that probability we call the model that computes this probability the language model and as we'll see as deceptively easy this task seems it's an extremely difficult and complicated task but first let's think about what the simplest way we can do this is let's say I roll a dice and I'm trying to compute the probability that I roll a two or three on a six-sided die the way I do this is to
see that I have six possible outcomes and I only want two of them so the probability becomes 2 over 6 theoretically to calculate the probability of blue occurring after the sky is I'd probably want to find every single occurrence of the sky is in history and compute how many times blue came after now obviously this isn't possible but what we can do is first gather a lot of text say all the Wikipedia articles then in order to compute the probability that blue comes after the sky is we look for every occurrence of the sky is
and count how many times blue occurred after it some of you could see some problems here you know what if the sky is never occurs the matching criteria is also really specific I'm gaining no information from phrases such as the sky was one solution to this is tweaking K the context window here I have three words of context which I can reduce or increase to sort of make sure that I don't look for anything too specific of a phrase phrase in this case if I reduce the number of context words I'm losing the word the
so you can see how I could lose some important words by tweaking the context window since I'm losing information this equation up here isn't really an equality it's more of an approximation I'm only really losing one word here but you can see how if I had a paragraph of context I would be losing a lot this type of model where I fix the context window size and look for all occurrences of the previous words is called an nram model where n refers to the number of words we examine at a time so for example if
I had a context window size of two I'm examining three words at a time so we have a 3gr model commonly called a trigram model engram models were the first early Renditions of language models and there were several improvements to them over the years for instance we can apply some smoothing function to make sure that the denominator is never zero in the case that the prefix never occurs also you have the trade-off of choosing the value of n too large a number and you have a hard time finding the context in your text too small
a number and you get a bad model so armed with our language model we can now find a way to generate text let's say I start with the prompt the most beautiful proof in math is now I have a distribution for all the possible next words the way we pick words is by sampling from this distribution what this means is that if the probability of a appearing next is 8 then I pick it with probability 08 I could do this by maybe choosing a random number between 0 and one and figuring out which word my
number falls into there's a whole world of algorithms to figure out how to generate text given a language model and one of the future videos will be on this but for instance I could restrict the words I sample from to just be the top 10 a level above is I could create what's called a Chain of Thought a sort of way for the model to reason through its output but we'll save that for another video okay great so let's try sampling with the trigram [Music] model and it's outputting words but it's not the best a
big part of why is since we only take in three words at a time we can't really get information from the previous sentence or paragraph you can really see this happening with the example here it's completely lost the idea that we're even talking about math we call these relations to previous sentences or paragraphs long form dependencies and this will be a common problem to fix throughout like language modeling and while people knew that engram models weren't the best no one really used them to write emails or stories researchers sort of used engram models as a
means to empirically study language today I've shown you a simple yet useful language model but there's so much to talk about engram models are nowhere close to what we have today a personal gripe I have about NLP is how arbitrary some of the decisions behind the techniques used seem like so my goal across the next few videos is to sort of ease into each decision I want to convince you that you could have thought about each of these yourself in the next video we'll cover how neural networks drastically improved our language modeling capabilities up until
2017 variants of the model will cover in the next video the recurrent neural network were used by Google will translate to translate between languages and well it works pretty well so join me on the next video and I'll tell you all about [Music] it