Dez Udezue
Blog

LLMs, evaluation and human judgement · Part 1 of 7

AI is a master of form, not substance: the mathematical reason for hallucinations

Imagine an AI providing a perfect academic citation, complete with volume numbers and a professional abstract, only for you to find the paper does not exist. The AI did not lie in the human sense. It simply calculated what a professional citation looks like and generated a sequence of words that fit the pattern.

A curved chain of ceramic tiles with one casting an unexpected shadow.
Part 1 of 7 · Browse the series

The Illusion of Certainty

When an AI gives a wrong answer, it often does so with absolute confidence. It can fabricate citations or historical events that feel entirely authentic. This occurs because there is a fundamental gap between how a model sounds and whether it is actually correct.

The model is not accessing a library of verified facts. Instead, it is performing a complex statistical calculation to determine which words should follow one another.

From Words to Numbers

To process language, a model first uses tokenization to break text into smaller chunks called tokens. These tokens are converted into embeddings, which are numerical coordinates in a multi dimensional space.

Words with similar meanings are placed close together. However, a word like "bank" can mean a river edge or a financial institution. To solve this, the model uses an attention mechanism.

This mechanism acts like a spotlight, looking at surrounding words to determine the specific meaning of a token. If the word "money" is nearby, the attention mechanism adjusts the numerical value of "bank" to represent a financial institution. This is a mathematical weighting process, not a conscious thought.

The Architecture of Prediction

After attention is applied, the data moves through several layers that refine the text. Some layers handle grammar, while others manage tone or logical relationships.

At the final stage, the model produces a probability distribution. It does not "pick" the right answer: it calculates the percentage chance that various tokens are the correct next step.

This is driven by pretraining, where the model is fed staggering amounts of internet text. By repeatedly trying to predict the next token, the model accidentally learns facts and reasoning patterns simply by mastering the patterns of human communication.

The Preference Trap

A raw model can be unpredictable. To fix this, developers use Reinforcement Learning from Human Feedback (RLHF), where humans rank different responses.

This process optimizes the model to produce answers that humans prefer. This leads to a critical flaw: humans often prefer answers that look professional and confident, even if they contain subtle errors.

The model learns that sounding helpful is the path to a high reward, which can inadvertently encourage it to prioritize fluency over truth.

Why Hallucinations Happen

Hallucinations are the result of these statistical gaps. Because the model cannot fact check itself in real time, it will generate the most plausible-looking sequence of tokens even if they do not map to a real world fact.

Some developers use Retrieval-Augmented Generation (RAG) to allow the AI to look up real documents. This improves accuracy, but it is not a perfect solution. The model can still misinterpret the source or ignore a contradiction.

The most important takeaway is that fluency is not understanding. An LLM is a brilliant tool for brainstorming or translation, but for any claim requiring a factual anchor, it is important to remember that the model is not recalling a fact: it is predicting a sentence.