1.0.0
Home
Menu ✕
▼Search
Search content
▼Content Navigator
▼Popular Tags
▼Archive
◀
Home> Artificial Intelligence> Generative AI> From output prediction to the probabilistic map

From output prediction to the probabilistic map: autoregression, self-attention and embeddings

What you will find in this article
  • What a generative model learns instead of a mapping: a probabilistic map of patterns, sequences and combinations, and why its output is a path through plausible continuations rather than a pick among labels.
  • Two analogies that make the map concrete — the artist who recombines a repertoire and the cartographer who infers terrain never seen — and where hallucination comes from.
  • Autoregression: generation one token at a time, each choice conditioned on everything already written, with the fluency and the drift that this implies.
  • Self-attention as selective focus over the history, and why it keeps a character introduced on page one alive many paragraphs later.
  • Embeddings: how words, images and code become vectors, and how cosine similarity turns meaning into geometry (Paris next to Rome, far from spoon), with a runnable example.
CODEFLOW · ARTIFICIAL INTELLIGENCE · GENERATIVE AI The probabilistic map Not a label for each input, but a distribution over what could come next autoregression · self-attention · embeddings context …the detective p(next token | context) opened 0.53 found 0.32 sang 0.07

Ask a fraud model about a payment and it answers with one of two labels it was trained to tell apart. Ask a language model to continue "the detective" and it does not answer with a label at all: it answers with a distribution — opened is likely, found is plausible, sang is unlikely but not impossible — and then commits to one of them, moves on, and asks the question again with one more word in the context. That shift, from a mapping between input and expected output to a map of probabilities over what could come next, is what this article is about, together with the three mechanisms that make the map usable: autoregression, self-attention and embeddings.[4]

1. From a mapping to a map of probabilities

Traditional AI, as defined in the previous article, learns a mapping between an input and its expected output. Generative AI changes the focus: instead of looking only for the correct answer to an input, it learns probability distributions over patterns, sequences and possible combinations. That learning builds a probabilistic map of what tends to make sense in a given context. The result is not a choice among known labels but a navigation through plausible paths to produce a new, coherent output.[4,5]

The difference shows in what the model returns. A classifier returns one point of a closed set. A generative model returns, at every step, a whole distribution over the next piece — and the output is the path it walks through those distributions. Figure 1 puts the two side by side.

A mapping returns a label; a probabilistic map returns a distribution — Figure 1
Input xa transaction Learned f(x)mapping x → y One labelfraud or normal Context so far“The detective” Modelprobabilistic map distribution over the next token opened  0.53 found  0.32 sang  0.07  ·  others 0.08 Traditional AI Generative AI The label is the end of the traditional pipeline. The distribution is one step of the generative one: a token is drawn from it and the question is asked again.
Figure 1 — The classifier's answer space was fixed before training. The generative model's answer is a distribution over every token in its vocabulary, computed for the current context and recomputed after each choice. Probabilities are illustrative.

Practise: open in the Lab: Exercise 1, Map versus mapping

2. Underlying patterns and coherent generation

Training on large volumes of data serves to capture the implicit structures that organise information, even when they are not explicitly labeled. The model learns regularities of language, style, association and continuity, which raises its ability to tell probable sequences from sequences that are foreign to the context.[5] That is the basis of coherent generation: the output seems to make sense because it respects recurring patterns learned during training. Nobody wrote down that a sentence in English tends to put the verb after the subject, that a recipe lists ingredients before steps, or that a function's closing brace comes after its body; the model absorbed those regularities from millions of examples in which they hold.

The same fact explains the failure mode. The better the training, the higher the chance that the model produces something consistent and the lower the chance that it drifts into a hallucination — an output that follows the patterns of plausible text without being anchored in anything true.[7] A hallucinated citation has the shape of a citation: authors, a title, a year, a venue. The map says "this is what a citation looks like here"; it does not say "this citation exists". Coherence and truth are different properties, and only the first one is what the map optimises.

