What Is Inference

Updated · 5 min read
easyPython 3.13aiinferencemodelsbeginnersinterview

What happens when you point a trained model at something new? Advitha's fruit-sorting model is trained. On Saturday morning at the market, a customer holds up an apple the model has never seen, and the app says: "most likely an apple". That moment, using the trained model on new input, is called inference.

Training happens once in a while. Inference happens every time anyone uses AI. This lesson explains what it is and what it isn't.

Using What Was Learned

Inference is using a trained model to produce an output for new input. The model applies the patterns stored in its parameters, and the parameters don't change.

A trained model turns new input into output, without changing
Everyday momentInputOutput from inference
Photo search"beach" and your photosThe beach photos
Voice typingYour speechText on the screen
A map's arrival timeYour route and today's traffic"Arrive at 9:12 a.m."
A chat assistantYour questionA reply, written word by word

Inference in Python

The fruit model from "What Is Training" learned a threshold of 0.5. Inference is just using it:

Python
threshold = 0.5  # learned during training, and now fixed
 
def predict(yellow):
    """Inference: use the trained parameter on new input. Nothing changes."""
    return "banana" if yellow > threshold else "apple"
 
for new_photo in [0.85, 0.15, 0.6]:
    print(f"Yellowness {new_photo}: most likely {predict(new_photo)}")
print("Threshold after inference:", threshold)
Output
Yellowness 0.85: most likely banana
Yellowness 0.15: most likely apple
Yellowness 0.6: most likely banana
Threshold after inference: 0.5

Three new photos, three answers, and the threshold is still 0.5. There is no comparing with labels and no adjusting: new photos don't come with labels, which is exactly why we need the model.

Why Inference Speed and Cost Matter

One inference is fast and cheap compared with training, but products run inference millions of times a day, so its cost adds up. That is why companies care about:

  • Speed (latency): how long one answer takes. Voice assistants need answers in a fraction of a second.
  • Cost per request: chat assistants that use large models pay for the computing behind every reply, which is why many services limit free use.
  • Where it runs: on your phone (private and quick, but limited to small models) or in a data center (powerful, but your input travels there).

Common Mistakes

Thinking the model learns while it answers. During inference, the parameters are fixed; "Does AI Learn from Every Conversation?" explains what does change.

Thinking inference is free because it's quick. At millions of requests a day, it is one of the biggest costs of running AI.

Thinking a confident output is a certain one. Inference gives the model's best guess, such as "most likely an apple".

Interview Corner

What is inference?

Using a trained model to produce an output for new input, such as recognizing a photo or answering a question. The model applies its learned parameters, which don't change.

Why does inference cost matter if each request is cheap?

Because products run inference at enormous scale. A small cost per request, multiplied by millions of requests a day, becomes a major expense, and speed affects how usable the product feels.

Practice

Exercise: spot inference. For one day, note five moments when an app ran inference for you. For each, write the input, the output, and whether you think it ran on your device or in a data center. What clue told you?

Check your understanding:

  1. Define inference in one sentence.
  2. In the Python example, what happened to the threshold during inference?
  3. Name two reasons companies care about inference speed and cost.

Quick check: what is inference

4 questions
1What is inference?
2What happens to a model's parameters during inference?
3Why doesn't inference compare outputs with labels?
4A translation feature works with no internet connection. What does that suggest?

Key Takeaways

Quick reference

TermMeaning
InferenceUsing a trained model on new input
LatencyHow long one inference takes
On-deviceInference that runs on your phone or computer
Cost per requestThe computing cost of one inference

Was this tutorial helpful?

Lesson 19 of 186