D ISTRIBUTED F INE - TUNING OF L ANGUAGE M ODELS ON P RIVATE D ATA
Anonymous authors
Paper under double-blind review
A BSTRACT
One of the big challenges in machine learning applications is that training data can be different from the real-world data faced by the algorithm.
In language modeling, the language of users (e.g. in private messaging) could change in a year and be completely different from what we observe in publicly available data.
At the same time, public data can be used for obtaining general knowledge (i.e. general model of English).
We study approaches to distributed ﬁne-tuning of a general model on user private data with the additional requirement of maintaining the quality on the general data.
Our experiments demonstrate that a technique based on model averaging and random rehearsal outperforms an approach based on transfer learning, and show that the proposed method improves prediction quality in a reasonable time.
The procedure leads to an almost 70% perplexity reduction and 8 . 7 percentage point improvement in keystroke saving rate on informal English texts compared to a basic model trained on Wikipedia.
We also propose an experimental framework for evaluating differential privacy of distributed training of language models and show that our approach has good privacy guarantees.
I NTRODUCTION
Two common problems arising after deployment of a machine learning model on user devices are discrepancy between training data and actual data stored on user devices, and the need of regular model updates.
In the case of language modeling, it corresponds to the difference between language and style of the training corpus mined in the Internet and messages of the user, which account for most of the text generated on the device.
Even if the training corpus includes a substantial part of informal texts (tweets, forum threads, etc.), real user data can be very different.
This is a challenge for word prediction algorithms in software keyboard applications.
The most general approach to improvement of customer experience in typing is integrating a separate user language model trained on device in an on-line fashion.
In the simplest case it is a smoothed n-gram (e.g. Kneser-Ney n-gram model (Goodman (2001))).
In Yoon et al.
(2017) continuously learned personalized language model based on LSTM was proposed but as far as each user generates only a small portion of textual data, such data by itself cannot be used for updates of the general model.
Thus, for a model update, a collection of potentially sensitive data from many users is needed.
As shown in McMahan et al.
(2016), collecting data for training may be avoided.
We propose a similar approach for distributed ﬁne-tuning of language models on private data.
In this sense our method can be considered as “federated ﬁne-tuning“ but we prefer to take more traditional term.
In this setting we start with a language model trained on a large text corpus representing the general language.
This model G will be updated continuously on user devices but with an additional requirement that the model must not go too far from the general language model, i.e. we don’t overﬁt on user data.
We pursue two goals: 1) to develop an algorithm of distributed ﬁne-tuning without need to collect sensitive user data; and 2) to prevent the language model from forgetting “general English“.
Besides, we provide analysis of possibility of privacy violation in our model.
(Hitaj et al.
(2017)) demonstrated an attack on distributed training algorithm leading to information leakage.
This means that privacy analysis in necessary for such algorithms.
Our main contributions are: 1) we propose an efﬁcient procedure of distributed ﬁne-tuning of language models immune to the problem of catastrophic forgetting (French (1999)), 2) we provide experimental evaluation of on-device training time and convergence rates of the general language model in realistic conditions, and 3) we propose an experimental framework for evaluation of differential privacy of distributed training of language models, and using this framework, we evaluate privacy guarantees of our approach.
In our research we are focused on improvement of keystroke saving rate (see section 2.4) because this metric reﬂects customer typing experience more directly than perplexity or BLEU.
We use
LSTM architecture for our language model as described in Zaremba et al.
and evaluate ondevice training time for this architecture.
We show that the on-device training time is reasonably small, thus demonstrating the feasibility of the whole approach.
D ISTRIBUTED FINE - TUNING OF LANGUAGE MODELS
As usual, our task is to predict the next word w N given a sequence of words w 1 . . .
w N − 1 .
If the prediction algorithm of a software keyboard application is based on a language model with low perplexity on the test data, the application provides a reasonably sorted list of input candidates.
Of course, the test data should be drawn from the same distribution as the user data.
In our case we also want to have only one, continuously improving model on a user device.
As far as the user can always switch to the general English, we have to prevent the model from overﬁtting on the texts written on the device, or catastrophic forgetting ( McCloskey & Cohen (1989); Goodfellow et al.
(2014); Kirkpatrick et al.
Our approach can be summarized as follows: 0)
At the ﬁrst stage we have an initial language model
G 0 trained on a large corpus of standard English; 1) As soon as a user inputs sufﬁcient volume of text, the latest version of G t is sent from the server to provide synchronous updates, and ﬁne-tuning starts on the device (some amount of text should be accumulated on the device); 2) When the training is ﬁnished the model ¯
G it is sent back to the server; 3)
Every time the updated models ¯ G it are received from K different users, one round of model update is run; 4) After N rounds, the new model G t + is deployed to devices.
2. L EARNING WITHOUT FORGETTING
In its original formulation (Li & Hoiem (2016)), the problem of learning without forgetting (LwF) consists in re-training of existing model Θ on new data such that its performance on the old data does not degrade.
More formally, suppose we have a classiﬁer with a set of parameters Θ trained and tested on a dataset D
= { Tr , Ts } where Tr and Ts are train and test sets accordingly.
Let D ∗ =
{ Tr ∗ , Ts ∗ } be some new dataset.
Our goal is to update the parameters Θ with dataset D (cid:48)
= { Tr ∗ ,
Ts ∪ Ts ∗ } i.e. we have to provide the best performance on old and new types of data having only training data of the new type.
In contrast, joint training Caruana (1997) assumes a model update with access to the both datasets:
[Equation]
As we want to avoid sending user data to the server, classical joint training is impossible.
On the other hand, LwF seems promising.
In this case we send the user a current instance of the general language model G t with weights θ g and ﬁne-tune it producing the model θ u , while θ g is used for generating predictions for regularization.
The resulting loss at step t and true word w t can be calculated as follows:
[Equation]
where
[Equation]
A similar approach is taken in Shin et al.
(2016) where predictions of a basic model (in this case θ g ) are taken as soft labels .
2. T RAINING WITH REHEARSAL
Minimizing loss in (1)–(2) is equivalent to minimizing Kullback-Leibler divergence L ( θ u ) =
KL ( P gr (cid:107) P u ) with respect to parameters θ u of P u where density of P gr is given by:
[Equation]
In (3) P
Tr ∗ ( x ) stands for the real distribution on a user device and P ( x | θ g ) is a probability given by the model of “general English“ θ g .
It suggests that instead of optimizing L ( θ u ) we can simply add data from Tr to Tr ∗ to obtain the (1 − λ ) portion.
This approach, called random rehearsal , was presented in Robins (1995).
In practice in the case of ﬁne-tuning with rehearsal a portion of the general English training corpus (standard English corpus) must be sent to the user device.
Volume of typical user data generated on device is of the order of tens of kilobytes per month, and the size of the training data sent to the device will be of the same order.
Overall, random rehearsal is more efﬁcient, because there is no need to calculate soft labels.
2. S ERVER - SIDE MODEL UPDATE
The server-side part of the solution must aggregate models ¯ G it from many users and use them to update the general model G t .
We took simple model averaging as a baseline solution and transfer learning (Bengio (2011); Tang et al.
as an alternative approach.
In the case of transfer learning we optimized cross-entropy function (1), with y ∗ i given by an average prediction from N aggregated models θ ku :
[Equation]
Just as in the case of on-device training, transfer learning-based approach is rather inefﬁcient in terms of time and memory because predictions from all models are needed.
2. K EYSTROKE SAVING RATE
Keystroke saving rate (KSS) McKenzie & Soukoreff (2002) is deﬁned as a relative decrease in the number of characters the user has to type, given suggestions from the software keyboard:
[Equation]
[Table]
[Table]
[Table]
On-device re-
training, λ =
[Table]
where N total is the total number of non-space characters in the typed text and N typed is the number of characters user still had to type until the correct suggestion was presented.
In our experiments we used top-3 suggestion lists.
From the deﬁnition above one can see that KSS is better for customer experience assessment compared to perplexity.
Besides, perplexity measure underestimates out-of-vocabulary (OOV) words.
In the presence of OOV words perplexity is ill-deﬁned, so all OOV words must be removed from the test set.
It makes a direct comparison of models with different vocabularies impossible, which is impractical.
Finally, our experiments have demonstrated that a small decrease in perplexity may not correspond to KSS improvement and doesn’t lead to any practical result.
Nevertheless, our method demonstrates considerable perplexity reduction as well.
2. M ODEL FINE - TUNING EXPERIMENTS
The goal of our experiments was to ﬁnd the most efﬁcient pipeline to distributed ﬁne-tuning of language models.
We compared several approaches for client-side and server-side model updates.
In accordance with the problem statement we assumed a substantial difference between the reallife user corpus and the standard English corpus used for initial training, so we took Twitter and
Wikipedia corpora for the user and standard English corpora correspondingly.
The standard English train dataset contained approximately 30M tokens.
The hyperparameters of the model were initially tuned on the Standard English validation set of 3.8M tokens.
The user train dataset contained approximately 1.7M tokens.
Updated models were tested on subsets of the Twitter and Wikipedia corpora containing 200k and 170k tokens correspondingly.
Comparison between the random rehearsal and LwF training methods were carried out on a single node.
For our experiments we used LSTM architecture from Zaremba et al.
(2014) with 2x650 LSTM layers, a vocabulary size of 30k, dropout 0 .
5 , minibatch size 20 , BPTT steps 35 .
The initial general
English model was trained in 39 epochs.
We report KSS and perplexity on both the standard English test set and the user data test sets.
In the case of the standard English test set KSS was calculated on a subset of 200 sentences ( tokens).
The initial general English model had a perplexity of 100 . 1 and 67 .
9% KSS rate on the
Standard English test and perplexity 336 . 0 and 49 .
7% KSS rate on the user data test set.
So, the model experienced a considerable 18 . 2% drop in performance on the user data test set.
Table 1 summarizes our experiments with on-device model update algorithms.
We see that the performance gap between the standard English and the user test sets can be considerably reduced at the cost of performance degradation on the ﬁrst dataset.
The best average perplexity is reached with the random rehearsal method and λ = 0 .
We believe that the reason of the comparably inferior performance of the LwF method can be explained by the fact that soft labels used by LwF give a poor approximation of the true word distribution of general English so adding a small portion of true data gives better results in terms of knowledge preservation.
[Figure]
[Table]
[Figure]
To compare model averaging and transfer learning for a server-side model update, we carried out a small experiment with 10 nodes and 1 iteration of the server-side update.
Each model was trained on a mobile phone with a quad-core mobile CPU with a clock frequency 2 . 31 GHz.
We used a minibatch size 10 , number of BPTT steps 20 , learning rate 0 .
75 and 1 epoch.
Training took approximately 140 seconds on 20 kilobytes of text (user-generated and rehearsal data).
Note that we used mobile CPU only, so using the computation time may be reduced by using mobile GPU.
Then updated user models were used for general model update on the server.
For the server-side model update algorithm we also tried the approach proposed in Shin et al.
In this case the new model is trained on the texts generated by its previous round of update.
We tested both 1 generation per epoch and a single time generation before the ﬁrst epoch.
We carried out at most 6 epochs so we had 1 and 5 cycles of text generation correspondingly.
Results of the experiment are summarized in Table 2.
We saw no signiﬁcant differences between transfer learning on real and generated data.
The difference between transfer learning and averaging is more sound but still not large.
At the same time model averaging is much more computationally efﬁcient, as long as transfer learning requires calculation of labels from each of the teacher models.
After 300 rounds of model updates with 3000 nodes ( 10 nodes per round) we ended up with an 8 .absolute gain in KSS on the user data test with only a 0 .
6 absolute KSS drop on the standard English data test.
Figure 2 shows that the model starts to perform reasonably well after 100 rounds of updates.
It also shows the importance of rehearsal for preventing catastrophic forgetting.
2. C OMMUNICATION COSTS
There are several modiﬁcations of federated learning aimed at minimization of communication cost (e.g. see Koneˇcn´y et al. (2016), Lin et al. One of the most helpful tricks is to use only the most important weight updates for aggregation either omitting the rest the weights (Koneˇcn´y et al.
(2016)) or accumulating them in order to use them once the sum becomes large enough (Lin et al.
Note that most of these methods suppose that an updated model is obtained by subtracting aggregated gradients which is in fact equivalent to aggregating weights of the users’ models in order to obtain an updated model as we usually write.
It was shown that only a very small part of weight updates needs to be taken into consideration in distributed learning setting without any loss in quality of the model.
In Lin et al.
(2017) for language modeling task the gradient compression ratio of 462x was obtained due to gradient accumulation strategy for small updates.
The advantage of our method is that the aggregation of user models after each on-device gradient update is not needed.
Instead we train user model for an epoch and only then send this model for aggregation.
This feature makes our distributed learning scheme competitive both in terms of performance and communication efﬁciency.
Moreover, in our scheme the data on a device is used only once and can be deleted after the on-device training stops whereas in the mentioned works the data on each device is used many times (once an epoch).
We can show that our method is comparable with that mentioned in Lin et al.
(2017) on a popular language modeling benchmark PTB.
At the end of the 40-th epoch the perplexity 72 . 24 was reached by the method proposed in Lin et al.
(2017) with total communication costs equal to 5.6Gb.
Our method reached perplexity 74 . 48 with the same communication costs on the same neural network architecture as in Lin et al.
(2017) ( 2 -layer LSTM with 1500 units, tied input and output embeddings, variational dropout).
The training took 28 rounds of averaging.
The model was trained during 10 epochs on each node (device) in each round of averaging.
As the task suggests, there was no pretrained model – the model was initialized randomly.
P RIVACY ANALYSIS 3. M ETHODOLOGY
Our analysis is based on the experimental evaluation of differential privacy.
The notion of differential privacy (Dwork & Roth (2014)) appears naturally in many applications when it comes to estimating of the possibility of privacy violation.
In particular, it can be applied to language models trained on private user data.
Loosely speaking, if we have a mechanism that takes some input data and produces some output then differential privacy measures how a single input unit inﬂuences the total output.
In order to achieve differential privacy, some randomness must be introduced into the mechanism.
Deﬁnition 1.
A randomized mechanism M with domain D and range S satisﬁes ( ε, δ ) -differential privacy if for any two inputs d , d (cid:48) ∈ D that are adjacent (i.e. differ in one record) and for any subset of outputs S ⊆ S it holds that:
[Equation]
In our case D is the set of all subsets of users and a randomized mechanism M ( d ) is a mechanism that generates texts according to a certain language model trained on d ∈ D .
Note that for any d we need to have
[Equation]
Thus it is necessary for S to be the set of all possible texts of some ﬁxed length rather than the set of all texts of an arbitrary length.
In our analysis we will consider only the space of texts containing 10 words.
This is reasonable because it is close to the average length of a sentence in our user data corpus and it seems that if user’s privacy is violated then 10 consequent words are already enough for an adversary to retrieve important information.
Let us ﬁx two adjacent sets of users d and d (cid:48) , train models θ and θ (cid:48) on them and introduce random variable c ( s ) .
It is deﬁned by the expression
[Equation]
for any s ∈ S .
Since a language model Θ assigns some positive probability to any sequence of words, c ( s ) is deﬁned correctly for all s ∈ S .
Parameter δ in the Deﬁnition 1 stands for the probability that two probabilities P ( s | θ ) and P ( s | θ (cid:48) ) differ much.
This fact is formalized by the following proposition:
Proposition 1.
If P ( s ∈ S : c ( s ) > e ε | θ ) ≤ δ then P ( S | θ ) ≤ e ε P
( S | θ (cid:48) )
+ δ for any S ⊆ S
Proof.
Let B = { s ∈ S : c ( s ) > e ε } .
Then for any S ⊆ S
P ( S | θ ) =
P ( S ∩ B | θ ) + P ( S ∩ B | θ ) ≤ P ( B | θ ) + e ε P ( S ∩ B | θ (cid:48) ) ≤ δ + e ε P
( S | θ (cid:48) )
[Figure]
The proposition implies that it is sufﬁcient to estimate the tail of the distribution of c ( s ) under measure P ( ·| θ ) .
Furthermore, Figure 3 suggests that the tail of the empirical distribution function of the observed variable c ( s ) has the Pareto distribution.
This seems natural as far as words in human language follow Zipf’s law which is a discrete analogue of the Pareto distribution.
To make a conﬁdent estimation of differential privacy parameters, we consider 20 different pairs of adjacent sets of users d and d (cid:48) .
For each one, we consider a composite null hypothesis that the tail of the random variable c ( s ) deﬁned in (6) has the Pareto distribution with the shape parameter equal to its Hill’s estimator (M. Hill (1975)).
Then we apply the Lilliefors test and accept the null hypothesis at a signiﬁcance level of 5% .
Quantiles of the Pareto distribution can be written down explicitly thus giving the following formula for estimation of parameters ε and δ :
[Equation]
where α and C are parameters of Pareto distribution deﬁned in statistical tests (see Appendix).
Finally, for a given δ we take the largest value of ε amongst all the experiments.
[-Experiment          (cid:98) α 16 .14 .
-]
3. E XPERIMENTAL EVALUATION
The critical value for the Lilliefors test at 5% signiﬁcance level is 1 . 08 .
In 19 cases out ofthe Lilliefors test fails to reject the null hypothesis.
This conclusion, together with sample visual representation in Figure 3, allows us to state that the random variable c ( s ) indeed has tails that decrease like the Pareto distribution tails with quite a big shape parameter.
Exact values of KS statistics and Hill’s estimators of this parameter for different pairs of users are provided in the Table 3. [Table]
[Table] Table 4 shows the results for different values of δ calculated by formula (7).
In this table the value of ε is the largest value of this parameter in all 20 experiments.
The total number of users is 3 · 10so it is reasonable to put δ = 10 − 4 .
For this choice of δ parameter ε equals to 0 .
It means that our algorithm offers reasonable privacy guarantees (see (Papernot et al., 2017)).
Additionally we provide values of ε for smaller values of δ .
The results shown in Table 4 demonstrate that our scheme provides a very good level of privacy protection.
However, it is necessary to say that we only aim to produce an empirical estimation of differential privacy which inevitably holds with some high probability but not almost surely (this fact makes our approach close to the so-called random differential privacy introduced in Hall et al.
In many machine learning algorithms, the outcome is initially deterministic and some wellknown distribution is used to generate noise in order to make the algorithm differentially private (e.g. Papernot et al.
In our mechanism the source of randomness lies inside the neural network and the output distributions can’t be written explicitly.
This is the reason why we are able to provide only empirical estimations of differential privacy parameters.
C ONCLUSION
We have presented our results in distributed ﬁne-tuning of neural language models.
We paid special attention to preventing a catastrophic forgetting of the general language after a model ﬁne-tuning on the user devices.
Our experiments showed that the performance of an initial model of the general
English on user data can be improved signiﬁcantly almost without a performance degradation on the standard English training data.
We found that a combination of on-device training with random rehearsal and server-side model averaging provides the best performance for such distributed ﬁnetuning.
We also measured on-device training time and it took less than 3 minutes with a realistic assessment of volume of the available user data.
Finally, we provided an experimental evaluation of differential privacy of our method and showed that the method has a reasonable level of differential privacy compared to other solutions.
We still have to note that we provided an empirical estimation of differential privacy which holds with some high probability but not almost surely.
A E XPERIMENTAL EVALUATION OF DIFFERENTIAL PRIVACY FOR TEXTS
One can usually identify that samples come from a power-law distribution by looking at its tail distribution function F ( x ) = 1 − F ( x ) where F ( x ) is a cumulative distribution function (e g.
Newman (2005) describes this method).
If F ( x ) =
C/x α then log F ( x ) =
log C − α log x , i.e. the plot should be linear on logarithmic axes.
Figure 3 shows the empirical tail distribution function of the observed variable c ( s ) .
We generated n = 3 · 10 4 samples (10-word sequences) with the model with parameters θ to get observations of c ( s ) .
It can be seen that the tail of c ( s ) is linear on logarithmic axes like the tail of the Pareto distribution in the region { log c ( s ) > 0 . 35 } .
So we suppose that F ( x ) =
C/x α for big values of x .
More precisely, we suppose that the distribution function of c ( s ) for x > x 0 can be represented by the following formula:
[Equation]
for some x 0 .
Parameter α plays the most important role in the further analysis of differential privacy.
A common way to estimate it is to use Hill’s estimator:
[Equation]
where c ( i ) n are the order statistics c (1) n ≥ c (2) n ≥ ... ≥ c ( k ) n ≥ ... ≥ c ( n ) n and n is the number of samples.
This estimator is described in M. Hill (1975).
It is a maximum likelihood estimator and it converges in probability to α when n → ∞ , k = k ( n ) → ∞ and k ( n ) /n
→ 0 .
Note that the estimator depends only on outliers of c ( s ) .
This is a very helpful property because it allows us to use it even when we need to estimate only the tail distribution F ( x ) for large values of x rather than the whole distribution.
In the experiments we take k ( n ) = 2 (cid:98)√ n (cid:99) .
We put x 0 = c ( k ) n .
For different pairs of adjacent sets of users d and d (cid:48) values of (cid:98) α vary from 14 .
4 to 20 . 9 .
Values of x 0 vary from 1 .
33 to 1 . 43 , so log x 0 lies in the interval [0 . 28; 0 . 36] in our experiments.
Then we tested the null hypothesis that the cumulative distribution function F ( x ) of the random variable c ( s ) is of the Pareto law with the shape parameter (cid:98) α for all x > x 0 .
The KolmogorovSmirnov (KS) test is often used for this purpose (Koning & Peng (2008) illustrates this approach).
Since we tested a composite hypothesis, we needed to use modiﬁcation of the KS test that is called the Lilliefors test.
In the same way as in Koning & Peng (2008) we introduced new random variables r i = log
c
( i ) n /c
( k ) n for i
= 1 , .., k .
Since c ( i ) n are order statistics, we have c ( i ) n /c ( k ) n ≥ 1 for i = 1 , .., k
and it can be shown that these variables are jointly equal in distribution to ordered samples from
Pareto law with the shape parameter α and the scale parameter 1 .
So, under the null hypothesis { r i } 1 ,..,k are exponential with the parameter α
and we can apply the Lilliefors test to check whether these samples really come from an exponential distribution with an unknown mean estimated by r = 1 / (cid:98) α .
The method that we use (the Lilliefors test for exponential distributions) is described in Gibbons &
Chakraborti (2010).
Essentially, we calculate a KS statistic for the exponential distribution with a mean that’s equal to 1 and an empirical distribution function F k ( r ) of the values { r i /r } 1 ,..,k :
[Equation]
This statistic doesn’t converge to the Kolmogorov distribution as shown in W. Lilliefors (1969).
It converges to the distribution with smaller critical values at the same signiﬁcance levels because we overﬁt on the sample data when the estimator r is plugged in.
We chose a 5% signiﬁcance level and critical value for it is 1 .
In 19 cases out of 20 the Lilliefors test failed to reject the null hypothesis at a 5% signiﬁcance level.
Table 3 provides exact values obtained during the application of the statistical test.
Relying on these values along with data visualization in 3 we can state that random variable c ( s ) has tails that decrease like the Pareto distribution tails.
The hypothesis that we accepted suggests that the cumulative distribution function of c ( s ) is given by the formula (8).
It means that the tail distribution function for all x > x 0 is given by
[Equation]
We chose x 0 = c ( k ) n , so F ( x 0 ) is just the ratio k/n .
Thus, C can be estimated by
[Equation]
Values of (cid:98) C are given in the Table 3.
Finally, from formula (11) and proposition 1 it is easy to derive that ( ε , δ )-differential privacy is provided by the values ε , δ that satisfy
[Equation]