Skip to content
Joey Wang
Menu

Search

AI-Native Engineering

Generalization: Why AI Looks Smart

How LLMs generalize from patterns instead of understanding, where that generalization holds up in practice, and where it quietly breaks down.

· 5 min read

ai #llm#ai

Part of the series: Software Engineering in the LLM Era

Audio summary

This is the part that makes people either overrate LLMs or get spooked by them.

You ask a model to write code in a style you did not explicitly teach it. It does a decent job. You give it a problem phrased in a way it probably never saw word-for-word in training. It still produces something useful.

That feels like intelligence, or close enough that people start talking as if the model is thinking in the human sense. What is really happening is less magical and more interesting: generalization. That is what this article is about, and why I think it matters for engineering with these systems.

What Is Generalization?

Generalization is the ability to apply knowledge from known situations to novel situations. You’ve seen a hundred dogs. You encounter a breed you’ve never seen. You still recognize it as a dog.

Without generalization, every new situation would require learning from scratch. Nothing would transfer.

In traditional software, there is no generalization:

def calculate_discount(price, discount_percent):
    return price * (1 - discount_percent / 100)

The function doesn’t adapt. It executes the same logic regardless of context. LLMs are fundamentally different: they generalize from patterns in their training data to handle inputs they have never seen.

How LLMs Generalize: Pattern Matching at Scale

Remember from the first article in this series: LLMs predict tokens based on probability distributions. Generalization emerges from that mechanism.

During training, the model sees patterns like “a dog is a” → “mammal”, “the dog” → “barked”, “every dog has” → “its day”. It learns statistical relationships between “dog” and related concepts. Given a novel prompt like “describe a Shiba Inu,” it may never have seen that breed name, but it has learned that “Shiba Inu” appears in similar contexts as “dog,” and that “describe a X” typically generates descriptions with a certain structure: appearance, behavior, origin, temperament. So it generates a plausible description.

This looks like understanding, but what you are mostly seeing is pattern completion at scale.

LLMs generalize by recognizing structural similarities between known and novel inputs.

They don’t have a concept of “dog” the way you do. They have a statistical representation, a position in a high-dimensional space where similar concepts cluster together.

Human Generalization vs AI Generalization

AspectHumanLLM
GroundingEmbodied experienceText patterns only
CausalityUnderstands cause-effectLearns correlation patterns
MemoryPersistent, associativeStateless, context-bound
LearningContinuous from experienceFrozen at training end
UnderstandingConceptual modelsStatistical associations

This table explains why LLMs can seem brilliant one moment and make bizarre errors the next: they are not doing the same thing you do when you “generalize,” even when the output looks identical.

Two Examples

Code generation. Ask for a function that filters active users who logged in within 30 days, and the model produces clean, idiomatic code, correct field names included. It has seen thousands of similar filtering functions: the pattern of filtering a list by conditions, common date manipulation, list comprehension syntax. It isn’t “knowing” how to filter, it’s completing a pattern it has seen many times. This works well because code has highly regular patterns and the model has seen millions of examples.

Math word problems. Ask “if 3 cats catch 3 mice in 3 minutes, how many cats catch 100 mice in 100 minutes,” and the model may walk through a step-by-step answer that looks like reasoning, and still get it wrong. It has seen many rate-problem templates and the phrase “let’s think step by step” often precedes correct answers in training data, but it isn’t computing. It’s generating text that looks like reasoning. When the problem is sufficiently novel, the pattern doesn’t match, and the answer is wrong.

Where Generalization Holds, and Where It Doesn’t

Zone 1: Direct Pattern Match
"Write a Python function to sort a list" → excels (seen this exact pattern)

Zone 2: Structural Similarity
"Write a Rust function to sort a list" → does well (same structure, different syntax)

Zone 3: Novel Combination
"Sort a list using quantum computing principles" → struggles (no direct pattern, must combine)

Zone 4: True Novelty
"Invent a new sorting algorithm for 4D data" → fails (requires genuine innovation)

The further from training patterns, the less reliable generalization becomes.

LLMs generalize well when the domain has regular patterns (code, formal writing, common reasoning), training data is abundant, the task resembles training examples, and errors are acceptable (drafts, exploration). They generalize poorly when the domain requires precise computation, training data is sparse (niche topics, recent events, private data), the task requires true novelty, or errors are costly (medical, legal, financial decisions).

Designing Around It

Before deploying an LLM feature, ask what zone the use case falls into, how similar it is to patterns the model has likely seen, and what a generalization failure costs you. Zone 1-2 tasks are usually safe to send straight to the model. Zone 3-4 tasks need scaffolding: use the LLM for ideation, and put a human or a validator between its output and anything that matters.

Few-shot examples are the cheapest way to shift a task into a more familiar zone. Instead of asking a model to classify a support ticket cold, show it three or four labeled examples first. The model isn’t learning in the training sense, but it now has a much closer pattern to match against.

The most reliable architecture combines the two: let the LLM generalize to produce a candidate answer, then check that answer with deterministic code before it reaches anything that matters.

The Feature and the Bug

The same mechanism that gives you rapid prototyping, cross-domain synthesis, and answers to questions you didn’t anticipate also gives you silent failures that look plausible, blind spots on rare inputs, and a hard stop at the training cutoff. It’s the same coin. Design for both sides of it: use generalization where the cost of being wrong is low, and wrap it in validation where the cost is high.

This is the second article in the “Software Engineering in the LLM Era” series. Read Article 1: What is LLM.