LLM Inference and Generation Settings

In the previous tutorial, we learned about the context window.

We saw that an LLM receives information as context and uses that information to produce a response.

Now let’s understand what happens when we actually use a trained AI model.

That process is called inference.


βš™οΈ What is Inference?

Inference is the process of using a trained AI model to produce an output from an input.

In simple terms:

Training teaches the model. Inference uses the trained model.

For example:

Input

Trained AI Model

Output

If the input is:

β€œThe sun rises in the”

the model may predict:

β€œeast”

The process of making that prediction is inference.


πŸ‹οΈ Training and Inference

Let’s make the difference very clear.

During training, the model learns.

Training Data

Model

Learning

Learned Parameters

After training is complete, we can use the model.

Input

Trained Model

Output

That second process is inference.

So:

Training = learning

Inference = using what was learned


βš™οΈ Inference in an LLM

For an LLM, the input is usually text.

For example:

β€œThe sky is”

The LLM processes the input and predicts what token should come next.

Conceptually:

"The sky is"

LLM

Possible next tokens

"blue"

The model then has:

β€œThe sky is blue”

It can continue predicting the next token.

"The sky is"

"blue"

"."

This process continues until the response is complete.


βš™οΈ LLMs Generate Tokens

We learned about tokens earlier.

An LLM doesn’t directly generate an entire paragraph at once.

It generates a sequence of tokens.

For example, a simplified response:

β€œThe sky is blue.”

could be generated as a sequence like:

The

sky

is

blue

The exact tokens depend on the tokenizer.

The important idea is:

An LLM generates its response step by step by predicting tokens.


πŸ“Œ What Does the Model Predict?

The model looks at the information currently available to it and calculates possible next tokens.

For example:

The sky is

The model might assign different probabilities to possible next tokens:

blue

high probability

clear

lower probability

beautiful

green

very low probability

These values are only an example.

The model is essentially asking:

β€œBased on everything I have seen so far, what should come next?”

It then selects a token according to the model’s generation settings.


πŸ“Œ Then It Predicts Again

After generating one token, the new token becomes part of the sequence.

For example:

The sky is

blue

Now the model has:

The sky is blue

It can predict the next token again.

The sky is blue

So the overall process looks like:

Input

Predict next token

Add token

Repeat

This continues until the model stops generating.


πŸ“Œ What Information Does the Model Use?

The model uses the information available in its current context.

We just learned about the context window.

So the simplified process is:

Current Context

LLM

Next Token

Updated Context

The newly generated token becomes part of the sequence used for subsequent predictions.


πŸ’‘ A Simple Example

Let’s imagine we ask:

β€œComplete this sentence: Water freezes at”

The model might predict:

Water freezes at

0

Then:

Water freezes at 0

Β°

Then:

Water freezes at 0Β°

C

The exact token sequence depends on the tokenizer and model.

But the basic idea is the same:

The model keeps predicting what should come next.


βš™οΈ Is Inference Only Used for Text?

No.

Inference is a general AI concept.

For example, an image-classification model could receive:

Image

AI Model

Prediction

The prediction might be:

β€œCat”

Similarly, a speech model could receive:

Audio

AI Model

Text

So:

Inference means using a trained model to produce a result.

For LLMs, that result is commonly generated text.


πŸ€” Why Is Inference Important?

Inference is the part of AI that users actually interact with.

When you:

  • Ask an AI a question
  • Generate text
  • Summarise something
  • Translate text
  • Generate code
  • Ask for an explanation

you are using a trained model through inference.

The model has already learned its parameters during training.

Now it is using those parameters to produce an output.


πŸ’‘ A Simple Real-World Analogy

Imagine a student preparing for an examination.

Learning

The student studies books and learns concepts.

Books

Study

Knowledge

Using the knowledge

During the exam, the student receives a question and gives an answer.

Question

Student's learned knowledge

Answer

This is only an analogy, but it helps us understand the difference:

AI Training

Learning

AI Inference

Using what was learned


βš™οΈ Does Inference Change the Model?

Normally, no.

When you ask an LLM a question, the model is not normally retraining itself from that question.

The trained parameters remain unchanged during ordinary inference.

So:

User Question

Inference

Response

does not mean:

User Question

Training

Changed Model

These are different processes.


βš™οΈ How Does an Answer Stop?

The model needs to know when to stop generating.

Generation can stop when:

  • The model produces an appropriate end condition
  • A configured stopping condition is reached
  • The maximum output length is reached

You don’t need to remember the technical details yet.

Just remember:

Inference continues until the model or application decides that generation should stop.


βš™οΈ Inference Can Be Fast or Slow

Inference requires the model to perform calculations.

A small model may produce responses relatively quickly.

A larger model may require more computing resources.

The speed can also depend on:

  • Model size
  • Hardware
  • Number of input tokens
  • Number of output tokens
  • Application configuration

So when people talk about AI inference performance, they are talking about how efficiently the model can produce its output.


🧩 The Complete Picture

Let’s put the concept together:

User Input

Tokens

Context

Trained LLM

Predict Next Token

Generated Token

Output Text

This entire process of using the trained model to generate the result is inference.


πŸ“Œ Training vs Inference β€” Remember This

This is the most important thing from this tutorial:

Training

Learn model

Parameters learned

Inference

Use model

Output

If you remember only one thing:

Training is when the model learns. Inference is when we use the trained model.


🧩 Key Takeaways

  • Inference means using a trained AI model to produce an output.
  • In an LLM, inference involves generating tokens.
  • The model predicts tokens one after another.
  • The current context influences those predictions.
  • Normal inference does not retrain the model.
  • Inference is what happens when we actually use an AI model.

🧩 Where We Are

Our journey now looks like:

Large Language Models

Tokens

Vectors

Embeddings

Transformers & Attention

Parameters

Context Window

Inference

During inference, the model has different possible next tokens with different probabilities.

So our next question is:

How can we control how predictable or varied the model’s responses are?

That leads us to our next topic:

πŸ€– AI Temperature