Research
An Invariant Latent Space Perspective on Language Model Inversion
An Invariant Latent Space Perspective on Language Model Inversion Overview Research area: AI security and privacy, specifically language model inversion (LMI) — recovering hidden prompts from the text
- arXiv
- 2511.19569
- Published
- 2025-11-24
- Authors
- Wentao Ye, Jiaqi Hu, Haobo Wang, Xinpeng Ti, Zhiqing Xiao, Hao Chen, Liyao Li, Lei Feng, Sai Wu, Junbo Zhao
AI summary
An Invariant Latent Space Perspective on Language Model InversionOverview
Research area: AI security and privacy, specifically language model inversion (LMI) — recovering hidden prompts from the textual outputs of large language models.
Technical level: Advanced. The paper assumes familiarity with transformer latent spaces, contrastive learning (InfoNCE), and prompt-inversion threat models.
Scope (one sentence): The paper proposes the Invariant Latent Space Hypothesis (ILSH) and builds Inv²A, a framework that reuses a frozen LLM as an "invariant decoder" alongside a lightweight trainable "inverse encoder" to recover user and system prompts from outputs, tested across 9 datasets and multiple forward LLMs.
What This Paper Is About
Language model inversion is the problem of reconstructing the prompt that produced an LLM's output. Existing methods (Logit2text, Output2prompt) train an external inverse model on millions of output–prompt pairs, which is data-hungry and generalizes poorly out of distribution.
This paper argues that the LLM's own latent space already contains an inverse mapping coupled to its forward mapping, and that inversion can therefore be achieved by learning a small encoder that projects outputs back into that space rather than teaching an external model the mapping from scratch.
Key Contributions
-
The Invariant Latent Space Hypothesis (ILSH). Two properties are proposed and empirically tested: source invariance (outputs sampled from the same prompt should preserve consistent semantics in the latent space) and cyclic invariance (the cycle X → Z → Y → Z → X should be self-consistent, so an inverse mapping Y → Z → X exists within the same latent space Z). Sufficiency is probed with 2,000 random Alpaca prompts sampled with GPT-2, and necessity is probed by SFT-training GPT-2 with outputs as prompts and prompts as labels.
-
The Inv²A framework (Invariant Inverse Attacker). An asymmetric round-trip decoder: a trainable inverse encoder (T5 encoder plus a linear projection) maps one or more outputs into a denoised pseudo-representation c, and the frozen forward LLM f decodes c into the recovered prompt. The LLM's embedding layer is excluded because the decoder input is a vector, not text.
-
Semi-sparse encoding for multiple outputs. Instead of concatenating all outputs (attention cost O(N²l²)), Inv²A encodes each output separately and concatenates the hidden states, reducing encoding complexity to O(Nl²), motivated by the finding that cross-attention between different outputs brings little performance gain.
-
A two-phase training recipe plus an optional training-free refinement. Alignment (source-aware contrastive learning with InfoNCE) followed by reinforcement (supervised inverse-pair learning with a 20% local warm-up of the projection layer, then joint fine-tuning on the remaining 80%), with an optional dynamic filter that performs iterative Monte Carlo neighborhood search when the model probability P falls below a threshold τ.
Main Findings
-
State-of-the-art inversion across scenarios. Inv²A achieves the best result on every reported metric in both the user prompt and system prompt scenarios, with an average absolute BLEU improvement of 4.77% over baselines. On the user prompt average of 8 datasets with LLaMA2-7B-Chat as the forward LLM, it scores 41.78 BLEU, 65.89 Token F1, 82.11 CS, 74.46 GPT, and 10.43 Exact, versus 35.34 BLEU for the best baseline, Output2prompt.
-
Naive round-trip decoding fails. Feeding outputs directly back into the forward LLM achieves only a BLEU score of 4.75, which the authors attribute to implicit source invariance and weak cyclic invariance; the inverse encoder's denoised pseudo-representation compensates for this.
-
Semantic recovery is stronger than surface-level recovery. Inv²A gains more on CS and GPT (semantic metrics) than on BLEU and Exact (surface-level metrics), indicating high semantic-fidelity reconstruction with room for improvement on fine-grained token recovery.
-
~80% data reduction. Inv²A reaches comparable performance with only 20 to 30% of the training data, as measured by varying both the number of prompts and the number of sampling rounds per prompt. It also trains fewer parameters than baselines, which mostly train a full T5 including the decoder.
-
Transferability across models and domains. Without additional fine-tuning, the encoder trained in the user prompt scenario transfers to Qwen2-7B, LLaMA3.2-3B, LLaMA3-8B, and LLaMA2-13B. On the out-of-domain Anthropic HH dataset, methods using the forward LLM itself or GPT-4o as the inverse model outperform T5, suggesting a well-generalized backbone matters when output patterns diverge from training.
-
Robustness to output perturbation. Inv²A maintains its gains under synonym replacement and across temperatures 0.5, 1.0, and 2.0, though absolute performance degrades severely at temperature above 2.0. For prompt length, BLEU trends downward as length grows; Output2prompt occasionally overtakes at around 120 words, a range containing only 0.4% of prompts.
-
Ablations confirm each component. Removing the encoder drops BLEU to 1.31 (versus 26.47 when LoRA fine-tunes the decoder instead), and the ablation baseline of Inv²A in Table 4 is 35.20 BLEU. Replacing the raw decoder with Qwen2 gives 33.38 BLEU; removing contrastive learning gives 33.91; adding the dynamic filter gives 35.97, with a second refinement turn at 36.06. Only about 15% of samples trigger the filter.
-
Interpretability: attention is redistributed. Token-wise attention analysis shows the encoder raises attention on tokens carrying key semantic information. Across all samples, the average ratio of shared-token attention to the sequence mean rises from 1.46 to 1.70.
-
Defenses are weak or costly. Diversity-based defenses have little effect because Inv²A's leverage is the invariant decoder. Layer-wise Gaussian noise injection is more effective than diversity-based defenses, but injecting into the MLP with λ = 2.5e-2 still causes an approximately 8% drop in forward BLEU.
Methodology in Plain English
The researchers start from an observation about how LLMs are structured: the model already has a rich internal "latent space" that maps prompts to outputs, so the machinery to go the other direction may already be inside it. To test this, they perturb outputs (synonym replacement, random word swaps, random noise) and measure whether inversion quality collapses, and they train a model to invert and check whether forward behavior improves as a side effect.
Building on that, their system works in three moves. First, a small trainable encoder reads the observed output (or several outputs, each encoded separately and concatenated) and produces a single vector — a "clean anchor" — that lives in the same space the LLM uses internally. Second, the original LLM, with its embedding layer removed and its weights frozen, decodes that vector into a guessed prompt. Third, because different samples from the same prompt should map to similar anchors, they add a contrastive phase that pulls together representations from outputs of the same prompt and pushes apart those from different prompts, then a supervised phase that directly rewards guessing the right prompt.
They also add an optional, training-free cleanup step: if the model's confidence is below a threshold, they ask the LLM to rewrite the output into semantically equivalent variants, and pick the variant whose recovered prompt best explains the original output, repeating this search for one or two rounds.
Evaluation uses LLaMA2-7B-Chat as the main forward LLM and a T5-base encoder, trained on 8 A800 GPUs with 80G memory (3 hours per model), with greedy decoding after training.
Why This Matters
Research impact. The paper reframes prompt inversion from "train an external inverse model" to "activate an inverse mapping that already exists," which is a different starting point for the inversion literature and for defenses. It also reports that prevalent defenses offer limited protection, and that a defense which does work (layer-wise noise injection) costs roughly 8% forward BLEU at λ = 2.5e-2.
Real-world applications and threat surfaces:
- Distributed inference systems: the final client in the pipeline sees a single output generated from a hidden user prompt, and if the model is open-source its weights are visible to every participating client.
- LLM-powered web services: a user can append queries to a hidden system prompt, collect multiple outputs, and recover developer- or application-provided instructions. On the Synthetic GPTs dataset, Inv²A reaches 92.78 CS and 94.20 GPT in this setting.
- Protected data assets embedded in prompts: the paper lists proprietary training data (e.g., tabular database questions, algorithm prompts, chain-of-thought prompts), user privacy data (e.g., fitness tracking, search history, shopping habits, customer databases), and copyright-related content (e.g., continuing a book series, recreating song lyrics, generating a plot summary with dialogue).
- Prompts engineered to induce specific model behaviors: system prompts that trigger special capabilities or abnormal outputs.
Industry relevance. Any organization deploying LLMs through a web interface with a confidential system prompt, or running distributed/federated inference across clients, is directly in the threat model. The paper's code and data are released at https://github.com/yyy01/Invariant_Attacker.
Future Directions
-
Scalable defenses that preserve utility. The paper calls this "a challenging open problem requiring community effort," since layer-wise noise injection degrades forward performance and differential privacy is impractical for already-released models due to retraining cost and limited controllability.
-
Extending beyond white-box access. Inv²A assumes full access to model parameters; applicability in strict black-box contexts remains limited.
-
Handling abstract or many-to-one prompts. When prompts are too abstract, or when multiple prompts map to identical outputs (the paper's example: "3-1" and "1+1" both yielding "2"), the invariant latent space becomes harder to interpret and reconstruction accuracy drops.
-
Improving fine-grained recovery. The gap between strong semantic metrics (CS, GPT) and weaker surface-level metrics (BLEU, Exact) points to remaining work on precise token-level reconstruction, and on long, complex system prompts that specify role, tone, and knowledge scope.
Target Audience
This paper is most useful to AI security and privacy researchers working on prompt leakage and model inversion; to LLM service operators and platform engineers who embed confidential system prompts or run distributed inference; to privacy and compliance practitioners evaluating whether hidden prompts constitute protectable assets; and to defense-oriented researchers looking for baselines that current protections fail to stop. Readers without background in transformer latent spaces and contrastive learning will find the method sections demanding, though the threat model and experimental tables are accessible.
Authors’ abstract
Language model inversion (LMI), i.e., recovering hidden prompts from outputs, emerges as a concrete threat to user privacy and system security. We recast LMI as reusing the LLM's own latent space and propose the Invariant Latent Space Hypothesis (ILSH): (1) diverse outputs from the same source prompt should preserve consistent semantics (source invariance), and (2) input<->output cyclic mappings should be self-consistent within a shared latent space (cyclic invariance). Accordingly, we present Inv^2A, which treats the LLM as an invariant decoder and learns only a lightweight inverse encoder that maps outputs to a denoised pseudo-representation. When multiple outputs are available, they are sparsely concatenated at the representation layer to increase information density. Training proceeds in two stages: contrastive alignment (source invariance) and supervised reinforcement (cyclic invariance). An optional training-free neighborhood search can refine local performance. Across 9 datasets covering user and system prompt scenarios, Inv^2A outperforms baselines by an average of 4.77% BLEU score while reducing dependence on large inverse corpora. Our analysis further shows that prevalent defenses provide limited protection, underscoring the need for stronger strategies. The source code and data involved in this paper can be found in https://github.com/yyy01/Invariant_Attacker.