← All writing

Large Language Models: The Magic Behind the Next Word

Large Language Models (LLMs) like ChatGPT, Gemini, Claude and Llama seem like they're thinking, but at their core they are prediction engines. They are built on the Transformer architecture and learn mathematical relationships between billions of words during "training", processing text in units called "tokens". Instead of "knowing" facts, they calculate the most probable next word in a sequence.

Imagine this. You pull out your phone to text a friend: "I'm running a little..." Before you can type the next letter, your phone suggests the word "late".

How did it know? It didn't read your mind and it doesn't understand the concept of time. It calculated the next word based on millions of past text messages: "late" is the most statistically probable word to follow that exact phrase.

Now scale this up. Feed the algorithm every book, article and website ever written. Give it thousands of supercomputers to map how every word relates to every other word. That is how a Large Language Model works.

The History

To understand how LLMs reached this level of fluency, it helps to look at a basic problem in earlier AI research.

Older language models read text sequentially. If they reached the end of a long paragraph, they often "forgot" what the first sentence was about; they struggled with context.

In 2017, a team of researchers introduced a new architecture called the Transformer and it changed the field. Instead of reading words one by one, the Transformer looks at an entire block of text at once. It uses a mechanism called Self-Attention to weigh the importance of every word in relation to the others, no matter how far apart they are.

How Do LLMs work?

Creating a modern LLM requires two distinct phases:

1. Pre-training (Reading the Sources) The model is fed massive, unstructured datasets: essentially a huge chunk of text from the internet. This phase works like a game of fill-in-the-blank. It hides a word, guesses what it is and adjusts its internal math based on whether the guess was right or wrong. It repeats this billions of times until it builds a detailed map of how human language is structured.

2. Fine-Tuning (Learning) A pre-trained model is "smart" but "chaotic". To make it useful, engineers apply techniques like Reinforcement Learning, in which human testers rate the model's responses, teaching it which answers are better than others.

The Hallucination Problem

Because LLMs are prediction engines, they have a critical flaw: they have no underlying model of reality. When an LLM computes an answer, it is not reasoning through logic the way a human does; it is predicting the sequence of words that usually follows a question like that one.

That prediction holds up when the training data on the topic is abundant and consistent. But when the data is sparse or contradictory, the model still predicts the next most likely word anyway and strings together plausible-sounding sentences that are false. This is a hallucination. The model isn't wrong because it "doesn't know" the answer; it has no concept of knowing at all. It only outputs what is statistically probable, whether or not that output is true.

Conclusion

Large Language Models are a major step in artificial intelligence. Built on the Transformer architecture's model of natural language structure, they can help draft legal documents, write code and analyze large datasets in seconds.

That same mechanism is also the limit: an LLM cannot distinguish a statistically likely sentence from a factually correct one. Treat its output as a well-informed draft, not a verified answer and check anything that matters against a real source.

References

  • [1] Vaswani, A., et al., "Attention Is All You Need," Advances in Neural Information Processing Systems, 2017.
  • [2] Zhao, W. X., et al., "A Survey of Large Language Models," arXiv preprint arXiv:2303.18223, 2023.
  • [3] Minaee, S., et al., "Large Language Models: A Survey," arXiv preprint arXiv:2402.06196, 2024.