Abstract
In-context learning (ICL) is an important capability of Large Language Models (LLMs), enabling these models to dynamically adapt based on specific, in-context exemplars, thereby improving accuracy and relevance. However, LLM's responses may leak the sensitive private information contained in in-context exemplars. To address this challenge, we propose Differentially Private In-context Learning (DP-ICL), a general paradigm for privatizing ICL tasks. The key idea for the DP-ICL paradigm is generating differentially private responses through a noisy consensus among an ensemble of LLM's responses based on disjoint exemplar sets. Based on the general paradigm of DP-ICL, we instantiate several techniques showing how to privatize ICL for text classification and language generation. We evaluate DP-ICL on four text classification benchmarks and two language generation tasks, and our empirical results show that DP-ICL achieves a strong utility-privacy tradeoff.
Introduction and Problem Statement
In-context learning (ICL) has become the primary method for adapting Large Language Models (LLMs) to specific tasks by providing a few "exemplars" (input-output pairs) within the prompt. While effective, this approach poses significant privacy risks when exemplars contain sensitive data, such as medical records or private communications. Malicious users can craft "prompt injection" attacks to trick the model into leaking these private exemplars, bypassing instructions to keep information confidential.
Traditional privacy-preserving methods like DP-SGD (Differentially Private Stochastic Gradient Descent) are often impractical for LLMs because they require massive computational resources, access to model weights (which is unavailable for black-box APIs like GPT-4), and make it difficult to implement the "right to be forgotten." This research introduces DP-ICL, a framework that provides formal differential privacy (DP) guarantees for ICL while remaining compatible with any LLM API.
The DP-ICL Methodology
The DP-ICL framework utilizes a "sample-and-aggregate" paradigm to ensure that no single private exemplar can significantly influence the final output. The process follows four main phases:
- Subsample and Partition: The private dataset is split into $n$ disjoint subsets (ensembles) using Poisson subsampling to amplify privacy.
- Pairing with Query: The user's query is paired with each subset to create multiple distinct prompts.
- Ensemble Inference: Each prompt is sent to the LLM independently, generating a collection of diverse responses.
- Private Aggregation: The responses are combined using DP noise to produce a single, privacy-preserving answer.
Specialized Aggregation Techniques
To handle various task types, the authors propose specific mechanisms:
- Text Classification: Uses a "Private Voting" mechanism (Report-Noisy-Max) where the model counts votes for each class across the ensemble and adds Gaussian noise before selecting the winner.
- Language Generation: To aggregate high-dimensional text, the authors propose Embedding Space Aggregation (ESA), which computes a DP-mean of semantic embeddings, and Keyword Space Aggregation (KSA), which privately identifies common keywords to guide the final response reconstruction.
Experimental Setup and Results
The framework was evaluated on classification benchmarks (SST-2, Amazon, AGNews, TREC) and generative tasks (PFL-DocVQA, SAMsum) using OpenAI's GPT-3 family and OpenLLaMA-13B.
- Competitive Accuracy: On SST-2, DP-ICL achieved 95.8% accuracy at $\epsilon=3$, matching non-private performance and outperforming state-of-the-art DP-SGD fine-tuning by 1.2%.
- Generative Success: For dialogue summarization (SAMsum), ROUGE scores dropped by only ~1% even under strict privacy constraints ($\epsilon=1$).
- Scaling Benefits: Utility-privacy tradeoffs improve significantly as the underlying LLM becomes more capable (e.g., moving from Babbage to Davinci).
Discussion and Conclusion
DP-ICL offers a robust solution for private LLM adaptation. Its black-box compatibility allows it to work with proprietary APIs, and it inherently supports the "right to be forgotten"—removing a user's data simply requires deleting their exemplar from the database without retraining. While the ensemble approach increases inference costs and latency, the strong utility-privacy tradeoff makes DP-ICL a promising path for deploying LLMs in sensitive domains.
Summary updated