AIAI Academy

Module 1: Foundations · 3 min read

What Is a Large Language Model (LLM), and How Does ChatGPT "Think"?

The mechanism behind ChatGPT, Claude and Gemini: predicting the next word, the transformer and the attention mechanism.

ChatGPT, Claude, Gemini and Llama sound like very different products, but they all rely on the same kind of technology: a large language model, or LLM.

The core idea: predicting what comes next

A language model does one thing: given a text, it calculates the most likely continuation. If you write "The capital of France is," the model will calculate that the word "Paris" is very likely and the word "banana" isn't.

The model picks one unit of text, appends it, and asks again what comes next. Unit by unit, a complete answer is built. The model doesn't plan the whole answer in advance and doesn't "pull" it from a database.

These units are called tokens, and there's a separate lesson on them.

How does predicting words lead to writing a contract?

To predict the next word well in every kind of text, the model has to learn a lot about the world: grammar, facts, writing styles, the logic of code and even the structure of a legal argument. When it's trained on a large share of the text available online and in books, that "knowledge" gets compressed into the billions of weights of the neural network.

That's why the same mechanism can summarize, translate, write code and draft a letter. The only difference between the tasks is the text that goes in.

🎬 Large Language Models explained briefly · 3Blue1Brown

The transformer and attention

What makes this possible is an architecture called the transformer, introduced in a 2017 paper by Google researchers. The T in GPT stands for it (Generative Pre-trained Transformer).

Its central innovation is the attention mechanism. When the model processes a word, it "looks" at all the other words in the text and decides which are relevant to understanding it.

Take the sentence: "The trophy didn't fit in the suitcase because it was too big." What does "it" refer to? The trophy. If we write "because it was too small," then the suitcase. Attention lets the model link "it" to the right word based on context. It also processes all the words in parallel rather than one after another, so it can be trained efficiently on enormous amounts of text.

🎬 Transformers, the tech behind LLMs | Deep Learning Chapter 5 · 3Blue1Brown

An LLM is not a search engine

This is the most important insight in this lesson:

  • A search engine finds existing documents and points you to them.
  • A language model generates new text that sounds plausible, based on patterns it learned.

That's why a language model can write a sentence that has never been written before, which is its strength. For the same reason it can also produce a "fact" that sounds credible and isn't true. That's a hallucination. Modern tools add real search to deal with this, covered in the lesson on RAG.

What a "chatbot" is, technically

A model trained only on internet text knows how to complete text, but not necessarily how to answer questions helpfully. What turns it into a conversational assistant is an additional training stage, in which it's taught to answer, refuse dangerous requests and follow a format. We'll take the full process apart in the lesson on how models are trained.

Bottom line: An LLM is a giant neural network that learned to predict the likely continuation of text. That simple prediction, at enormous scale, produces abilities that look like understanding. It's not a database of facts, so it's always worth checking important facts.

Sources

Read next