▼An old idea: language was always predictable
In 1951 Claude Shannon asked people to guess the next letter of an English text and measured how well they did: printed English carries only about one bit of information per letter, because most of what comes next is predictable from what came before.[9] A language model is a machine that learned that predictability at the scale of tokens, styles and topics. The probabilistic map is not a new idea; what is new is a model large enough to hold a useful one.

3. Two analogies: the artist and the cartographer

The artist analogy reduces the abstraction of the process. An artist observes many works, internalises styles, compositions and relations, and then produces something new without literally copying a specific piece. The generative model operates in a similar way: it uses a learned statistical repertoire to compose an original output conditioned on the context it received. Originality arises from the coherent recombination of patterns, not from creation out of nothing.

The cartographer analogy explains the map itself. A cartographer does not only record the mountains, rivers and forests already seen; they learn the logic of the terrain and start to infer where new elements could exist. The model likewise does not merely memorise examples: it learns the structure of the space of possibilities. When asked to generate something similar to what it knows, it projects a new configuration compatible with the regularities it observed. That is how it can draw an "imaginary island" coherent with the islands it has seen — a harbour on the sheltered side, a river coming down from the highlands, a village at the river mouth — even though that particular island never existed.

AspectThe artistThe cartographer
What is learnedA repertoire of styles, compositions and relationsThe logic of the terrain: which configurations are possible
What is producedA new work that recombines the repertoireA new map compatible with the regularities
What it is notNot a copy of one pieceNot a memory of one place
Where it failsPastiche: style without substancePlausible terrain that is not there
Mechanism in the modelEmbeddings and attention (sections 6 and 7)The learned distribution, sampled step by step (section 4)

Table 1 — The two analogies describe the same object from two sides: the artist stresses recombination, the cartographer stresses the structure that makes a never-seen output coherent.

Practise: open in the Lab: Exercise 2, The cartographer

4. Autoregressive models: one token at a time

Autoregressive models generate content token by token, choosing each next element on the basis of the previous ones.[4,5] In text this means that each word produced changes the context available for the next decision, forming a chain of local dependencies. Formally, the probability of a whole sequence is the product of the probability of each token given everything before it:

(1) p(x1, …, xT | prompt) = ∏t=1T  p(xt | prompt, x<t)

Take the scenario of generating a novel in the style of a famous detective series. The model uses the learned repertoire of style and structure — a crime, a list of suspects, a clue the reader overlooked, a reveal in the last chapter — but the concrete construction happens step by step during generation. Coherence emerges because each new choice must be compatible with what has already been written: once the detective has opened something, the next token is very probably something that can be opened. Figure 2 shows one step of the chain.

One step of autoregressive generation — Figure 2
each token is chosen given the prompt and every token before it Prompt The detective opened the letter ? and 0.44 slowly 0.27 then 0.06 Step 6: the context is the prompt plus five tokens. The model returns a distribution; one token is drawn from it and joins the context for step 7. The output is never planned as a whole: it is the trail left by a sequence of local decisions, each compatible with the previous ones.
Figure 2 — Autoregression as a chain: the dashed arcs are the dependencies of each token on the ones before it. The distribution at position 6 is computed for exactly this context; after "and" is drawn, position 7 gets a new one. Probabilities are illustrative.

Practise: open in the Lab: Exercise 3, Softmax

5. Autoregression as a process of writing

The writer analogy shows why autoregression works well for language. A writer does not materialise the whole text at once; they write a sentence, use that sentence to guide the next one, and adjust course as the narrative advances. The model does the same at statistical scale: it keeps autocompleting itself until the sequence is done. This mechanism explains both the fluency of generation and the possibility of drift: when the chain starts to follow a path that is plausible but incorrect, every later step is conditioned on that error and tends to make it look consistent rather than to fix it.[6]

  • Fluency. Each token is chosen to fit the ones already written, so the surface is smooth by construction.
  • Drift. A single unlikely choice — a wrong name, an invented number — becomes context for everything after it. The map has no separate notion of "true"; it only has "consistent with what came before".
  • Why review stays mandatory. Reading the output is the only step in which something other than the map judges it.
