What Is Inference
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.
| Everyday moment | Input | Output from inference |
|---|---|---|
| Photo search | "beach" and your photos | The beach photos |
| Voice typing | Your speech | Text on the screen |
| A map's arrival time | Your route and today's traffic | "Arrive at 9:12 a.m." |
| A chat assistant | Your question | A 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:
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)Yellowness 0.85: most likely banana
Yellowness 0.15: most likely apple
Yellowness 0.6: most likely banana
Threshold after inference: 0.5Three 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:
- Define inference in one sentence.
- In the Python example, what happened to the threshold during inference?
- Name two reasons companies care about inference speed and cost.
Key Takeaways
Quick reference
| Term | Meaning |
|---|---|
| Inference | Using a trained model on new input |
| Latency | How long one inference takes |
| On-device | Inference that runs on your phone or computer |
| Cost per request | The computing cost of one inference |
Was this tutorial helpful?