January 23, 2026 · 11 min read

Training and Inference Generation process of LLM

An easy, farmer-friendly walk-through of how an LLM is trained (by learning patterns from lots of text) and how it later answers your question (by predicting the next small piece of text, one step at a time).

AI Basics · Tokenization · LLM · Inference · Training · Tech Simplified


This six-panel diagram walks through how a large language model (LLM) is trained and how it later generates answers, step by step, one box at a time. (see the generated image below)

training and inference

This diagram is a high-level map of an LLM’s life: first it learns by reading a huge amount of text, then it answers you by generating text one small piece at a time.

To make this feel real, we’ll use a use-case that’s close to a naïve farmer’s life.

The Farmer Use-Case: A “Village Helper” Who Learns From Old Notebooks

Imagine a farmer named Rashid.

Rashid has a small problem: people keep asking him questions:

  • “When should we water the wheat?”
  • “How do we treat pests on tomato leaves?”
  • “What should we do if the sky looks like rain but the wind is hot?”

Rashid wishes he had a helpful assistant who can answer like a wise elder.

So he decides to create a Village Helper—a student who learns from a giant pile of farming notebooks and then answers questions.
That student is our LLM.

Now we’ll walk through the same 6 steps from the diagram, using Rashid’s story.


1. Training Data Ingestion (Collecting Learning Material)

In the diagram: “Training content (cloud) → ingest text”

In the farm story: Rashid gathers learning material for his Village Helper.

He collects:

  • old diaries from experienced farmers
  • seed and fertilizer notes
  • pest treatment notes
  • weather sayings and seasonal reminders
  • market notes (when prices rise, when demand drops)

But these notes are messy:

  • some pages are torn
  • handwriting styles differ
  • some notes repeat
  • some pages contain useless scribbles

So before teaching the student, Rashid and helpers do basic cleaning:

  • remove junk pages
  • keep the readable lines
  • group pages into bundles so the student can study in an organized way

Simple meaning:
This step is just collecting lots of text and making it usable for learning.


2. Tokenization (Breaking Words Into Small Pieces)

In the diagram: “Tokenizer converts input text into token IDs”

In the farm story: Rashid’s student cannot learn directly from handwriting like a human can.

The student only understands numbers.

So Rashid uses a “word cutter and labeler” tool:

  • It breaks sentences into small parts (tokens).
  • It gives each token a number (token ID).

Example:

“water the wheat” might become small pieces like:

  • “water” → 175
  • “the” → 22
  • “wheat” → 222

Sometimes a word is uncommon (like a rare seed name).
Then the tool breaks it into smaller pieces it already knows.

Simple meaning:
Tokenization is turning text into numbered pieces so the model can work with it.


3. Training Step (Core Learning Loop)

In the diagram: “LLM → softmax probabilities → loss → backprop update”

In the farm story: Now the student starts practicing, again and again.

The practice game: “Guess the next word”

Rashid opens a notebook and reads:

“If the soil is dry, then ____”

The student must guess the next token.

Maybe the student guesses:

  • “sleep” (wrong)
  • or “water” (right)

At the beginning, the student is terrible.
But Rashid has the correct notebook text, so Rashid can check the answer.

What “probabilities” mean in simple farm words

Instead of choosing only one guess, the student makes a list like:

  • “water” → 85% likely
  • “wait” → 9% likely
  • “plough” → 2% likely
  • many other words → tiny chances

That “percent list” is what the diagram shows as softmax probabilities.

Loss: “How wrong were you?”

If the notebook says the correct next word is water, but the student gave it a small chance, Rashid says:

“You were quite wrong. Fix your thinking.”

That wrongness score is called loss.

Backprop update: “Adjust the knobs inside the student’s brain”

The student has many internal knobs (weights).
When the student is wrong, Rashid turns those knobs slightly so that next time:

  • “water” becomes more likely in similar sentences
  • bad guesses become less likely

This correction happens millions to billions of times across all the notebooks.

Simple meaning:
Training is just: guess next token → compare with truth → correct yourself → repeat a lot.


4. User Prompt (Inference)

In the diagram: “User prompt → tokenize → feed into model (weights frozen)”

In the farm story: Training is finished. The student has learned patterns from the notebooks.

Now Rashid brings the student to the village to answer real questions.

A farmer asks:

“My wheat leaves are turning yellow. What should I do?”

Important point:
The student is not learning new lessons now.
The student is only using what was already learned.

Also, Rashid uses the same word cutter and labeler (same tokenizer) to convert this question into token IDs, otherwise the student will be confused.

Simple meaning:
Inference is the “answering time,” not “learning time.”


5. Predict Next Token (Choosing the Next Piece)

In the diagram: “Model outputs probabilities → sample next token (greedy/top-k/top-p/temperature)”

In the farm story: The student hears the question and starts forming an answer, but does it in tiny steps.

First it thinks:

“What is the first word I should say?”

Maybe the probabilities look like:

  • “Check” → high chance
  • “Stop” → medium chance
  • “Dance” → near zero chance

Then the system must choose one token.

Why not always choose the top option?

Sometimes you want very steady answers (like medicine dosage).
Then you choose the safest, highest-probability token.

Other times you want more variety (like writing a story or giving multiple options).
Then you allow a bit of randomness.

That “randomness dial” is what people call temperature.

  • Low temperature: practical, stable, less surprising
  • High temperature: more variety, sometimes weird

Simple meaning:
The model doesn’t output a sentence. It outputs a menu of next-token chances, then one is picked.


6. Generate Full Answer (Repeat Until Finished)

In the diagram: “Append token → repeat until EOS”

In the farm story: The student doesn’t speak the whole answer in one breath.

It speaks like this:

  1. Chooses the first token: “Check”
  2. Adds it to the growing answer: “Check …”
  3. Looks again at the full context (question + what it already said)
  4. Chooses the next token: “the”
  5. Now it has: “Check the …”
  6. Next token: “soil”
  7. Now: “Check the soil …”

This continues until the student produces a special “stop” token, meaning:

“My answer is complete.”

That stop sign is the EOS token (End Of Sequence).

Simple meaning:
The model creates the answer one token at a time, repeatedly.


Big-Picture Insight (Why This Works So Well)

In Rashid’s village story, the student became useful not because it memorized one notebook, but because it learned patterns across many notebooks:

  • which words usually follow others
  • how advice is normally written
  • how causes and effects are described
  • how steps are ordered (“first… then… finally…”)

An LLM is basically that same student—trained with an enormous number of examples—so its “next token guessing” becomes strong enough to look like real understanding.

Not magic.
Just a very large amount of practice, guided by corrections.


Quick Mental Summary (One Line Per Step)

  1. Ingestion: collect and clean learning text (the notebooks).
  2. Tokenization: cut text into pieces and number them.
  3. Training loop: guess next piece, compare with truth, adjust internal knobs.
  4. Prompt/inference: user asks a question; model uses learned knobs (no new learning).
  5. Next token: model predicts chances for the next piece; system picks one.
  6. Full answer: repeat token picking until the stop sign (EOS).