▼Always taking the most likely token is not the best writing
One might expect the best output to come from always picking the top token of each distribution. In practice, that greedy strategy produces repetitive, dull text, while sampling from the distribution — with a temperature that sharpens or flattens it, or a cut that keeps only the most probable tokens — produces text that reads as human-like.[6] Human text is not a sequence of most-likely words; it is a sequence of plausible ones. The map is meant to be walked, not followed along its ridge.

6. Self-attention: keeping the relevant parts of the context

Attention and context were introduced before; the new point here is self-attention as the way of preserving relevant relations along the sequence. Self-attention lets the model weigh which earlier parts of the text matter more for interpreting or generating the next token.[1] In a long text this helps the model keep links between distant elements — a character introduced at the beginning and picked up many paragraphs later. Without this mechanism, generation would lose continuity far more easily, because a model that only looked at the last few tokens could not know who she is.

In practical terms, self-attention works as a system of selective focus over the available history. The model does not treat all previous tokens as equally important; it assigns larger weights to the relations most useful for the current decision. Each position builds a query, compares it with the keys of every position before it, turns the comparisons into weights that sum to one and uses them to blend the values:

(2) Attention(Q, K, V) = softmax( QK⊤√dk ) V

Back to the book: this is what lets the model sustain the identity of the main character and the logic of the narrative even when many events happen in between. The pronoun on page two hundred attends to the name on page one, and the clue being examined attends to the letter opened three sentences earlier. Figure 3 shows the weights for one such decision.

Selective focus: which earlier tokens matter for “she” — Figure 3
Attention weights of the pronoun over the history (darker = more weight) Nadia found the key … many paragraphs and hundreds of tokens later she turned it again weights from “she”: Nadia 0.62 · key 0.21 · found 0.05 · the 0.02 · everything else 0.10 Illustrative weights, consistent with the coreference patterns observed in attention heads of real models. A model that only saw the last few tokens could not resolve “she”.
Figure 3 — Self-attention as selective focus: for the decision at "she", the model weights the name introduced long before far above the tokens in between. That is what keeps the character's identity stable across a long text.

Practise: open in the Lab: Exercise 4, Selective focus

7. Embeddings: from symbols to vectors

Before operating on words, images or code, the model converts those elements into numeric vectors called embeddings.[2,4] This vector representation turns symbolic items into points of a mathematical space where relations can be measured computationally. The model does not "read Portuguese" or "read English" the way a human does; it processes numeric patterns that encode semantic and contextual properties. That is what makes it possible to compare meaning by geometric proximity between vectors.

The embeddings are not designed by hand. They are learned together with the rest of the model, adjusted so that words used in similar ways end up with similar vectors — which is exactly the property the probabilistic map needs, because a distribution learned for one context can then apply to another context that is close in this space even if the words differ.[4] Real models use hundreds or thousands of dimensions; Figure 4 uses two so that the geometry can be seen.

▼What the dimensions mean
Nothing, individually. In the toy space of Figure 4 the two axes were chosen by hand (a "capital" direction and a "France to Italy" direction) so the picture is readable. In a real model no axis has a name: meaning is spread across all the dimensions, and only distances and directions between vectors are interpretable — which is why comparisons use the angle between vectors, equation (3), rather than any single coordinate.

8. Semantic similarity by vectors

When two terms appear in similar contexts, their vectors tend to end up close in the semantic space; when they appear in very different contexts, they tend to end up far apart.[2,10] That is why pairs such as Paris and Rome occupy nearby regions, while Paris and spoon usually sit further apart. The analogy with geographic coordinates helps: vector proximity works like proximity of location, but in a space of meaning. The standard measure is the cosine of the angle between two vectors:

