Sentence-level Privacy for Document Embeddings
Casey Meehan, Khalil Mrini, Kamalika Chaudhuri
Introduction
Language models have now become ubiquitous in NLP Devlin et al. (2019); Liu et al. (2019b); Alsentzer et al. (2019), pushing the state of the art in a variety of tasks Strubell et al. (2018); Liu et al. (2019a); Mrini et al. (2021). While language models capture meaning and various linguistic properties of text Jawahar et al. (2019); Yenicelik et al. (2020), an individual’s written text can include highly sensitive information. Even if such details are not needed or used, sensitive information has been found to be vulnerable and detectable to attacks Pan et al. (2020); Abdalla et al. (2020); Carlini et al. (2020). Reconstruction attacks Xie and Hong (2021) have even successfully broken through private learning schemes that rely on encryption-type methods Huang et al. (2020).
As of now, there is no broad agreement on what constitutes good privacy for natural language Kairouz et al. (2019). Huang et al. (2020) argue that different applications and models require different privacy definitions. Several emerging works propose to apply Metric Differential Privacy Alvim et al. (2018) at the word level Feyisetan et al. (2019); Feyisetan and Kasiviswanathan (2021); Carvalho et al. (2021); Qu et al. (2021); Yue et al. (2021); Xu et al. (2021) . They propose to add noise to word embeddings, such that they are indistinguishable from their nearest neighbours.
At the document level, however, the above definition has two areas for improvement. First, it may not offer the level of privacy desired. Having each word indistinguishable with similar words may not hide higher level concepts in the document, and may not be satisfactory for many users. Second, it may not be very interpretable or easy to communicate to end-users, since the privacy definition relies fundamentally on the choice of embedding model to determine which words are indistinguishable with a given word. This may not be clear and precise enough for end-users to grasp.
In this work, we propose a new privacy definition for documents: sentence privacy. This guarantee is both strong and interpretable: any sentence in a document must be indistinguishable with any other sentence. A document embedding is sentence-private if we can replace any single sentence in the document and have a similar probability of producing the same embedding. As such, the embedding only stores limited information unique to any given sentence. This definition is easy to communicate and strictly stronger than word-level definitions, as modifying a sentence can be changing one word.
Although this definition is strong, we are able to produce unsupervised, general embeddings of documents that are useful for downstream tasks like sentiment analysis and topic classification. To achieve this we propose a novel privacy mechanism, deepcandidate, which privately samples a high-dimensional embedding from a preselected set of candidate embeddings derived from public, non-private data. deepcandidate works by first pre-tuning a sentence encoder on public data such that semantically different document embeddings are far apart from each other. Then, we approximate each candidate’s Tukey Depth within the private documents’ sentence embeddings. Deeper candidates are the most likely to be sampled to represent the private document. We evaluate deepcandidate on three illustrative datasets, and show that these unsupervised private embeddings are useful for both sentiment analysis and topic classification as compared to baselines.
In summary, this work makes the following contributions to the language privacy literature:
A new, strong, and interpretable privacy definition that offers complete indistinguishability to each sentence in a document.
A novel, unsupervised embedding technique, deepcandidate, to generate sentence-private document embeddings.
An empirical assessment of deepcandidate, demonstrating its advantage over baselines, delivering strong privacy and utility.
Background and Related Work
We denote a ‘document’ as a sequence of sentences. Let be any finite-length sentence. Then, the space of all documents is and document is written as for any non-negative integer of sentences. In this work, we focus on cohesive documents of sentences written together like reviews or emails, but our methods and guarantees apply to any sequence of sentences, such as a collection of messages written by an individual over some period of time.
1 Differential Privacy
The above privacy notion is inspired by Differential Privacy (DP) Dwork (2006). It guarantees that — whether an individual participates (dataset ) or not (dataset ) — the probability of any output only chances by a constant factor.
Given any pair of datasets that differ only in the information of a single individual, we say that the mechanism , satisfies -DP if
Note that we take probability over the randomness of the mechanism only, not the data distribution. DP has several nice properties that make it easy to work with including closure under post-processing, an additive privacy budget (composition), and closure under group privacy guarantees (guarantees to a subset of multiple participants). See Dwork et al. 2014 for more details.
The exponential mechanism is a randomized algorithm with output distribution
2 Related Work
Previous work has demonstrated that NLP models and embeddings are vulnerable to reconstruction attacks Carlini et al. (2020); Abdalla et al. (2020); Pan et al. (2020). In response there have been various efforts to design privacy-preserving techniques and definitions across NLP tasks. A line of work focuses on how to make NLP model training satisfy DP Kerrigan et al. (2020); Bagdasaryan et al. (2019). This is distinct from our work in that it satisfies central DP – where data is first aggregated non-privately and then privacy preserving algorithms (i.e. training) are run on that data. We model this work of the local version of DP Dwork et al. (2006), wherein each individual’s data is made private before centralizing. Our definition guarantees privacy to a single document as opposed to a single individual.
A line of work more comparable to our approach makes documents locally private by generating a randomized version of a document that satisfies some formal privacy definition. As with the private embedding of our work, this generates locally private representation of a given document . The overwhelming majority of these methods satisfy an instance of Metric-DP Alvim et al. (2018) at the word level Feyisetan et al. (2019); Feyisetan and Kasiviswanathan (2021); Carvalho et al. (2021); Qu et al. (2021); Yue et al. (2021); Xu et al. (2021). As discussed in the introduction, this guarantees that a document is indistinguishable with any other document produced by swapping a single word in with a similar word. Two words are ‘similar’ if they are close in the word embeddings space (e.g. GloVe). This guarantee is strictly weaker than our proposed definition, SentDP, which offers indistinguishability to any two documents that differ in an entire sentence.
Privacy-preserving embeddings.
Sentence-level Privacy
We now introduce our simple, strong privacy definition, along with concepts we use to satisfy it.
In this work, we adopt the local notion of DP Dwork et al. (2006), wherein each individual’s data is guaranteed privacy locally before being reported and centralized. Our mechanism receives a single document from a single individual, . We require that provides indistinguishability between documents differing in one sentence.
Given any pair of documents that differ only in one sentence, we say that a mechanism satisfies -SentDP if
2 Sentence Mean Embeddings
maintains significant information unique to the document and is useful for downstream tasks like classification and sentiment analysis.
We call the document embedding since it summarizes the information in document . While there exist other definitions of document embeddings Yang et al. (2016); Thongtan and Phienthrakul (2019); Bianchi et al. (2020), we decide to use averaging as it is a simple and established embedding technique Bojanowski et al. (2017); Gupta et al. (2019); Li et al. (2020).
3 Tukey Depth
Depth is a concept in robust statistics used to describe how central a point is to a distribution. We borrow the definition proposed by Tukey (1975):
In other words, take the hyperplane orthogonal to vector , , that passes through point . Let be the probability under that a point lands on one side of and let be the probability that a point lands on the other side, so . is considered deep if is close to a half for all vectors (and thus all passing through ). The Tukey Median of distribution , , is the set of all points with maximal Tukey Depth,
We only access the distribution through a finite sample of i.i.d. points, . The Tukey Depth w.r.t. is given by
and the median, , maximizes the depth and is at most half the size of our sample \big{\lfloor}\frac{n}{2}\big{\rfloor}.
Generally, finding a point in is hard; SOTA algorithms have an exponential dependency in dimension Chan (2004), which is a non-starter when working with high-dimensional embeddings. However, there are efficient approximations which we will take advantage of.
deepcandidate
While useful and general, the document embedding does not satisfy SentDP. We now turn to describing our privacy-preserving technique, deepcandidate, which generates general, -SentDP document embeddings that preserve relevant information in , and are useful for downstream tasks. To understand the nontrivial nature of this problem, we first analyze why the simplest, straightfoward approaches are insufficient.
Our method has three pillars: (1) sampling from a candidate set of public, non-private document embeddings to represent the private document, (2) using the Tukey median to approximate the document embedding, and (3) pre-training the sentence encoder, , to produce relevant candidates with high Tukey depth for private document .
1 Taking advantage of public data: sampling from candidates
and denote the corresponding distribution over as . By selecting candidate documents that are similar in nature to the private document , we inject an advantageous inductive bias into our mechanism, which is critical to satisfy strong privacy while preserving information relevant to .
2 Approximating the document embedding: The Tukey Median
We now propose a novel mechanism , which approximates by sampling a candidate embedding from . works by concentrating probability on candidates with high Tukey Depth w.r.t. the set of sentence embeddings . We model sentences from document as i.i.d. draws from distribution . Then, is draws from , the distribution of sentences from passing through . Deep points are a good approximation of the mean under light assumptions. If belongs to the set of halfspace-symmetric distributions (including all elliptic distributions e.g. Gaussians), we know that its mean lies in the Tukey Median Zhu et al. (2020).
Formally, is an instance of the exponential mechanism (Definition 2.2), and is defined by its utility function. We set the utility of a candidate document embedding to be an approximation of its depth w.r.t. sentence embeddings ,
The approximation , which we detail in the Appendix, is necessary for computational efficiency. If the utility of is high, we call it a ‘deep candidate’ for sentence embeddings .
The more candidates sampled (higher ), the higher the probability that at least one has high depth. Without privacy, we could report the deepest candidate, . However, when preserving privacy with , increasing has diminishing returns. To see this, fix a set of sentence embeddings for document and the i.i.d. distribution over candidate embeddings . This induces a multinomial distribution over depth,
where randomness is taken over draws of .
For candidate set and sentence embeddings , the probability of ’s selected candidate, , having (approximated) depth is given by
where is the fraction of candidates in with depth w.r.t. the sentence embeddings of document , . For sufficiently large, concentrates around , so further increasing does not increase the probability of sampling a deep candidate.
For numerical intuition, suppose (as in our experiments), candidates have depth , and all other candidates have depth 0, will sample one of these deep candidates w.p. under the settings in Table 1.
For low (high privacy), about 1% of candidates need to have high depth in order to be reliably sampled. Note that this is only possible for documents with sentences. For higher , will reliably sample low depth candidates even if there are only a few.
From these remarks we draw two insights on how deepcandidate can achieve high utility. (1) More sentences A higher enables greater depth, and thus a higher probability of sampling deep candidates with privacy. We explore this effect in our experiments. (2) Tuned encoder By tuning the sentence encoder for a given domain, we can modify the distribution over document embeddings and sentence embeddings to encourage deep candidates (high probability for deep ) that are relevant to document .
3 Taking advantage of structure: cluster-preserving embeddings
4 Sampling Algorithm
The final component of deepcandidate is computing the approximate depth of a candidate for use as utility in the exponential mechanism as in Eq. (3). We use a version of the approximation algorithm proposed in Gilad-Bachrach and Burges 2012. Intuitively, our algorithm computes the one-dimensional depth of each among ’s sentence embeddings on each of random projections. The approximate depth of is then its lowest depth across the projections. We are guaranteed that . Due to space constraints, we leave the detailed description of the algorithm for the Appendix.
satisfies -Sentence Privacy
Proof follows from the fact that has bounded sensitivity (changing one sentence can only change depth of by one). We expand on this, too, in the Appendix.
Experiments
We produce private, general embeddings of documents from three English-language datasets:
Good Reads Wan and McAuley (2018) 60k book reviews from four categories: fantasy, history, romance, and childrens literature. Train-48k | Val-8k | Test-4k
20 News Groups Lang (1995) 11239 correspondences from 20 different affinity groups. Due to similarity between several groups (e.g. comp.os.ms-windows.misc and comp.sys.ibm.pc.hardware), the dataset is partitioned into nine categories. Train-6743k | Val-2247k | Test-2249k
IMDB Maas et al. (2011) 29k movie reviews from the IMDB database, each labeled as a positive or negative review. Train-23k | Val-2k | Test-4k
To evaluate utility of these unsupervised, private embeddings, we check if they are predictive of document properties. For the Good Reads and 20 News Groups datasets, we evaluate how useful the embeddings are for topic classification. For IMDB we evaluate how useful the embeddings are for sentiment analysis (positive or negative review). Our metric for performance is test-set macro score.
2 Training Details & Setup
The candidate set consists of 5k document embeddings from the training set, each containing at least 8 sentences. To train , we find clusters with -means. We train a classifier on document embeddings to predict class, where is the number of classes (topics or sentiments).
3 Baselines
We compare the performance of deepcandidate with 4 baselines: Non-private, Truncation, Word-level Metric-DP, and Random Guesser.
Non-private: This demonstrates the usefulness of non-private sentence-mean document embeddings . We generate for every document using SBERT, and then train a classifier to predict ’s label from .
Word Metric-DP (MDP): The method from Feyisetan et al. 2019 satisfies -word-level metric DP by randomizing words. We implement MDP to produce a randomized document , compute with SBERT, and predict class using .
Random Guess: To set a bottom-line, we show the theoretical performance of a random guesser only knowing the distribution of labels.
4 Results & Discussion
How does performance change with privacy parameter ? This is addressed in Figures 4(a) to 4(c). Here, we observe how the test set macro score changes with privacy parameter (a lower offers stronger privacy). Generally speaking, for local differential privacy, is taken to be a strong privacy regime, is moderate privacy, and is weak privacy. The truncation baseline mechanism does increase accuracy with increasing , but never performs much better than the random guesser. This is to be expected with high dimension embeddings, since the standard deviation of noise added increases linearly with dimension.
The word-level MDP mechanism performs significantly better than truncation, achieving relatively good performance for . There are two significant caveats, however. First, is the privacy definition: as discussed in the Introduction, for the same , word-level MDP is strictly weaker than SentDP. The second caveat is the level of at which privacy is achieved. Despite a weaker privacy definition, the MDP mechanism does not achieve competitive performance until the weak-privacy regime of . We suspect this is due to two reasons. First, is the fact that the MDP mechanism does not take advantage of contextual information in each sentence as our technique does; randomizing each word independently does not use higher level linguistic information. Second, is the fact that the MDP mechanism does not use domain-specific knowledge as our mechanism does with use of relevant candidates and domain specific sentence encodings.
In comparison, deepcandidate offers strong utility across tasks and datasets for relatively low values of , even into the strong privacy regime. Beyond , the performance of deepcandidate tends to max out, approximately 10-15% below the non-private approach. This is due to the fact that deepcandidate offers a noisy version of an approximation of the document embedding – it cannot perform any better than deterministically selecting the deepest candidate, and even this candidate may be a poor representative of . We consider this room for improvement, since there are potentially many other ways to tune and select the candidate pool such that deep candidates are nearly always good representatives of a given document .
How does performance change with the number of sentences ? This is addressed in Figures 4(d) to 4(f). We limit the test set to those documents with in the listed range on the x-axis. We set , the limit of the strong privacy regime. Neither baseline offers performance above that of the random guesser at this value of . deepcandidate produces precisely the performance we expect to see: documents with more sentences result in sampling higher quality candidates, confirming the insights of Section 4.2. Across datasets and tasks, documents with more than 10-15 sentences tend to have high quality embeddings.
Conclusions and Future Work
We introduce a strong and interpretable local privacy guarantee for documents, SentDP, along with deepcandidate, a technique that combines principles from NLP and robust statistics to generate general -SentDP embeddings. Our experiments confirm that such methods can outperform existing approaches even with with more relaxed privacy guarantees. Previous methods have argued that it is “virtually impossible” to satisfy pure local DP Feyisetan et al. (2019); Feyisetan and Kasiviswanathan (2021) at the word level while capturing linguistic semantics. Our work appears to refute this notion at least at the document level.
To follow up, we plan to explore other approaches (apart from -means) of capturing the structure of the embedding distribution to encourage better candidate selection. We also plan to experiment with decoding private embeddings back to documents by using novel candidates produced by a generative model trained on .
Acknowledgements
KC and CM would like to thank ONR under N00014-20-1-2334. KM gratefully acknowledges funding from an Amazon Research Award and Adobe Unrestricted Research Gifts. We would would also like to thank our reviewers for their insightful feedback.
References
Appendix A Appendix
We now describe in detail our instance of the exponential mechanism . Recall from Definition 2.2 that the exponential mechanism samples candidate with probability
Thus, is fully defined by its utility function, which, as listed in Equation (3), is approximate Tukey Depth,
We now describe our approximation algorithm of Tukey Depth , which is an adaptation of the general median hypothesis algorithm proposed by Gilad-Bachrach and Burges (2012).
Note that we can precompute the projections on line 10. The runtime is : for each of candidates and on each of projections, we need to compute the scalar difference with sentence embeddings. Sampling from the multinomial distribution defined by then takes time.
Additionally note from lines 13 and 15 that utility has a maximum of 0 and a minimum of , which is a semantic change from the main paper where maximum utility is and minimum is 0.
A.2 Proof of Privacy
Theorem 4.1 satisfies -Sentence Privacy
It is sufficient to show that the sensitivity,
Let us expand the above expression using the terms in Algorithm 1.
The last step follows from the fact that for all . In other words, by modifying a single sentence embedding, we can only change the number of embeddings greater than on projection by 1. So, the distance of from can only change by 1 on each projection. In the ‘worst case’, the distance \big{|}h_{j}(x,f_{i})-\frac{k}{2}\big{|} reduces by 1 on every projection . Even then, the minimum distance from across projections (the worst case depth) can only change by 1, giving us a sensitivity of 1. ∎
A.3 Experimental Details
Here, we provide an extended, detailed version of section 5.
For our non-private baseline, we demonstrate the usefulness of sentence-mean document embeddings. First, we generate the document embeddings for each training, validation, and test set document using SBERT, . We then train a classifier to predict each document’s topic or sentiment, where is the number of classes. The number of training epochs is determined with the validation set.
deepcandidate:
We first collect the candidate set by sampling 5k document embeddings from the subset of the training set containing at least 8 sentences. We run -means with cluster centers, and label each training set document embedding with its cluster. The sentence recoder, is trained on the training set along with the linear model with the Adam optimizer and cross-entropy loss. For a given document , its sentence embeddings are passed through , averaged together, and then passed to to predict ’s cluster. ’s loss is then back-propagated through . A classifier is trained in parallel using a separate instance of the Adam optimizer to predict class from the recoded embeddings, where is the number of classes (topics or sentiments). The number of training epochs is determined using the validation set. At test time, (generating private embeddings using ), the optimal number of projections is empirically chosen for each using the validation set.
Truncation:
The truncation baseline Li and Clifton (2021) requires first constraining the embedding instance space. We do so by computing the 75% median interval on each of the 768 dimensions of training document embeddings . Sentence embeddings are truncated at each dimension to lie in this box. In order to account for this distribution shift, a new classifier is trained on truncated mean embeddings to predict class. The number of epochs is determined with the validation set. At test time, a document’s sentence embeddings are truncated and averaged. We then add Laplace noise to each dimension with scale factor , where is the width of the box on that dimension (sensitivity in DP terms). Note that the standard deviation of noise added is inversely proportional to the number of sentences in the document, due to the averaging operation reducing sensitivity.
Word Metric-DP:
Our next baseline satisfies -word-level metric DP and is adopted from Feyisetan et al. (2019). The corresponding mechanism takes as input a document and returns a private version, , by randomizing each word individually. For comparison, we generate document embeddings by first randomizing the document as prescribed by Feyisetan et al. (2019), and then computing its document embedding using SBERT. At test time, we classify the word-private document embedding using .
Random Guess:
To set a bottom-line, we show the theoretical performance of a random guesser. The guesser chooses class with probability equal to the fraction of labels in the training set. The performance is then given by .
A.4 Reproducability Details
We plan to publish a repo of code used to generate the exact figures in this paper (random seeds have been set) with the final version. Since we do not train the BERT base model , our algorithms and training require relatively little computational resouces. Our system includes a single Nvidia GeForce RTX 2080 GPU and a single Intel i9 core. All of our models complete an epoch training on all datasets in less than one minute. We never do more than 20 epochs of training. All of our classifier models train (including linear model) have less than 11 million parameters. The relatively low amount of parameters is due to the fact that we freeze the underlying language model. The primary hyperparameter tuned is the number of projections . We take the argmax value on the validation set between 10 and 100 projections. We repeat this for each value of .
For all datasets, we limit ourselves to documents with at least 2 sentences.
IMDB: This dataset has pre-defined train/test splits. We use the entire training set and form the test set by randomly sampling 4,000 from the test set provided. We do this for efficiency in computing the Metric-DP baseline, which is the slowest of all algorithms performed. Since the Metric-DP baseline randomizes first, we cannot precompute the sentence embeddings – we need to compute the sentence embeddings every single time we randomize. Since we randomize for each sentence of each document at each and each over 5 trials – this takes a considerable amount of time.
Good Reads: This dataset as provided is quite large. We randomly sample 15000 documents from each of 4 classes, and split them into 12K training examples, 2K validation examples, and 1K test examples per class.
20 News Groups: We preprocess this dataset to remove all header information, which may more directly tell information about document class, and only provide the model with the sentences from the main body. We use the entire dataset, and form the Train/Val/Test splits by random sampling.