Recovering Private Text in Federated Learning of Language Models

Samyak Gupta, Yangsibo Huang, Zexuan Zhong, Tianyu Gao, Kai Li, Danqi Chen

Abstract

Federated Learning (FL) is widely regarded as a privacy-preserving paradigm because it allows models to be trained on decentralized data without requiring raw data to leave local devices. However, recent research into gradient inversion suggests that private information may still be leaked through shared model updates. This paper presents FILM (Federated Inversion Attack for Language Models), a novel attack framework capable of reconstructing private text from gradients even in large-batch settings of up to 128 sentences. We further demonstrate that the primary vulnerability lies in the word embedding layer and propose a simple, effective defense: freezing word embeddings during fine-tuning.

1. Introduction

In Federated Learning, clients compute gradients on local datasets and transmit these updates to a central server. While this avoids direct data sharing, the security of the process relies on the assumption that gradients do not contain enough information to reconstruct the original input. While gradient inversion has been successfully demonstrated in the image domain, text remains a significant challenge due to its discrete nature and the noise introduced by averaging gradients across large batches.

Existing attacks often fail when the batch size exceeds a single sentence. FILM addresses these limitations by leveraging the prior knowledge of pre-trained language models (LMs) to navigate the discrete search space of text, successfully recovering high-fidelity sequences from complex, multi-sentence updates.

2. The FILM Attack Framework

FILM departs from traditional continuous optimization methods used in image recovery. Instead, it employs a three-stage pipeline designed to handle the discrete properties of language:

  1. Bag-of-Words (BoW) Extraction: The attack first identifies the set of tokens present in a batch by analyzing the gradients of the word embedding layer. A non-zero gradient for a specific token typically indicates its presence in the training batch.
  2. Beam Search for Reconstruction: Using the extracted bag of words, FILM utilizes a beam search algorithm to find the most probable sequences. This process is guided by the prior knowledge of a pre-trained LM (e.g., GPT-2), allowing the attacker to reconstruct coherent sentences even when the gradient signal is weak.
  3. Prior-Guided Token Reordering: To refine the output, FILM uses a scoring function that balances perplexity (linguistic fluency) and gradient matching (how well the candidate matches the observed updates). The attack performs iterative phrase-level and token-level swaps to maximize this score, significantly improving reconstruction fidelity.

3. Experimental Evaluation

3.1 Datasets and Setup

The framework was evaluated using the WikiText-103 dataset for general language modeling and the Enron Email Dataset to simulate real-world privacy risks involving sensitive personal information. Experiments were conducted using a GPT-2 model (117M parameters).

3.2 Performance and Scalability

FILM demonstrates unprecedented scalability in text recovery. While previous state-of-the-art methods like DLG or TAG often fail beyond a batch size of 1, FILM successfully reconstructs text from batches as large as 128 sentences.

At a batch size of 1, the attack achieves near-perfect recovery with ROUGE-L scores approaching 1.0. As the batch size increases to 16 and beyond, FILM continues to recover significant portions of the original text, outperforming baselines across ROUGE scores and the Named Entity Recovery Ratio (NERR).

4. Discussion: Memorization and Defense

4.1 The Role of Memorization

A key insight of this research is that the inherent power of LMs—their ability to memorize patterns—is also a primary security vulnerability. FILM shows that as a model is fine-tuned, it increasingly "remembers" private data. This memory is reflected in the gradients, making the model more susceptible to inversion attacks over time.

4.2 Freezing Embeddings as a Defense

The authors identify the Bag-of-Words extraction from the embedding layer as the critical bottleneck for the attack. By freezing word embeddings—keeping them static while only fine-tuning the transformer layers—the attacker is prevented from identifying the tokens used in the batch.

Experimental results show this defense is highly effective. While traditional defenses like Differential Privacy (DPSGD) or gradient pruning often significantly degrade model utility, freezing embeddings maintained a perplexity of 11.48 (compared to 11.40 for the unfrozen baseline) while effectively reducing the attacker's recovery capability to zero.

5. Conclusion

FILM demonstrates that Federated Learning of language models is more vulnerable to gradient inversion than previously thought, particularly when models memorize sensitive training data. However, the discovery that the embedding layer is the primary leak point offers a practical path forward. Freezing embeddings provides a low-cost, high-utility defense that can protect private text without the heavy performance penalties associated with traditional privacy-preserving techniques.

Summary updated

BibTeX
@inproceedings{gupta2022recovering,
  author = {Samyak Gupta and Yangsibo Huang and Zexuan Zhong and Tianyu Gao and Kai Li and Danqi Chen},
  title = {{Recovering Private Text in Federated Learning of Language Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=dqgzfhHd2-},
}
Figure