(3) cos(u, v) = u · v‖u‖ ‖v‖
(4) vParis − vFrance + vItaly ≈ vRome

Equation (3) gives 1 for vectors pointing the same way, 0 for unrelated ones and −1 for opposites, regardless of their length. Equation (4) is the famous consequence: directions in the space carry relations, so subtracting France from Paris and adding Italy lands near Rome.[3] This structure is one of the bases on which the model recognises relations, keeps context and chooses more plausible continuations.

Six words in a toy embedding space, and their cosine similarities — Figure 4
Two dimensions, chosen by hand for the picture capital France ↔ Italy direction ParisRomeFranceItaly spoonfork Paris − France ≈ Rome − Italy Cosine similarity, equation (3) ParisRomeFranceItalyspoon ParisRomeFranceItalyspoon 1.00 0.71 0.57 −0.17 −0.89 0.71 1.00 −0.17 0.57 −0.95 0.57 −0.17 1.00 −0.91 −0.14 −0.17 0.57 −0.91 1.00 −0.30 −0.89 −0.95 −0.14 −0.30 1.00 Paris − France + Italy = (−0.55, 0.85): cosine 0.98 with Rome, −0.79 with fork, −0.88 with spoon. Vectors in the code box below; the numbers are exact for this toy space.
Figure 4 — Left: the vectors of six words in a two-dimensional space built for the picture; the dashed arrows are the same displacement, which is what makes equation (4) work. Right: the cosine similarities computed from those vectors with the code below. A real model has hundreds of dimensions and no named axes, but the same geometry.

The whole of Figure 4 fits in a few lines. The vectors are the ones plotted; the outputs in the comments are what the code prints:

semantic_neighbours.py — Python
import math

vec = {                                   # toy embeddings in two dimensions; real models use hundreds
    "paris":  (0.35, 0.85),  "rome":  (-0.35, 0.85),
    "france": (0.45, 0.10),  "italy": (-0.45, 0.10),
    "spoon":  (0.05, -0.60), "fork":  (-0.05, -0.55),
}

def norm(u):
    return math.sqrt(sum(a * a for a in u))

def cosine(u, v):
    # equation (3): 1 = same direction, 0 = unrelated, -1 = opposite; length does not matter
    dot = sum(a * b for a, b in zip(u, v))
    return dot / (norm(u) * norm(v))

def neighbours(word, k=2):
    others = [w for w in vec if w != word]
    return sorted(others, key=lambda w: cosine(vec[word], vec[w]), reverse=True)[:k]

def analogy(a, b, c):
    # equation (4): a - b + c, then the closest word that is not one of the three
    target = tuple(x - y + z for x, y, z in zip(vec[a], vec[b], vec[c]))
    candidates = [w for w in vec if w not in (a, b, c)]
    return max(candidates, key=lambda w: cosine(target, vec[w]))

print(neighbours("paris"))                # ['rome', 'france']
print(neighbours("rome"))                 # ['paris', 'italy']
print(round(cosine(vec["paris"], vec["spoon"]), 2))   # -0.89: far apart
print(analogy("paris", "france", "italy"))   # rome

Practise: open in the Lab: Exercise 5, Cosine and analogy

9. Conclusion

A generative model does not store answers; it stores a map. Training on large volumes of data turns the implicit structure of language, code and images into probability distributions over what tends to make sense in a given context. Autoregression walks that map one token at a time, which is why the output is fluent and why it can drift; self-attention decides which parts of the history matter for each step, which is why a long text keeps its characters and its thread; embeddings give the map its coordinates, so that meaning can be compared as distance and relations as direction. Keep the cartographer in mind: the model infers terrain it never saw, coherent with terrain it did see — and only a reader can check whether the city is really there.

