All lessons Leer en español

History · Unit 09

Language models

From local word statistics to neural representations, transformers, retrieval, and assistants, with clear limits on memory and trust.

12 minready

Helpful before thisA short history of AI

After this lesson you can

  • distinguish autoregressive prediction from masked-language-model objectives
  • explain tokens, embeddings, attention, and context without treating them as guaranteed memory
  • separate retrieved evidence, generated claims, and permission to act

Explore the eras below. On wider screens, scroll sideways to see the full timeline.

A language model learns patterns in language and can assign probabilities or useful representations to text. Many conversational generators predict successive tokens, but that is not the definition of every model in the field. Different training objectives and architectures support generation, classification, retrieval, and other tasks.

Causal and masked language modelingCausal modeling predicts a following token from earlier context. Masked modeling predicts a missing token using permitted surrounding context. These are distinct training setups, not successive stages.Causal predictionEarlier context → next tokenthe sky is …Earlier text supplies contextMasked predictionSurrounding context → gapthe … is blueBoth sides can supply context
Two families of prediction: a causal model uses earlier context for the next token; a masked model can use surrounding context for a missing token. These learning setups support different uses.

From local statistics to learned representations

Statistical language models estimate which sequences are likely. An n-gram model approximates context using a limited number of neighboring items. Such models were useful in speech and language applications; their limitations do not make them pointless predecessors.

Neural language models learned distributed representations and probability functions together. Bengio and colleagues described an influential model in 2003. Work such as word2vec in 2013 made learned word vectors especially prominent.

An Embedding is a numerical representation, not a perfect dictionary definition. Similarity reflects the model and task; nearby vectors do not prove two claims mean the same thing. Representations derived from sensitive data also require privacy review. Turning information into numbers does not automatically anonymize it.

Why an unseen phrase is a problem

Imagine a tiny word-level bigram model trained on “the cat sleeps” and “the dog sleeps.” It has counts for those neighboring word pairs, but none for “the rabbit.” A raw count estimate gives an unseen continuation no support even though the sentence may be ordinary English. Smoothing can reserve probability for unseen events; it cannot supply unlimited context or reliable facts.

Learned representations offer another way to generalize. Similar contexts can influence related predictions without storing a separate count for every exact phrase. The 2003 neural probabilistic model explored that idea. Generalization can also be wrong: a useful statistical resemblance does not prove that a new statement is true.

Tokens and attention

A Token may represent a word piece, a byte sequence, or a special marker. Tokenization affects length and representation. It is useful to distinguish characters, words, and tokens when estimating what fits into an input.

The 2017 transformer paper showed an architecture based on Attention mechanisms. Attention combines representations according to learned scores. Masks govern which positions can interact: a causal decoder normally cannot use future output tokens, while a masked model such as BERT can use surrounding input context.

Roles, masks, and training can influence instruction-following. They do not by themselves constitute a complete application security boundary. A document’s text must not acquire permission to alter policy simply because the model can read it.

For a causal example, give the model “The museum closes at” and ask it to continue. Its next prediction can use preceding tokens, but not the answer it has yet to generate. In a masked example, “The museum [MASK] at six” supplies words on both sides of the missing position. The second task therefore has different available evidence. Neither objective, by itself, looks up the museum’s real opening hours.

Training and use are different stages

Pretraining learns broad patterns from a training objective. Further training can adapt a model to instructions, preferences, or particular tasks. These stages can change behavior and capability; they are more than cosmetic chat packaging.

An application may combine a model with search, stored state, and tools. Retrieval-augmented generation adds selected external information to generation. Retrieval does not automatically update the model’s learned parameters, and retrieved information can still be outdated, irrelevant, or misleading.

Three places information can live

Mechanism What it contributes What changes it
Learned parameters Patterns fitted during training A training or model-update process
Prompt and current context Instructions and material supplied for this invocation The application’s selection of input
External retrieval Chosen documents or records from another store Source updates, indexing, and retrieval choices

If our fictional museum changes its closing time, updating a document can make new evidence retrievable without retraining the model. But the application must retrieve the right version and include it. A fact being stored somewhere does not prove it reached this answer. Conversely, inserting a correction in one prompt does not necessarily change the model’s parameters or every future conversation.

The 2020 GPT-3 paper made learning tasks from examples in context especially prominent. In that evaluated setup, examples guide the response without a gradient update to the model for each task. This is different from fine-tuning: the input can change while the learned parameters remain fixed.

Context is bounded and selected

A Context window limits what an invocation can use and generate under the implementation. When material exceeds the available capacity, applications may reject it, truncate it, summarize it, or select portions. There is no universal rule that the oldest message always disappears.

A large window does not guarantee reliable use of every included fact. Durable storage, retrieval, and conversational context are distinct mechanisms. Check what evidence is actually available for the answer.

EXPLORE THE CONCEPT

What does the assistant actually know?

Explore three short situations. The answer depends on available evidence and application behavior, not on how confident the wording sounds.

The relevant rule was not included

A larger advertised window does not prove the rule reached this invocation. The assistant should acknowledge the missing evidence and retrieve or request the rule rather than invent its contents.

A retrieved document asks for a new action

Retrieval supplies source material, not permission. The application must evaluate any proposed action against the user's request and its own access controls; source text does not grant new authority.

The answer includes a polished citation

Check the actual source and whether it supports the specific claim. A title, date, or hyperlink can look convincing while being incorrect, unavailable, or irrelevant.

A simplified learning model. It connects to no systems and uses no real data.

Check claims and actions separately

Fluent answers can contain factual errors, unsupported inferences, or invented references. Sampling settings can affect variation but do not supply a truth guarantee. Verify consequential claims against suitable evidence.

Tool-enabled applications add another decision: should a proposed action run, using which identity and permissions? Text-only output can also affect decisions or disclose information. Evaluate both paths. Secure AI systems connects these concepts to practical protective design.

Instruction-following training can make a response better match a person’s request and preferred format. It does not convert fluent generation into verified knowledge. An assistant can follow “answer in three bullet points” perfectly while placing an unsupported claim in every point. Historical progress in usability and progress in factual reliability must therefore be evaluated separately.

PredictThe assistant cites a retrieved museum policy, but the cited paragraph concerns last year’s holiday schedule. Is the citation enough?

No. Check the date, scope, and exact support for the claim. A real source can still be the wrong evidence for today’s question.

Terms you met

TokenEmbeddingAttentionContext windowRetrieval-augmented generation

Check yourself

No timer. No penalties. Read the explanation and try again whenever you like.

  1. Are all language models defined only by predicting the next token from earlier tokens?

    Show the answer

    Correct answer: No; autoregressive and masked-language-model objectives use different conditioning. Causal prediction is common in generators; masked models can use surrounding context for missing tokens.

  2. Does a long context window prove the model retained every earlier conversation detail?

    Show the answer

    Correct answer: No; included material and its effective use depend on the application and model. History may be omitted, summarized, retrieved, or unavailable; length alone is not a memory guarantee.

  3. Does retrieving a document make its instructions authorized?

    Show the answer

    Correct answer: No; source content and authority to act are separate. An application must preserve permission boundaries when using external material.

  4. What should happen to a plausible citation in generated text?

    Show the answer

    Correct answer: Verify the cited work exists and supports the claim. Formatting and fluent wording do not establish provenance or accuracy.

Try it

  • WriteAsk a fictional study assistant to summarize three invented library rules. Compare its answer with the supplied rules, mark unsupported claims, and decide what it should say if one rule is missing. Do not include real secrets or personal records.
References