What is an LLM, and how does it work?

A large language model (LLM) is an AI system trained on huge amounts of text to predict the next piece of text in a sequence. That one skill, done at enormous scale, is what lets tools like ChatGPT, Claude and Gemini answer questions, write, summarise and code. LLMs don’t look facts up the way a database does, which is why they can sound confident and still be wrong.

The short explanation

Give an LLM some text and it works out which word is most likely to come next, adds it, and repeats. Do that thousands of times and you get a paragraph, an essay or a working function. The “large” refers both to the training data, often trillions of words drawn from books, websites and code, and to the model itself, which can have hundreds of billions of internal settings, called parameters.

How an LLM works, step by step

  1. Tokens. Text is split into tokens: whole words, parts of words or punctuation. “Unbelievable” might become “un”, “believ” and “able”. Models read and write in tokens, which is why usage limits and pricing are counted in them.
  2. Training. During pre-training, the model reads vast amounts of text and repeatedly guesses the next token. Each wrong guess slightly adjusts its parameters. Over billions of examples it picks up grammar, facts, styles of writing and patterns of reasoning.
  3. The transformer. Almost all modern LLMs use the transformer architecture, introduced by Google researchers in 2017. Its key idea, attention, lets the model weigh how every token in the input relates to every other, so it can keep track of what “it” or “they” refers to across a long passage.
  4. Fine-tuning. A raw pre-trained model is good at continuing text but not at being helpful. Further training on examples of good answers, plus feedback from human reviewers (reinforcement learning from human feedback, or RLHF), turns it into an assistant that follows instructions.
  5. Generating a reply. When you send a prompt, the model predicts a probability for every possible next token, picks one, and repeats. A setting called temperature controls how adventurous those picks are.

Key terms you will see

Term What it means
Parameters The internal values learned during training; roughly, the model’s size
Context window How much text the model can consider at once, including your prompt, files and its reply
Prompt The instructions and content you give the model
Hallucination A fluent but false or invented answer
RAG Retrieval-augmented generation: fetching relevant documents and giving them to the model so it answers from real sources
Open-weight model A model whose parameters are published so anyone can run it on their own hardware

Why LLMs hallucinate

An LLM generates what is statistically plausible, not what it has checked. If the training data was thin on a topic, or the question invites a specific answer it doesn’t have, it will still produce fluent text, and that text can include made-up citations, figures or quotes. Web search and RAG reduce this by giving the model real sources to work from, but they don’t remove it. For anything that matters, check the source.

What LLMs are good and bad at

  • Good at: drafting and editing text, summarising long documents, explaining concepts, translating, writing and reviewing code, and brainstorming.
  • Weaker at: precise arithmetic without tools, very recent events unless they can search, niche facts, and knowing when they don’t know something.

The main LLMs today

The best-known assistants are built on a handful of model families: OpenAI’s GPT models (ChatGPT), Anthropic’s Claude models, Google’s Gemini models and xAI’s Grok. Meta, Mistral, Alibaba’s Qwen team and DeepSeek publish open-weight models that developers can run themselves. New versions arrive every few months, so the leader in any given task changes often.

For a practical comparison of two of them, see Claude vs ChatGPT.