References (10) Tags Related Articles Versions and History
  • [1]A. Vaswani; N. Shazeer; N. Parmar et al. — Attention Is All You Need, NeurIPS 2017. arXiv:1706.03762 (accessed on 09/10/2026)Academic paper
  • [2]T. Mikolov; K. Chen; G. Corrado; J. Dean — Efficient Estimation of Word Representations in Vector Space, ICLR Workshop 2013. arXiv:1301.3781Academic paper
  • [3]T. Mikolov; I. Sutskever; K. Chen; G. Corrado; J. Dean — Distributed Representations of Words and Phrases and their Compositionality, NeurIPS 2013. arXiv:1310.4546Academic paper
  • [4]Y. Bengio; R. Ducharme; P. Vincent; C. Jauvin — A Neural Probabilistic Language Model, Journal of Machine Learning Research 3, 2003. jmlr.orgAcademic paper
  • [5]A. Radford; J. Wu; R. Child; D. Luan; D. Amodei; I. Sutskever — Language Models are Unsupervised Multitask Learners, OpenAI, 2019. cdn.openai.comTechnical report
  • [6]A. Holtzman; J. Buys; L. Du; M. Forbes; Y. Choi — The Curious Case of Neural Text Degeneration, ICLR 2020. arXiv:1904.09751Academic paper
  • [7]Z. Ji; N. Lee; R. Frieske et al. — Survey of Hallucination in Natural Language Generation, ACM Computing Surveys 55(12), 2023. arXiv:2202.03629Academic paper
  • [8]D. Bahdanau; K. Cho; Y. Bengio — Neural Machine Translation by Jointly Learning to Align and Translate, ICLR 2015. arXiv:1409.0473Academic paper
  • [9]C. E. Shannon — Prediction and Entropy of Printed English, Bell System Technical Journal 30(1), 1951. doi:10.1002/j.1538-7305.1951.tb01366.xAcademic paper
  • [10]J. Pennington; R. Socher; C. D. Manning — GloVe: Global Vectors for Word Representation, EMNLP 2014. aclanthology.org/D14-1162Academic paper

Further reading

  • [a]J. Alammar — The Illustrated Transformer. jalammar.github.ioTutorial
  • [b]I. Goodfellow; Y. Bengio; A. Courville — Deep Learning, MIT Press, 2016, chapter 10 (sequence modeling). deeplearningbook.orgBook

References verified on 09/10/2026 and checked during technical review. External links open outside Codeflow.

Key concepts:Probabilistic mapAutoregressive generationSelf-attentionEmbeddingsCosine similarityHallucination as drift

Click a tag to list all related articles.

Title Category Reading Published Status
Mythology, automata and the origin of the question: the early history of AI, from Turing to the first winter Artificial Intelligence14 min 09/10/2026 Published
Traditional AI versus generative AI: predict from known data or compose new outputs Artificial Intelligence13 min 09/10/2026 Published
When code stops being the differentiator: the developer's role with generative AI Artificial Intelligence13 min 09/09/2026 Published
Fundamentals over tools: how to evaluate and build with generative AI Artificial Intelligence12 min 09/09/2026 Published
What is Generative AI, and why did it only become viable now? Artificial Intelligence12 min 09/08/2026 Published
5 related article(s) in Artificial Intelligence
Article version
1
Published on
09/10/2026 14:00
Author
@rafaelsantos
Source language
English

09/10/2026 14:00 — Initial publication of the article.

▼Comments

Comments are GitHub Discussions on codeflow/codeflow.github.io. Sign in with GitHub to post; each article has its own thread.

Contents
Help
Article Contents ✕
Figures

The contents reflect the article open in the main area.

Help ✕
How to read an article

The labels at the top indicate the category, level and review stage of the content. Numbered citations [1] point to the References tab at the end of the article.

The formulas are numbered on the right and referenced in the text as “equation (n)”. The figures are SVG: they follow browser zoom without loss.

Use the language selector at the top to switch between versions of the same article, when they exist.

Exercise Lab ✕
Language not available ✕


You can keep reading it in the current language or go to the Home page in the selected language.