A large language model (LLM) is a neural network trained on huge amounts of text to predict the next token, a word or word piece. Repeating that prediction produces sentences, code and answers. An LLM does not look facts up or know what is true, so it can state wrong things fluently. ChatGPT, Claude and Gemini are built on LLMs.
This page explains LLMs in short sections: what they predict, how they are trained, why they get facts wrong, and how to pick one for a project. It has a table of terms you can bookmark and a Python script you can run to watch next-word prediction happen.
Papers, prices and model facts were read from primary sources on 11 November 2026. Prices and limits change often, so check the dates.
- 1Text inyour prompt, cut into tokens
- 2Predicta score for every possible next token
- 3Pickchoose one token
- 4Repeatadd it and predict again
An LLM in plain words, with a table of terms
A large language model is a neural network trained on a very large amount of text to predict the next token. A token is a piece of text: a word, part of a word or a punctuation mark. Predict one token, add it to the text, predict the next, and the model writes a sentence, an essay or a function. ChatGPT, Claude and Gemini are apps built on top of LLMs.
The key consequence is that an LLM produces text that is likely, not text that has been checked. It has no built-in fact database to look things up in. That is why it can write a convincing wrong answer, and why products add search, documents or tools around it. What is RAG covers the documents route. For a longer walk-through, see Masai's What is a Large Language Model.
| Term | Plain meaning | Why it matters |
|---|---|---|
| Token | A chunk of text the model reads and writes, often a word or part of a word | Prices and limits are counted in tokens, not words |
| Parameters (weights) | The numbers inside the network that training adjusts | More parameters usually mean more capacity and more memory to run |
| Transformer | The network design behind modern LLMs, built around attention, from a 2017 paper | Lets the model weigh every part of the input when predicting the next token |
| Pre-training | Learning to predict the next token on a huge text collection | Where most language skill and knowledge comes from |
| Post-training | Extra training with human feedback so the model follows instructions | Turns a text predictor into an assistant |
| Inference | Using the trained model to produce an answer | This is the part you pay for in an API |
| Context window | How much text the model can consider at once | Long documents must fit, or be retrieved in pieces |
| Temperature | A setting for how random the choice of the next token is | Low for facts and code, higher for brainstorming |
| Embedding | A list of numbers that represents the meaning of a text | Powers semantic search and RAG |
| Hallucination | A fluent output that is false or unsupported | Check anything that matters |
| Open weights | The trained parameters can be downloaded and run by you | You can run it locally, but the licence still applies |
A next-word predictor you can run
Real LLMs are huge, but the core task fits in a few lines. This script 'trains' on one tiny text by counting which word follows which, then generates by choosing next words. It is a toy bigram model: it looks at one previous word and uses whole words as tokens. A real LLM uses a transformer that reads the whole context, sub-word tokens and billions of learned parameters. GPT-3, described in a 2020 paper, had 175 billion.
import random
from collections import Counter, defaultdict
corpus = ("the cat sat on the mat . the dog sat on the rug . "
"the cat chased the dog . the dog chased the cat .")
words = corpus.split() # step 1: "tokenise" (real models use sub-word pieces)
counts = defaultdict(Counter) # step 2: "train" = count which word follows which
for a, b in zip(words, words[1:]):
counts[a][b] += 1
def next_word_probs(word):
total = sum(counts[word].values())
return {w: round(c / total, 2) for w, c in counts[word].most_common()}
print("after 'the':", next_word_probs("the"))
print("after 'sat':", next_word_probs("sat"))
def generate(start, steps, rng=None):
out = [start]
for _ in range(steps):
options = counts[out[-1]]
if rng is None: # greedy: always take the most likely next word
out.append(options.most_common(1)[0][0])
else: # sampling: draw in proportion to the counts
r, running = rng.random() * sum(options.values()), 0
for w, c in options.items():
running += c
if r < running:
out.append(w)
break
return " ".join(out)
print("greedy:", generate("the", 6))
for seed in (5, 7):
text = generate("the", 6, random.Random(seed))
first = text.split(" .")[0]
print(f"seed {seed}: {text!r} | first sentence in training text? {first in corpus}")Output:
after 'the': {'cat': 0.38, 'dog': 0.38, 'mat': 0.12, 'rug': 0.12}
after 'sat': {'on': 1.0}
greedy: the cat sat on the cat sat
seed 5: 'the dog chased the rug . the' | first sentence in training text? False
seed 7: 'the cat sat on the dog .' | first sentence in training text? FalseWhat it shows
- Probabilities, not facts. After 'the' the model gives 'cat' and 'dog' 0.38 each. It stores how often words follow each other and nothing else.
- Fluent but false. Seed 7 writes 'the cat sat on the dog', a sentence that never appears in the training text and contradicts it (the cat sat on the mat). The model recombined patterns that fit. Real LLMs do the same at far greater scale, so a smooth sentence is not evidence that it is right.
- Greedy decoding loops. Always taking the likeliest word gave 'the cat sat on the cat sat', which starts to repeat. Sampling adds variety, and temperature is the dial for how much.
- A fixed seed makes the random draw repeatable, so the output above is the same on every run.
How an LLM is built and used: training vs inference
- Pre-training. The model reads a huge text collection and learns to predict the next token. This is the expensive step and the vendor does it once.
- Post-training. The raw model is trained further to follow instructions. The 2022 InstructGPT paper used human-written examples and then reinforcement learning from human rankings. It found people preferred outputs from a 1.3 billion parameter model trained this way over the 175 billion parameter GPT-3.
- Inference. You send a prompt and the model generates tokens one at a time. Its weights do not change while you chat. Any 'memory' is text the app puts back into the prompt.
The transformer design behind this comes from the 2017 paper 'Attention Is All You Need' by Vaswani and colleagues, which dropped recurrent and convolutional layers and relied entirely on attention.
Context window
The context window is how much text the model can consider in one request. Anthropic's model overview lists 1M tokens for its current Claude models as of 11 November 2026, and says that is roughly 555,000 words on its current tokenizer. Ollama's library lists 128K to 256K tokens for Gemma 4 tags and 256K for Qwen3.8 27B. A bigger window is a limit on what fits, not a promise that the model uses all of it well: research on long inputs found models do worse on facts placed in the middle.
Why LLMs hallucinate
A 2025 paper, 'Why Language Models Hallucinate' by Kalai and colleagues, argues that hallucinations follow from how models are trained and tested. It says training and evaluation procedures reward guessing over acknowledging uncertainty, and it frames hallucinations as errors in telling incorrect statements apart from facts. The authors propose changing how existing benchmarks are scored. The toy above shows the basic mechanism in miniature: pick a plausible next token, and plausible is not the same as true.
What helps in practice:
- Give the model the source text and tell it to answer only from it. That is the idea behind RAG.
- Ask for the source and open it. A confident citation can still be invented.
- Let tools do exact work: a calculator for sums, a database query for numbers, a code runner for code.
- A lower temperature makes output steadier. It does not make false statements true.
- Test on questions where you already know the answer, and write down the failures. The prompt engineering guide shows how to ask for sources and uncertainty.
Open weights vs closed models, and how to choose one for a project
A closed model such as Claude, GPT or Gemini runs on the vendor's servers, and you reach it through an app or an API. An open-weights model such as Gemma or Qwen publishes its trained parameters so you can download and run it. 'Open weights' is not the same as 'open source'. The Open Source Initiative's Open Source AI Definition 1.0 expects detailed information about the training data, the complete training and inference code under OSI-approved licences, and the parameters under OSI-approved terms. Many downloadable models release only the weights, so read the licence before you use one in a product.
| Option | Examples, 11 Nov 2026 | Cost to try | Catch |
|---|---|---|---|
| Closed model in a chat app | Claude, ChatGPT and Gemini free plans | ₹0, with usage limits | Limits and features change, and vendors do not publish the caps as numbers |
| Closed model API, free tier | Gemini API: Gemini 3.8 Flash is listed as free of charge | $0, with rate limits | Free tiers change, so check free LLM APIs for developers |
| Closed model API, paid | Claude Sonnet 5.5 at $2 per million input tokens and $10 per million output; Claude Haiku 5.5 from $0.10 and $0.50 | Pay per token | The bill grows with usage |
| Open weights, run locally | Gemma 4 tags from 4.6 GB (e2b) to about 20 GB (31b); Qwen3.8 27B at 18 GB, via Ollama | Free to download; needs your RAM or GPU | Smaller local models are usually less capable than the largest hosted ones |
- Start with a free API tier and the smallest model that passes your own test questions.
- Use a small, cheap model for classification and extraction, and a stronger one for hard reasoning or code.
- Go local when the data is private or you want to learn how models run, and your laptop has the memory.
- Do not choose by leaderboard alone. Check what each test measures, and test on 20 examples of your own work.
- Re-check prices and limits before you commit to a design, because they change.
Tool-by-tool picks are in best AI tools in 2026, ranked. To see how these terms fit into the wider field, read AI vs data science vs machine learning.
Cost basics: you pay for tokens in and tokens out
API prices are quoted per million tokens, with one price for input (everything you send) and a higher one for output (what the model writes). A token is not a word: Anthropic's overview puts 1M tokens at roughly 555,000 words on its current tokenizer, so a token is a little over half a word there. Other vendors' tokenizers differ. Costs rise with prompt length because every call sends the whole context again.
# Prices are US dollars per million tokens (Claude Sonnet 5.5 list price, 11 Nov 2026).
INPUT_PER_M, OUTPUT_PER_M = 2.00, 10.00
def cost(input_tokens, output_tokens):
return input_tokens / 1_000_000 * INPUT_PER_M + output_tokens / 1_000_000 * OUTPUT_PER_M
one_call = cost(3_000, 300) # a RAG question: 3,000 tokens of context in, 300 tokens out
print(f"one call: ${one_call:.4f}")
print(f"1,000 calls: ${1000 * one_call:.2f}")
print(f"same call, whole 500-page book pasted in (200,000 tokens): ${cost(200_000, 300):.2f}")Output:
one call: $0.0090
1,000 calls: $9.00
same call, whole 500-page book pasted in (200,000 tokens): $0.40A question that sends 3,000 tokens of retrieved text and gets 300 tokens back costs under a cent at that list price. Pasting a 500-page book, about 200,000 tokens, into every call costs about 44 times as much. That is why RAG retrieves a few chunks instead of sending everything.
Three ways to keep a bill small: send less text, use the smallest model that works, and use caching and batching where the vendor offers them. Anthropic lists prompt cache reads at 5% of the base input price for Sonnet 5.5, and batch requests at 50% off. Gemini 3.8 Flash on the Gemini API has a free tier, and its paid price is $0.75 per million input tokens and $3.75 per million output tokens through 31 December 2026, then $1.50 and $7.50 from 1 January 2027. All prices here are in US dollars.
Frequently asked questions
What is an LLM in simple words?
An LLM, or large language model, is a program trained on a huge amount of text to predict the next word or word piece. By repeating that prediction it can write sentences, answer questions and produce code. It works with patterns in language, not with a checked database of facts, which is why it can sound sure and still be wrong.
Is ChatGPT an LLM?
ChatGPT is an app. The LLM is the model inside it, from OpenAI's GPT family. The app adds the chat screen, tools, memory and safety rules around the model. The same is true of the Claude app and the Gemini app. People often say ChatGPT when they mean the model, which is where the confusion comes from.
What does 'large' mean in large language model?
It refers to the size of the model, counted in parameters, and the amount of text it was trained on. GPT-3, described in a 2020 paper, had 175 billion parameters. There is no official threshold: 'large' is a loose label, and smaller models that run on a laptop are still called LLMs by many people.
What is the difference between AI, generative AI and an LLM?
AI is the broad field of machines doing tasks that need intelligence. Machine learning builds AI by learning from data. Generative AI creates new content such as text, images or audio. An LLM is a generative model for text, built with machine learning. So every LLM is generative AI, but not all AI is an LLM.
What is a token in an LLM?
A token is the unit of text the model reads and writes. It may be a whole word, a piece of a word, a number or punctuation. Limits and prices are counted in tokens. Anthropic's overview says 1M tokens is roughly 555,000 words on its current tokenizer, so a token is a little over half a word.
Do LLMs understand what they say?
They learn patterns that let them solve many language tasks, but they are trained to predict likely text, not to check truth. That is why they can produce fluent falsehoods. Whether this counts as understanding is debated, so the practical rule is simpler: treat the output as a draft and verify facts that matter.
Can I run an LLM on my laptop?
Yes, if it has enough memory. Tools such as Ollama download open-weights models and run them locally. Its library lists Gemma 4 tags starting at about 4.6 GB for the smallest. Small local models are usually less capable than the largest hosted ones, but they are free to run and work offline once downloaded.
Sources checked
- Attention Is All You Need (Vaswani et al., June 2017)
- GPT-3 paper: 175 billion parameters
- InstructGPT: 1.3B model preferred over 175B GPT-3
- Why language models hallucinate (Kalai et al. 2025)
- Lost in the Middle
- Claude model prices, 1M context, 555k words per 1M tokens, cache and batch discounts
- Gemini 3.8 Flash free tier and paid prices
- Gemma 4 tag sizes and context windows
- Qwen3.8 27B size and context window
- Open Source AI Definition 1.0
Learn this with mentors
AI and machine learning programmes with admissions open: live classes, mentors and project work.

