Large Language Models (LLMs) Explained: How AI Actually Works
Most people believe artificial intelligence like ChatGPT "thinks" about a problem and then writes an answer. It doesn't. It mathematically predicts the next most likely piece of a word (a token) based on everything you've typed and everything it has ever read.
Understanding how LLMs work strips away the magical thinking surrounding them. They are not conscious entities reading a library of facts; they are unfathomably massive calculators predicting linguistic patterns.
The Transformer Architecture
Before 2017, AI processed language sequentially—reading word by word, from left to right. This meant the AI quickly "forgot" the beginning of a paragraph by the time it reached the end.
Then Google researchers released a paper called "Attention Is All You Need" which introduced the Transformer architecture.
The Attention Mechanism
Transformers use "Self-Attention" to look at an entire wall of text simultaneously, mathematically scoring how every single word relates to every other word in context. If you type "The bank of the river," the transformer knows "bank" relates to water, not money, because it cross-referenced it with the word "river" simultaneously.
Tokenization and Next-Token Prediction
LLMs do not read words or letters; they read "Tokens." A token is roughly equivalent to a 4-letter chunk of a word.
- Training During training, the model reads billions of pages from the internet. It takes a sentence, hides the last word, guesses it, and adjusts billions of internal "weights" (parameters) based on whether it was right or wrong.
- Inference (When you use it) When you submit a prompt, the model converts your text to tokens, runs them through its massive neural network, and spits out a probability distribution for what the very next token should be. It picks the most likely one, adds it to your prompt, and starts the entire calculation over again for the next token.