Module 1 · Foundations of Agentic AI · scripted

Next-Word Prediction: Learning from Patterns

15 minoutcomes: prompt-engineering

How does the LLM formulate its response?

LLMs are taught, as part of their training process, to predict the next word. The model is shown a sentence where we already know what the next word should be, and it is trained until its prediction matches. Repeat this at enormous scale and something remarkable happens: the model becomes incredibly sensitive to the patterns in our words.

Part of the underlying architecture is a mechanism for learning what to pay attention to — words it saw earlier, even much further back in the text — and how to use them to figure out what's coming next. That attention to distant context is a large part of what makes the prediction so powerful.

The simple case: patterns it already knows

user

Complete this sentence with one word: Mary had a little ____

assistant

lamb

NoteNo reasoning required — the phrase appears so often in training text that "lamb" is overwhelmingly the most probable next word. This is next-word prediction at its most visible.
user

Lille Petter Edderkopp klatret på min ____

assistant

hatt

NoteSame mechanism, different language. The model has seen the Norwegian nursery rhyme too. Pattern sensitivity isn't an English feature — it's the core skill.

Beyond memorized phrases: patterns established on the fly

Memorized rhymes are the trivial case. The interesting case is a pattern that exists only inside the current conversation. Watch a transcript establish two characters — their voices, their relationship, their situation — and then hand the model just two words of the next line:

user

Here is a scene. Continue it.

MAGNUS (a gruff Molde fisherman, man of few words, distrusts technology): "Forecast app says calm seas. App doesn't smell the wind."

INGRID (his granddaughter, marine-biology student, teases him gently): "Your nose has a software update available, bestefar."

MAGNUS: "Nose has worked for fifty years. Never needed charging."

INGRID: "And yet you charge your hearing aid every night."

MAGNUS: "That's

assistant

different," Magnus grunted, pushing the tiller over. "Hearing aid doesn't tell me when to fish. It tells me when you're talking."

NoteThe completion continues several patterns at once: it sounds like Magnus (short, gruff, dry), it answers Ingrid's jab, it fits the boat, and it advances the exchange. "Mary had a little" looked simple — but the same mechanism handles a rich pattern the prompt itself established seconds ago. Nothing was memorized; the pattern was in the document.

We don't actually know how it does this

Here is the honest and fascinating part: we don't know how the model does this internally. We know how to set these systems up, train them, and build them — but how the structure inside gives rise to this capability is an area of active research. Much of that research looks strikingly like neuroscience: researchers run ablation studies, disabling components to see what breaks, the same way we probe the brain. We built it, we can train it, and we are still reverse-engineering what it actually learned.

We know how to build one — not what it learned

Hold both of these at once, because both are true. We know how to train one: the architecture, the training loop, the data pipeline — the mechanics of building these systems are established engineering, written down and reproducible. And at the same time: we don't know what the learned weights represent or how they operate. The recipe is understood; the thing the recipe produces is not. Everything in this course sits on that strange foundation.

A conversation is a trajectory

Now connect this back to an earlier idea. If the prompt is the whole conversation, and the model continues patterns, then a conversation is not a container of facts — it is a trajectory. Every message pushes the model in a direction; the model tries to complete the conversation along the path the document has established, until it reaches a natural stopping point (or a word limit). Same question, different trajectory, different continuation:

user

We've been writing postcard lines all morning: "Molde wears the rain like a wool sweater — comfortably." Give me one about the fjord.

assistant

"The fjord doesn't reflect the mountains — it keeps a copy, in case the weather takes the originals."

NoteThe conversation established a pattern: short, poetic, wry. The question "give me one about the fjord" rides that trajectory.

The trajectory is assembled from the conversation's parts

Where did that trajectory come from? Not from any single sentence. Read the conversation again and you can pick out the components — a place, a task, a voice, a track record — each one embedded somewhere in the text. Together they aim the document. When you read a conversation and sense where it could head next — that sense is the trajectory.

The parts that aim the document

The trajectory is not a rail

Two more things before the contrast example, and they matter. First: the trajectory does not have to be deterministic or tightly constrained — it is a direction, not a track. Second, the consequence: the same conversation can yield a different trajectory each time we generate. Send the identical document twice and watch:

The same conversation, generated twice
user

We've been writing postcard lines all morning: "Molde wears the rain like a wool sweater — comfortably." Give me one about the fjord.

assistant

"The fjord doesn't reflect the mountains — it keeps a copy, in case the weather takes the originals."

NoteNow send the SAME document again — not one word changed:
assistant

"The fjord is the sky's rough draft — revised twice a day by the tide."

NoteSame place, same task, same voice, same history — a different line. Both continuations honor the trajectory's components; neither is "the" answer. Generation samples from the possibilities the document has made probable. The trajectory is a cone, not a rail — and everything we do as prompt engineers is narrowing or aiming that cone.

And now the contrast: the same subject, aimed down a completely different trajectory.

user

We're planning ferry logistics. Crossing times: Molde–Vestnes 35 min, departures every 45 min from 06:00. Now — the fjord: what do I need to know?

assistant

Key operational facts: the crossing is weather-exposed in autumn; allow buffer for missed departures (worst case 45 min); last sailing ~23:30; foot passengers board 5 min before departure.

NoteSame underlying subject — "the fjord" — completely different continuation, because the document pushed a different trajectory. Neither answer is the "real" one. The trajectory decided.

The takeaway

Prompt engineering is trajectory engineering. Every technique to come — examples, roles, tools, plans, retrieved knowledge — is a way of shaping the document so that the most probable continuation is the one we want.

Your turn

Take a question from your own domain that could be answered in two very different registers — poetic and operational, or theoretical and practical. Write two short conversations that establish each trajectory, end both with the same question, and compare what comes back.