← Latest papers
💬 NLP

PTP: Previous-Token Prediction based LLM Inversion for Near-Exact Prompt Reconstruction

This paper introduces PTP, a black-box method for near-exact prompt reconstruction that trains an explicit inverse language model from scratch using previous-token prediction on synthetic data generated by the target LLM, outperforming prior semantic reconstruction approaches in accuracy and transferability.

Original authors: Pirzada Suhail, Nagasai Saketh Naidu, Atanu R Sinha, Amit Sethi

Published 2026-08-03
📖 7 min read🧠 Deep dive

Original authors: Pirzada Suhail, Nagasai Saketh Naidu, Atanu R Sinha, Amit Sethi

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

=== SUMMARY ===
Imagine you are standing in front of a magical, all-knowing robot that loves to tell stories. You give it a secret starting sentence, and it instantly spits out a long, fascinating tale. This is how modern "Large Language Models" (LLMs) work: they are like super-smart autocomplete engines that predict the next word in a sentence, one by one, to build a response. But here's the tricky part: if you only see the end of the story (the response), can you figure out exactly what the start was (the prompt)? It's like trying to guess the first move of a chess game just by looking at the final checkmate. Usually, this is nearly impossible because many different starting sentences can lead to the same ending. Scientists have been trying to solve this "inversion" puzzle to understand how these AI minds work, to catch them if they reveal secrets, or to see if we can trick them. Most previous attempts required peeking inside the robot's brain (accessing its internal code) or using massive amounts of outside data to guess the starting point.

Now, meet the researchers who decided to try a different trick. Instead of trying to read the robot's mind or guess based on outside knowledge, they built a "reverse robot." They taught this new robot to think backward. While the original robot learns by asking, "What comes next?", the new robot learns by asking, "What came before?" They didn't need to see the original robot's secret code or use a giant library of outside books. Instead, they played a game with the original robot: they fed it random starting words and recorded the stories it told. Then, they fed those stories into their new "reverse robot" in reverse order, teaching it to predict the words that must have come before. It's like watching a movie played backward and learning to predict the scene that just happened. The result? This new method, called Previous-Token Prediction (PTP), can reconstruct the original starting sentence with surprising accuracy, even when the robot is a "black box" (meaning we can't see inside it). It suggests that by simply flipping the direction of how we teach the AI, we can unlock a powerful way to rewind its thoughts.

The Magic of Rewinding Time

Think of a Large Language Model (LLM) as a very chatty friend who is great at finishing your sentences. If you say, "Once upon a time," they might say, "there was a dragon." If you say, "The sky is," they might say, "blue." This friend works by looking at what you just said and guessing the next word. This is called "Next-Token Prediction." It's how they write stories, answer questions, and chat with us.

But what if you only have the friend's answer and want to know exactly what you asked? Maybe you heard a great story and want to know the exact question that started it, or perhaps you want to see if the friend is hiding a secret instruction. This is the "inversion" problem. It's hard because many different questions can lead to the same answer. If your friend says, "I love pizza," you could have asked, "What's your favorite food?" or "What do you like to eat on Fridays?" or even "Tell me about your diet."

The Old Way vs. The New Trick

Before this paper, scientists tried to solve this by either:

  1. Peeking inside the brain: Looking at the robot's internal math (logits) to reverse-engineer the question. This is like trying to solve a puzzle while wearing X-ray glasses.
  2. Using a giant reference guide: Training a separate AI on millions of question-and-answer pairs from the internet to guess the question. This is like hiring a detective who has read every book in the library.

The problem with these old ways is that they often need special access (which you don't get with a "black box" model) or huge amounts of outside data. They also tend to guess a question that means the same thing but isn't the exact same words.

The "Backwards Robot" Solution

The authors of this paper, working with models from IIT Bombay and Adobe Research, came up with a clever, self-contained solution. They didn't need X-ray glasses or a library. They just needed the robot itself.

Here is how they built their "Backwards Robot":

  1. The Setup: They took the target robot (the one they wanted to invert) and played a game with it. They fed it every single word in its vocabulary as a starting point and let it generate a short story.
  2. The Twist: They took those stories and reversed them. If the robot wrote "The cat sat," they turned it into "sat cat The."
  3. The Training: They trained a brand new, small robot (an "inverse model") from scratch using these reversed stories. This new robot learned a new skill: Previous-Token Prediction. Instead of guessing what comes next, it learned to guess what came before.
    • Analogy: Imagine learning to drive a car by only watching videos of the car driving in reverse. Eventually, you get so good at reversing that if you see a car parked, you can perfectly predict the path it took to get there.
  4. The Fine-Tuning: To make sure the robot spoke like a human, they gave it a few real examples of questions and answers (from a dataset called ShareGPT) and taught it to reverse those too.

The Results: Rewinding the Tape

When they tested this new method, the results were quite impressive. They used a model called Qwen3-0.6B and found that their "Backwards Robot" could reconstruct the original prompt (the question) with high accuracy.

  • Exact Match: About 64.77% of the time, the reconstructed prompt was exactly the same as the original. This is a big deal because previous methods often only got the meaning right, not the exact words.
  • Token F1: They scored 63.64, which is a measure of how many of the individual words matched perfectly.
  • Semantic Similarity: Even when the words weren't identical, the meaning was very close (Cosine Similarity of 86.13).

The paper also showed that this "Backwards Robot" is quite flexible. Even if they trained it on one type of robot (Qwen) and asked it to guess the prompts for a different type of robot (like LLaMA or GPT-4o), it still worked reasonably well. It wasn't perfect on the exact words (because different robots use different dictionaries), but it got the meaning right. This suggests the robot learned a general "logic" of how to reverse-engineer thoughts, not just a specific trick for one model.

Why This Matters

The paper argues that this approach is better than the old ways for a few reasons:

  • It's a "Black Box" Solution: You don't need to see the robot's internal code or weights. You just need to talk to it.
  • It's Self-Contained: It doesn't need a massive external database of questions and answers. It generates its own training data by playing with the target robot.
  • It's Faithful: Because it learns the exact reverse of the forward process, it can reconstruct the exact words, not just the general idea.

However, the authors are careful to note that this isn't a magic wand that solves everything. If the robot you are trying to invert uses a completely different set of symbols (vocabulary) or a very different brain structure, the exact word-for-word reconstruction gets harder. Also, generating the training data takes a lot of questions to ask the robot, which can be slow.

The Big Picture

In simple terms, this paper shows that if you want to know what a robot was thinking before it spoke, you don't need to break it open or hire a detective. You just need to teach a new robot to think backward. By flipping the script and training a model to predict "what came before" instead of "what comes next," the authors created a tool that can rewind the tape of AI conversations with surprising precision. It's a playful yet powerful reminder that sometimes, to understand the future, you just need to look at the past in reverse.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →