Large Language Model

Print Print
Reading time 3:10

A large language model (LLM) is a type of machine learning model trained on vast amounts of text to predict and generate natural language. Modern LLMs are built on the transformer architecture and are trained with billions to trillions of parameters, allowing them to perform a wide range of language tasks - answering questions, writing code, summarizing text, translating languages - without being explicitly programmed for each one.

How LLMs Are Trained

Training an LLM happens in stages. In pre-training, the model reads enormous quantities of text scraped from the web, books, and other sources, learning statistical patterns in language by repeatedly trying to predict missing or upcoming words. This stage requires massive compute clusters and can take weeks or months, producing what is often called a "base model." Base models are good at continuing text in a plausible way, but they aren't yet tuned to be helpful assistants - that comes later, in post-training stages such as instruction tuning and reinforcement learning from human feedback.

Tokens and Context Windows

LLMs don't process text character by character or word by word; they process tokens, which are chunks of text produced by a tokenizer (often a sub-word piece, roughly 3-4 characters in English on average). The context window is the maximum number of tokens a model can consider at once, encompassing both the input prompt and the generated output. A larger context window lets a model reason over longer documents or conversation histories, but also increases the compute cost of each request, since attention (see below) scales with the number of tokens being processed.

Next-Token Prediction

At its core, an LLM is a function that takes a sequence of tokens and outputs a probability distribution over what the next token is likely to be. Generating text is a repeated process: predict the next token, append it to the sequence, and repeat.

Simplified generation loop

tokens = tokenize(prompt)
for _ in range(max_new_tokens):
    next_token = model.predict_next(tokens)
    tokens.append(next_token)
    if next_token == END_OF_SEQUENCE:
        break
output = detokenize(tokens)

A setting called temperature controls how deterministic this process is: a temperature of 0 always picks the most likely token, while higher values introduce more randomness into the selection, producing more varied (and sometimes less predictable) output.

Instruction Tuning and Alignment

A raw, pre-trained model is skilled at predicting plausible text but has no particular tendency to be helpful, honest, or safe - it will happily continue a harmful prompt if that's the statistically likely continuation. To turn a base model into an assistant, developers apply supervised fine-tuning on curated examples of good question-and-answer behavior, often followed by reinforcement learning from human feedback (RLHF), where the model is rewarded for producing outputs that human raters prefer. This alignment process is what gives modern chat-style LLMs their characteristic helpful, conversational tone.

Using LLMs via an API

Most LLM providers expose their models through an HTTP API, typically accepting a list of messages and returning a generated response as JSON.

Typical chat completion request

{
  "model": "example-llm-1",
  "messages": [
    { "role": "system", "content": "You are a helpful assistant." },
    { "role": "user", "content": "Explain recursion in one sentence." }
  ],
  "temperature": 0.7
}

This message-based format (system, user, and assistant roles) is now a de facto standard across most LLM providers, making it relatively easy to switch between different models in an application.

Limitations

LLMs have well-documented limitations: they can produce confident but incorrect statements (see hallucination), their knowledge is frozen at whatever point their training data was collected unless supplemented with external tools, and they have no persistent memory between separate conversations unless an application explicitly stores and re-supplies that context. Understanding these limitations is essential for building reliable applications on top of LLMs.

By: Tomas Silny
Edited: 2026-08-13 06:49:57