On a Utilitarian Approach to Privacy Preserving Text Generation

Differentially-private mechanisms for text generation typically add carefully calibrated noise to input words and use the nearest neighbor to the noised input as the output word. When the noise is small in magnitude, these mechanisms are susceptible to reconstruction of the original sensitive text. This is because the nearest neighbor to the noised input is likely to be the original input. To mitigate this empirical privacy risk, we propose a novel class of differentially private mechanisms that parameterizes the nearest neighbor selection criterion in traditional mechanisms. Motivated by Vickrey auction, where only the second highest price is revealed and the highest price is kept private, we balance the choice between the first and the second nearest neighbors in the proposed class of mechanisms using a tuning parameter. This parameter is selected by empirically solving a constrained optimization problem for maximizing utility, while maintaining the desired privacy guarantees. We argue that this empirical measurement framework can be used to align different mechanisms along a common benchmark for their privacy-utility tradeoff, particularly when different distance metrics are used to calibrate the amount of noise added. Our experiments on real text classification datasets show up to 50% improvement in utility compared to the existing state-of-the-art with the same empirical privacy guarantee.


Introduction
Over the past decade, privacy-preserving machine learning has emerged as a hot topic in a variety of real world speech and language applications. In natural language processing (NLP), ensuring data privacy in machine learning tasks is especially challenging because text data tends to be rich in sensitive and potentially identifiable information about the users that contributed to these datasets.
The literature is replete with approaches proposed for privacy-preserving text analysis, such as replacing sensitive information with general terms (Cumby and Ghani, 2011;Anandan et al., 2012;Sánchez and Batet, 2016), injecting additional words into original texts (Domingo-Ferrer et al., 2009;Pang et al., 2010;Sánchez et al., 2013), as well as k-anonymity and its variants (Sweeney, 2002;Machanavajjhala et al., 2007;Li et al., 2007). However, these methods are provably non-private and have been shown to be vulnerable to re-identification attacks (Korolova et al., 2009;Petit et al., 2015). To ensure a quantifiable privacy guarantee, differential privacy (DP) has become the de facto standard for privacy-preserving statistical analysis (Dwork et al., 2006;Dwork, 2008;Dwork et al., 2014), with applications to text analysis.
At a high level, a randomized algorithm is differentially private if the output distributions from any two neighboring databases are (near) indistinguishable. This indistinguishability is controlled by a privacy parameter, which, in the case of text analysis, is often scaled by the distance between neighboring datasets to capture the semantic similarity between different words (Feyisetan et al., 2019;Fernandes et al., 2019;Xu et al., 2020). This calibration enables the mechanisms to enjoy metric-DP , which was first introduced as a generalization of local DP (Kasiviswanathan et al., 2011) for protecting location privacy. Observe that a direct application of local DP mechanisms will be too restrictive because it requires that the probability ratio between the output distributions of any two words in the vocabulary be bounded by some fixed constant. Due to the high dimensional nature of textual tasks and very large vocabulary sizes (e.g. 2.2M words for GLOVE common crawl (Pennington et al., 2014)), this can lead to adding a lot of noise for achieving the desired privacy guarantees, severely impacting the utility of the NLP task. Comparing Metric-DP Mechanisms. In the context of text analysis, we are given a vocabulary set W and an embedding function φ : W → R p , where p is the dimensionality of the embedding model. For any > 0, a mechanism M : W → W is said to be differentially private with respect to a given metric d : R p × R p → [0, ∞) if for any w, w ,ŵ ∈ W, the following holds: The probabilistic guarantee in (1) ensures that the log probability ratio of observing any outputŵ given two inputs w and w is bounded by d{φ(w), φ(w )}. This makes metric-DP less restrictive in that the indistinguishability of the output distributions is scaled by the distance between the inputs. If d{φ(w), φ(w )} = 1(w = w ), then metric-DP reduces to standard DP.
Note that while metric-DP allows for a flexible privacy budget calibrated by not only but also the distance metric, this flexibility makes it harder to interpret the privacy parameter . For example, in standard DP, = 30 essentially means negligible privacy guarantee since e 30 is an astronomically large probability ratio; however, = 30 is common in the metric-DP literature (Fernandes et al., 2019;Xu et al., 2020) and still provides meaningful privacy guarantees. This is because the pairwise distance in the word embedding space can be small floating numbers, which brings exp (30d{φ(w), φ(w )}) to a reasonable scale. Thus, alone cannot fully characterize the privacy guarantee without the knowledge of the underlying metric space. More importantly, this indicates that the privacy guarantees from DP mechanisms with respect to different metrics are not directly comparable using only their values.
Our Contributions. A common feature in the existing metric-DP text generation mechanisms is to add a calibrate noise to the input word embedding and then output the nearest neighbor to the noisy embedding as the output. However, when the additive noise is small in magnitude, the input word is likely to remain unchanged, which may constitute an empirical privacy risk because it is trivial for the adversary to reconstruct the original word. To mitigate this issue, we present a novel class of metric-DP text generation mechanisms in this paper. Motivated by the Vickrey auction (Vickrey, 1961) scheme, also known as the second-price auction, we refer to this class of mechanisms as Vickrey mechanisms.
Just as in a Vickrey auction, where only the second highest price is revealed 1 and the highest price is kept private, the proposed Vickrey mechanisms generalize the noisy nearest neighbor selection by including the second nearest neighbor in the selection pool using a tuning parameter. The inclusion of the second nearest neighbor greatly reduces the empirical reconstruction risk on the original word.
To select the tuning parameter above, we present a strategy based on optimizing the empirical privacy-utility tradeoff. The empirical privacy measurement is constructed in the context of analysis on de-identified text, which quantifies the risk on how well an adversary can reconstruct the original text based on the observed (possibly perturbed) text. The better the reconstruction, the lower the empirical privacy guarantee. This general framework allows comparing text generation mechanisms that use different distance metrics (see Section 3).
We emphasize that our empirical privacy metric does not supersede the metric-DP guarantee; instead, it provides a new dimension along which different metric-DP mechanisms can be aligned. We say that, within the class of metric-DP mechanisms, an optimal mechanism is the one that maximizes the empirical privacy guarantee while keeping the utility loss of the downstream task under some maximum tolerable budget. This definition for privacyutility tradeoff, modeled as a constrained optimization problem, resembles the literature on protecting privacy for location data (Shokri et al., 2011(Shokri et al., , 2012Clark et al., 2019). We extend the analysis for the broader class of metric-DP mechanisms. Additionally, in our experiments, we demonstrate that our proposed Vickrey mechanisms outperform existing mechanisms with respect to the empirical privacyutility tradeoff on real text classification datasets.
Related Work. Metric-DP Laud et al., 2020), an extended notion of local DP (Kasiviswanathan et al., 2011), is a popular tool for privacypreserving text analysis. A text generation mechanism that satisfies DP with respect to the hyperbolic distance metric was proposed in (Feyisetan et al., 2019). This mechanism requires specialized training of word embeddings in the high-dimensional hyperbolic space. For word embeddings in the Euclidean space, like GLOVE (Pennington et al., 2014) or FASTTEXT (Bojanowski et al., 2017), mechanisms like the Laplace mechanism (L 2 met-13 ric) (Fernandes et al., 2019; and the Mahalanobis mechanism (using a regularized Mahalanobis metric) (Xu et al., 2020) have been proposed. However, a structured comparison of these different mechanisms remains unclear.
Empirical privacy measurements. A variety of empirical techniques for privacy measurement have been proposed for many different applications. In the membership inference attack literature (Shokri et al., 2017;Yeom et al., 2018;Salem et al., 2018;Song and Shmatikov, 2019), an AUC based detectability metric is commonly used to quantify the information leakage from machine learning models about their training data. However, the model trained on a given dataset can only serve as a proxy to estimate its privacy guarantee. Moreover, the detectability metric can vary across different machine learning models and implementations of the inference attack based auditors.
Hypothesis testing based approaches have also been proposed to empirically estimate (Ding et al., 2018;Gilbert and McMillan, 2018;Liu and Oh, 2019). However, the assumptions in these methods constrain their general applicability. In a recent line of work on privacy-preserving text analysis Xu et al., 2020), privacy statistics defined as (i) probability of inputs not being redacted, and (ii) number of distinct outputs given a fixed input, have been used to characterize the empirical privacy of a text generation mechanisms. While those metrics are intuitive and descriptive, there is not a direct association that relates them to the privacy leakage. Within the class of metric-DP text generation mechanisms, the corresponding definition of empirical privacy-utility tradeoff is a constrained optimization to maximize the empirical privacy while keeping the utility loss under a preset budget. This constrained setup can find its precedent in the location data privacy literature (Shokri et al., 2011(Shokri et al., , 2012Clark et al., 2019). We differ in their approach as we require the optimal mechanism to also satisfy metric-DP.

The Class of Vickrey Mechanisms
To motivate our construction of the Vickrey mechanisms, we begin by discussing the limitations of a general approach in the existing metric DP text generation mechanisms. We denote by W = {w 1 , . . . , w n } the vocabulary set containing n distinct words, and by φ : W → R p a fixed embedding function that maps each word in the vocabu-lary set to a p−dimensional real vector (referred to as the embedding for the word).
A common first step is to sample an additive noise Z from a density function p(z) ∝ exp{−d(z, 0)}, where d is the distance metric used in the mechanism 2 . For example, the Laplace mechanism uses d(x, y) = x − y 2 (also known as Euclidean or L 2 distance), and the Mahalanobis mechanism uses d(x, y) = (x − y)Σ −1 (x − y) (also known as Mahalanobis distance), where Σ is the sample covariance of the word embeddings.
Once the noise is sampled, it is then added to the input word embedding and the word with an embedding that is nearest to this noised embedding is chosen as the output: A limitation of this noisy nearest neighbor selection is that when |Z| is small (in particular, smaller than half the distance from the input word to its nearest neighbor), the first nearest neighbor to the noised embedding is the same as the original input word. The problem is exaggerated for rare words, which exist in the sparse regions of the embedding space and hence, do not get perturbed even for larger noise scales. This makes it easier for an adversary to reconstruct the original word, which may contain sensitive information (e.g. street names).
The proposed Vickrey mechanisms generalize the noisy nearest neighbor selection step by distributing the selection probability between the first and second nearest neighbor 3 using a tuning parameter t ∈ [0, 1] (see Algorithm 1). Intuitively, this generalization makes the reconstruction of the original input word harder (see Figures 1 and 2).
We capture our intuition for the claim above in Figure 1. For simplicity, the horizontal axis in both plots represents the one-dimensional embedding on a vocabulary containing only 5 words: (A, B, C, D, E). The vertical axis represents the output probability of each word through the mechanism. The plots represent the output probability in the mechanism for each of the 5 words, corresponding to the potential noised embedding values on the horizontal axis. The top plot represents the Laplace mechanism when only the first nearest neighbor Figure 1: Word probability in the Laplace mechanism (top) and the Vickrey mechanism (bottom) at 0 < t < 1 for each of the 5 words as a function of the noised onedimensional embedding. The Vickrey mechanism in this example always has two candidate words as output.
Algorithm 1: The Vickrey Mechanism to the noised embedding is feasible for selection (t = 0). In this case, all 5 curves are step functions since only the nearest neighbors are returned. The bottom plot shows the output probability for the Vickrey mechanisms, which always impart plausible deniability with another word when the noised embedding falls in any open interval.
Overview of Algorithm 1. We outline the main steps for the class of Vickrey mechanisms in Algorithm 1. For each word in the input, an additive noise Z is sampled according to the density function p(z) ∝ exp{−d(z, 0)}. Then the Vickrey mechanism will select both the first and second nearest neighbor of the noised embedding as candidates, and randomly output one of them according to probabilities calibrated by their distances to the noised embedding using a tuning parameter t. The closer t is to 1, the more the Vickrey mechanism favors the second nearest neighbor. Privacy Analysis. We formally prove that the Vickrey mechanism M t at privacy parameter > 0 enjoys metric-DP guarantee for any t ∈ [0, 1].
Theorem 1. For any t ∈ [0, 1], > 0, metric d and w, w ,ŵ ∈ W, the Vickrey mechanism M t from Algorithm 1 satisfies metric-DP: to be the set that has w i and w j as the first and second nearest neighbors. Let p w (z) be the density function for the perturbed embedding conditional on the input w: Since metric d satisfies the triangle inequality, we obtain: and ρ(w,ŵ) = Pr{M t (w) =ŵ}. Since ρ(w,ŵ) is a sum of partial probabilities in the areas wherê w is either the first or the second nearest neighbor to the noised embedding, we have: where C(w, w ) = e d{φ(w),φ(w )} , as desired.
For our experiments, we use the Euclidean distance for d so that the Vickrey mechanism reduces to the Laplace mechanism when t = 0. In general, any distance function d that satisfies the triangle inequality can be used to ensure the desired metric-DP guarantee (quantified by the parameter ).
We now discuss how to select the tuning parameter in Algorithm 1. We do this by optimizing an empirical formulation of the privacy-utility tradeoff. We discuss the details of this formulation next.

General Framework for Empirical Privacy Utility Tradeoff
Let M : W → W denote some privacy-preserving text generation mechanism (that maps words to their noised versions). Define f M (w |w) Pr{M (w) = w } to be the probability of observing w as the output of the mechanism M from the input word w. Note that this probability is conditioned on the knowledge of w. We assume a prior probability measure π : W → [0, 1], which represents the adversary's domain knowledge about the NLP task and distribution of words in the dataset under consideration. Depending on the use case, the prior distribution π can be chosen as uniform, which means the user has no information on the word distribution in the context; or π can be chosen as the empirical word distribution in the corpus on which the user wishes to perform text generation. Given this formulation, we define the expected utility loss for mechanism M as follows: where d L : W × W → [0, ∞) is a utility-specific distance metric. The utility loss can be bounded as L M < C for some bound C > 0, depending on the maximum tolerance for the underlying task.
To model the empirical privacy loss, we assume an informative adversary A that uses the prior π and has full knowledge of the text generation mechanism M and the parameter used (similar to (Shokri et al., 2011(Shokri et al., , 2012). This adversary uses the posterior probability of each word given the observed perturbed output to make its inference: Thus, from A's perspective, the expected inference error with respect to M is given by: where d E : W × W → [0, ∞) is some privacyspecific distance metric. Our goal is, therefore, Algorithm 2: Empirical Parameter Selection for the Vickrey Mechanism 1 Input: Vocabulary W, maximum utility loss C, sampler for the Vickrey mechanism M t at any privacy parameter > 0 and tuning parameter t to find a mechanism within the class of metric-DP mechanisms M that maximizes the expected inference error E M while keeping the utility loss L M below C: To compare different mechanisms, we will compare their expected inference error E M under different tolerance thresholds on the expected utility loss L M . We favor mechanisms with high E M , while maintaining L M < C.
Note that d L and d E do not have to be the same distance metrics. For instance, d L can depend on the downstream machine learning tasks, like the absolute difference in classification error, perplexity or even cross-entropy loss. From the privacy perspective, a natural choice is d E (w,ŵ) = 1(ŵ = w), which means the adversary attempts to retrieve the original word from the redacted output and considers the inference attack successful if the inferred word is the exactly same as the input word. Based on applications, the adversary can also choose d E to be the Euclidean distance such that the goal of the inference attack is to have the inferred word as close to the original word as possible.

Selecting the Tuning Parameter
We outline the main steps for optimizing the privacy parameter as well as the tuning parameter t in Algorithm 2. This optimization is with respect to the empirical privacy-utility tradeoff as laid out in (5). We initialize with the privacy parameter = 0 at some small initial value 0 and tuning parameter t = 0, so that the initial mechanism is essentially a metric-DP mechanism that implements the noisy first nearest neighbor selection. Next, we incrementally double the value of until the expected utility loss L M t < C (recall that a smaller typically has larger utility loss 4 ). Once the maximum is obtained, we iterate over different values of t between 0 and 1 (since a monotonicity assumption cannot be made here in general for the behavior of E M ). The final parameters opt and t opt chosen provide the highest empirical privacy while keeping the utility loss within the specified budget. More importantly, Theorem 1 ensures that the selected mechanism enjoys at least as much metric DP as the initial mechanism, which implements only the nearest neighbor selection.

Experimental Results
Setup. We evaluate the performance of the proposed Vickrey mechanisms in terms of the empirical privacy-utility tradeoff on three datasets: • The Product Reviews dataset consists of a list of 2,006 positive sentiment words and 4,783 negative sentiment words extracted from customer reviews (Hu and Liu, 2004). This is a word-level dataset and the metric d L in expected utility loss is 1{sentiment(w ) = sentiment(w)}, i.e., the loss is incremented when a positive sentiment word is redacted into a negative sentiment word, or vice versa.
• The IMDb Movie Reviews dataset (Maas et al., 2011) has a total vocabulary size of 145,901, where a pre-specified set of 26,078 words are subject to redaction in the text generation mechanism (those are the words selected for adversarial model training in (Jia et al., 2019)). The utility task is the sentence-level binary sentiment classification, where the underlying model is a bidirectional LSTM using 90% of the data for training and 10% for testing.
• The Twitter dataset contains 7,613 tweets, with a vocabulary of 22,013 words 5 . Each tweet is associated with a label indicating whether the tweet describes a disaster event or not. The classification model is a bidirectional LSTM using 9:1 data split for training/testing.
For all three datasets, we consider both 300dimensional GLOVE embeddings (Pennington 4 An implicit assumption we make in Algorithm 2 is that LM increases monotonically with , following the intuition that a larger noise scale leads to larger utility loss. We defer the discussion around relaxing this assumption to future work. 5 https://www.kaggle.com/c/ nlp-getting-started et al., 2014) and 300-d FASTTEXT embeddings (Bojanowski et al., 2017). The empirical privacy measurement uses the adversary's expected inference error rate, i.e. d E (ŵ, w) = 1(ŵ = w). The utility-specific metric d L is chosen to be the misclassification error rate. The prior word distribution is chosen to be the empirical word distribution in the dataset, because we want to assume an informative adversary so as not to underestimate the privacy risk. In the Vickrey mechanism, the distance function is the Euclidean distance, so that t = 0 is equivalent to the Laplace mechanism . We also compare our results with the Mahalanobis mechanism (Xu et al., 2020).
Results and Observations. In Figure 2(A) -2(D) shows the empirical privacy-utility tradeoff on the Product Reviews between the Laplace mechanism, Mahalanobis mechanism, and the Vickrey mechanisms with tuning parameter at to 0.25, 0.5, 0.75, and 1. The vertical axis in all plots represents the adversary's inference error in the mechanism. The error bars are computed over 100 runs. In the 2(A), the horizontal axis is the privacy budget . When approaches 0, the inference error in all mechanisms approach 1, which is expected because magnitude of the additive noise is large. When increases, the inference error drops, but the drop in Laplace mechanism is much faster than the other mechanisms. It is worth noticing that the curves for Laplace mechanism and the Vickrey mechanisms are mostly parallel with each other: when t increases from 0 to 0.75, a higher value of t is better in terms of empirical privacy at the same ; but when t increases to 1, the empirical privacy will not further increase since the randomness in noisy selection between the first and second nearest neighbor is replaced by the deterministic selection of the second nearest neighbor, which makes the adversary's inference attack easier by finding the second nearest neighbor. However, Vickrey mechanism at t = 1 still dominates Laplace mechanism which only selects the noisy first nearest neighbor for redaction. The slope for the Mahalanobis mechanism is different from the rest, where intersects with Vickrey mechanisms with different t at different . At = 100, the baseline Laplace mechanism has negligible inference error, which means the adversary can almost always make correct guesses, whereas in the other mechanisms the error is still substantial. Figure 2(B) plots inference error vs. misclassi- fication error of words (positive words to negative words, or vice versa). When vertically slicing the plot, we see that for each utility loss budget greater than 0.1, a larger value of t will result in a better privacy guarantee. When capped at a maximum = 100, the curves with a higher t value will have a higher minimum feasible misclassification error, which is around around 0.02 for t = 0.25 and Mahalanobis, about 0.04 for t = 0.5, about 0.06 for t = 0.75, and about 0.1 for t = 1. This is expected because as more weight is put on the second nearest neighbor, the utility loss becomes larger at large values (small noise), because it is more likely that the original word will get changed to its neighbors. But this loss is upper bounded by the nearest neighbor replacement, which tends to be small as is shown in the experiments in the paper. The plot suggests that if the user has a maximum utility loss budget of 0.06, they should go with the Vickrey mechanism at t = 0.75 because when slicing vertically at misclassification error of 0.06, the green curve for t = 0.75 attains a higher empirical privacy than the other mechanisms. However, when the utility loss budget is 0.02, the user should choose t = 0.25 because the green line is on top of the other curves (red and black) that can achieve the utility loss of 0.02 (the blue, cyan, and purple curves cannot achieve utility loss within 0.02 when is capped at 100). Figure 2(C) and 2(D) on Product Reviews using 300-d FASTTEXT embedding show similar patterns as those in 2(A) and 2(B) in terms of the privacy-utility tradeoff.
The results and interpretations are qualitative similar in Figure 2(E) -2(H) on IMDb Movie Reviews and in Figure 2(I) -2(L) on Twitter. In empirical privacy vs plots, the Laplace mechanism consistently has a lower value of empirical privacy measure than the Vickrey mechanism and the Mahalanobis mechanism. This gap in adversary's inference error becomes wider as increases. In the privacy vs utility loss plots, the difference between mechanisms is more significant on Twitter than on IMDb reviews. The patterns are consistent across plots, which both show that the Vickrey mechanism can improve the privacy-utility tradeoff beyond the baseline mechanism.
The difference in the result between GLOVE and FASTTEXT, particularly in 2(E) vs. 2(G) and 2(I) vs. 2(K), is due to the difference in inter-word distance distributions between the two embedding spaces (see Figure 1 in ). In particular, the inter-word distances are generally smaller in FASTTEXT than in GLOVE, so that for a fixed noise scale , the inference error is expected to be larger in FASTTEXT than in GLOVE.

Generalizing Vickrey Mechanism
Beyond the Second Nearest Neighbor By a random selection of both the first and the second nearest neighbor to the noised embedding, we have shown that the Vickrey mechanism can empirically improve the privacy-utility tradeoff upon the existing Laplace and Mahalanobis mechanisms. A natural generalization is to extend the selection to k ≥ 2 nearest neighbors (see Algorithm 3). Algorithm 3 presents the outline of the generalized Vickrey mechanism that randomly chooses among the noisy k nearest neighbors as output, where the selection probability is inversely associated with their distance to the noised embedding. Similar to Algorithm 2, the tuning parameters are selected as to optimize for the empirical privacyutility tradeoff, but the selection process will be more challenging because the optimization space is unbounded. We defer the details of this optimization to future work. However, we formally state in Theorem 2 the metric-DP guarantee from the generalized Vickrey mechanism in Algorithm 2. Due to space constraints, we defer the details of Setŵi ←wir with prob. pr(t 1,...,k ,φi), where pr(t 1,...,k ,φi) = exp{−tr φ(w ir −φ i 2 } j exp{−t j φ(w ij −φ i 2 } for all r ∈ [k]. 7 returns =ŵ1ŵ2 . . .ŵn. the proof since it is similar to that for Theorem 1. Theorem 2. For any t = [t 1 , . . . , t k ] ∈ [0, ∞) k , k ∈ Z + , > 0 and w, w ,ŵ ∈ W, the generalized Vickrey mechanism M t from Algorithm 3 satisfies metric-DP for any metric d.
In Figure 3 , we compare 5 generalizations of the Vickrey mechanism that deterministically select the noisy 1 st , . . . , 5 th neighbors as the output on the Product Reviews data using both 300-d GLOVE and 300-d FASTTEXT. We can see that the improvement is most significant between the 1 st and 2 nd nearest neighbor. It also shows that there is benefit in introducing the 3 rd nearest neighbor into the selection pool, while no big difference is found beyond the 3 rd neighbor.

Discussion and Conclusion
In this paper, we present a measurement framework to quantify the empirical privacy-utility tradeoff for metric-DP text generation mechanisms, where the empirical privacy metric is the reconstruction risk of the original text based on the redacted text. We adopt a constrained optimization setup, where within the class of metric-DP mechanisms, we maximize the empirical privacy guarantee while keeping the machine learning utility loss under a prespecified tolerance. A novel class of Vickrey mechanism is proposed, which not only enjoys metric-DP but also optimizes the privacy-utility tradeoff within the constraint. We apply our methodology to the three text classification datasets and demonstrate how to empirically compare the privacyutility tradeoff as well as how to choose the optimal parameter setting according to the constrained optimization. Our results show superior performance when compared to existing mechanisms.
Our analysis in this paper leaves ample room for further investigation. An ongoing work we are exploring is the inclusion of contextual information into the probability calibration between the two nearest neighbors. We leave it as an interesting open problem to explore how the choice of k th neighbor impacts the tradeoff in this scenario, since contextual signals will likely restrict the set of candidate words we can choose from.