CORTEX: Token-Level Hallucination Detection in RAG via Comparative Internal Representations
The paper proposes CORTEX, a token-level hallucination detection method for Retrieval-Augmented Generation that identifies ungrounded content by comparing a model's internal representations with and without retrieved documents, while leveraging information propagation and span-consistent smoothing to achieve fine-grained localization of hallucinations.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you have a very smart, well-read assistant (the AI) who is trying to answer a question for you. To make sure the answer is accurate, you give the assistant a stack of reference books (the retrieved documents) to look at while they write.
Sometimes, the assistant does a great job, sticking strictly to the books. Other times, they might accidentally invent a fact or mix up a detail, even though the books are right there on the desk. This is called a "hallucination."
The problem is that in a long, detailed answer, the AI might get 90% of the facts right from the books, but slip up on just one or two sentences. Most current tools are like a security guard who only checks the entire report at the end. If the report is mostly good, they might say, "Looks fine!" and miss the tiny lie hidden in the middle.
This paper introduces CORTEX, a new tool designed to be a "microscope" that checks the answer word-by-word (or token-by-token) to spot exactly where the AI is making things up.
Here is how CORTEX works, using three simple analogies:
1. The "With and Without" Test (Comparative Internal Representations)
Imagine you are trying to figure out if a student is actually reading a textbook or just guessing.
- The Old Way: You look at the student's answer and try to guess if they read the book.
- The CORTEX Way: You ask the student the same question twice.
- First time: You give them the textbook to read.
- Second time: You take the textbook away and ask them to answer from memory.
CORTEX compares the "brain activity" (internal thoughts) of the AI during these two scenarios.
- If the AI is talking about a fact found in the book, its "brain" changes significantly when the book is present. It's like the student's eyes lighting up because they found the answer in the text.
- If the AI is making something up (hallucinating), its "brain" looks almost the same whether the book is there or not, because it's just pulling from its own memory.
By comparing these two states, CORTEX can spot exactly which words changed because of the book (good) and which words stayed the same because they were made up (bad).
2. The "Chain of Thought" Detective (Contextual Residual)
Sometimes, an AI is smart enough to read a fact from the book early in the answer, and then use that fact to build the rest of the sentence later.
- The Problem: If you only look at the later sentence, it might look like the AI isn't using the book anymore, because the book isn't mentioned right there. This could trick a detector into thinking the later sentence is a lie, even though it's based on a true fact found earlier.
- The CORTEX Solution: CORTEX acts like a detective who follows the trail. It realizes, "Hey, this sentence is relying on a fact the AI just read two sentences ago." It subtracts that "indirect influence" so it doesn't get confused. This prevents the tool from falsely accusing the AI of lying when it's actually just continuing a true story.
3. The "Noise Filter" (Label-Persistence Smoothing)
Imagine you are listening to a radio station that has a lot of static. Sometimes the static makes a single word sound like a lie, even if the whole sentence is true.
- The Problem: Raw detection tools can be jittery. They might flag one word as a lie, then the next word as truth, then the next as a lie, creating a messy, scattered pattern. But in reality, if an AI is lying, it usually lies for a whole phrase or sentence, not just one isolated word.
- The CORTEX Solution: CORTEX applies a "smoothing" filter. It assumes that if one word is a lie, the words immediately next to it are likely part of the same lie. It connects the dots, turning a scattered mess of "maybe-lies" into a clear, solid block of "definite-lies." This makes the final result much easier for a human to read and understand.
The Results
The authors tested CORTEX on two different sets of questions and three different AI models. They found that:
- CORTEX is much better at finding the exact words that are made up compared to other methods.
- It works even when the AI is an "API" model (a black box you can't see inside) by using a different, open AI model to do the detective work behind the scenes.
- Every part of the system (the comparison, the chain-of-thought check, and the smoothing) helped make the detection more accurate.
In short, CORTEX is a tool that helps us trust AI answers more by pinpointing exactly where the AI is making things up, rather than just guessing if the whole answer is good or bad.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.