# Federated Learning for Mobile Keyboard Prediction

Federated learning trains keyboard prediction models on phones without server copies of typed text

Andrew Hard, Kanishka Rao, Rajiv Mathews, Swaroop Ramaswamy, Françoise Beaufays, Sean Augenstein and 3 more · arXiv · 2018-11-8

- **Problem** Gboard's next-word predictions came from a server-side n-gram decoder, and a stronger neural model needs typing text that users may not want sent to servers.
- **Method** The authors train a CIFG recurrent model on phones with Federated Averaging, where each client learns from its own typed text and the server averages the updates.
- **Results** The federated CIFG reached 16.4% top-1 recall on server-hosted logs, against 13.0% for the FST decoder.

## Why keyboard predictions need training text

Gboard offers the user three candidates in the suggestion strip, and the centre slot holds the candidate judged most probable. Until this work, those candidates came from a word n-gram finite state transducer, called the FST decoder, whose static English model is a 5-gram Katz smoothed Bayesian interpolated model with 1.25 million n-grams.

Keyboard models face tight resource limits: a visible response is expected within 20 milliseconds of an input event, and the model must run on both low-end and high-end phones.

Training a model that predicts real typing needs a large sample of text that resembles what users type, and public corpora often follow a different distribution from the user population. Collecting such text on a server requires logging, storage and security infrastructure, and users may be uneasy about personal text being stored remotely.

The study asks whether a recurrent model trained where the text is produced can match a server-trained model and the FST decoder on recall.

The authors present federated learning as an alternative to server-side collection for training this kind of model in a commercial product.

## The CIFG next-word model

The predictor is a recurrent network. Unlike n-gram models and feed-forward networks with a fixed window, an RNN conditions on a context whose length is not fixed, and LSTM gating is used to handle exploding and vanishing gradients in back-propagation through time. The model is a CIFG, a variant of the LSTM in which a single gate controls both the input and the forget behaviour through \\( f\_t = 1 - i\_t \\).

The authors argue that this coupling cuts the number of parameters per cell by 25% and leaves model performance unchanged, which matters on devices with limited computation.

Each word is a one-hot vector \\( v \\in \\mathbb{R}^{V} \\) with a vocabulary of \\( V = 10,000 \\) words for both input and output, and the embedding \\( d = Wv \\) uses \\( W \\in \\mathbb{R}^{D \\times V} \\). The output projection shares the same matrix, so the input embedding and output projection are tied, and a softmax over the output logits gives normalized probabilities trained with cross-entropy loss.

With \\( D = 96 \\) and a single layer of 670 units, the network has 1.4 million parameters, more than two thirds of which sit in the embedding matrix.

## How FederatedAveraging builds the global model

In each round the server sends the current global model \\( w\_t \\) to a subset \\( K \\) of client devices, and each client trains only on its own local examples. At \\( t = 0 \\) the clients start from a model that is either randomly initialized or pre-trained on proxy data. Each client holds \\( n\_k \\) examples, a count that varies by device and, for Gboard, follows the user's typing volume.

Each client computes the average gradient \\( g\_k \\) on its data at \\( w\_t \\), using one or more steps of stochastic gradient descent, and the local update is \\( w\_t - \\epsilon g\_k \\rightarrow w^k\_{t+1} \\), where \\( \\epsilon \\) is the client learning rate. The server aggregates these client models with weights \\( n\_k / N \\), where \\( N = \\sum\_k n\_k \\), so that \\( \\sum\_{k=1}^{K} \\frac{n\_k}{N} w^k\_{t+1} \\rightarrow w\_{t+1} \\).

Clients with more local examples therefore carry more weight in the new global model.

The server applies the aggregate with a Momentum optimizer that uses Nesterov accelerated gradient, a momentum hyperparameter of 0.9 and a server learning rate of 1.0. The authors report that this reduced training time compared with alternatives including pure SGD, and each round closes after 100 to 500 client updates.

Client updates are processed in memory and discarded after they are added to the aggregate, and only model weights are uploaded. The authors note that the approach still requires trusting the aggregation server not to inspect individual weight uploads, and that secure aggregation and differential privacy are complementary techniques.

## Server training on logged snippets

Server training uses snippets from Gboard users who opted in to share text typed in Google apps.

The study uses logs from the English-speaking population in the United States, with about 7.5 billion sentences for training and 25,000 sentences each for test and evaluation. The average sentence is 4.1 words long, and chat apps generate most of the logged text, at 60%, followed by web input at 35% and long form text at 5%.

Adam and AdaGrad were not found to improve convergence, and the network converges after 150 million SGD steps.

## Federated training on client caches

Each client cache stores the text typed by the device owner along with the prediction candidates the decoder generated. Clients must also be in North America, run Gboard release 7.3 or greater and have the US English language model enabled. The authors note that these criteria are chosen for the Gboard implementation and are not inherent to the federated learning platform.

Train, test and eval samples are defined as separate computation tasks rather than explicit splits, and the probability of client reuse across them is minimal in a large enough population. The cache mix is Chat 66%, Social 16%, Web input 5% and Other 12%.

Each round uses FederatedAveraging with 100 to 500 client updates, and each client processes about 400 example sentences in one epoch. The federated CIFG converged after 3000 rounds, in which 600 million sentences were processed by 1.5 million clients, and training typically took 4-5 days.

Recall is the ratio of correct predictions to the total number of tokens. For the n-gram decoder, recall is measured by comparing the candidates stored in the on-device cache with the text users actually entered, and the decoder is not trained.

## Offline recall on logs and caches

On server-hosted logs, top-1 recall was 13.0% for the FST decoder, 16.5% for the server CIFG and 16.4% for the federated CIFG. Top-3 recall was 22.1% for the FST decoder, 27.1% for the server CIFG and 27.0% for the federated CIFG.

Both CIFG models exceed the decoder on both metrics, and the two CIFG models sit close together on logs. The authors caution that logs are less representative of the true typing distribution, so this comparison supports less than the cache comparison.

On client-owned caches, top-1 recall was 12.5±0.2 for the n-gram decoder, 15.0±0.5 for the server CIFG and 15.8±0.3 for the federated CIFG. The quoted errors depend on the number of clients used in federated evaluation.

The federated CIFG improves top-1 recall by a relative 5% (0.8% absolute) over the server-trained CIFG on caches. The authors take the caches to represent typing more accurately, because they are not truncated and are not limited to Google-owned apps, and read the gain as federated learning giving access to higher-quality training data.

## Live production results

Errors for these live results come from the jackknife method applied to user buckets.

Top-1 impression recall was 5.24±0.02 for the n-gram decoder, 5.76±0.03 for the server CIFG and 5.82±0.03 for the federated CIFG.

Prediction click-through rate, the clicks divided by proposed candidates, was 2.13±0.03 for the n-gram decoder, 2.36±0.03 for the server CIFG and 2.35±0.03 for the federated CIFG.

The authors note that the n-gram model uses a vocabulary an order of magnitude larger and includes personalized user history and contacts models, so the CIFG gains are notable.

## Limitations

The logs comparison is weaker because logs are less representative than client caches, so the cache and live results carry most of the evidence for the federated gain.

Federated eligibility is restricted to devices and locations meeting the Gboard criteria, and the cache experiment covers only that population. The federated run and its gain over the server model are small: 0.8% absolute on caches and 1% relative on impression recall, with click-through rate slightly lower.

The paper names secure aggregation and differential privacy as complementary techniques, and the reported experiments do not evaluate them with the federated runs. The n-gram baseline is not trained in any of these studies, so the comparison measures the decoder as it stood.

## Paper info

- **Authors**: Andrew Hard, Kanishka Rao, Rajiv Mathews, Swaroop Ramaswamy, Françoise Beaufays, Sean Augenstein, Hubert Eichner, Chloé Kiddon, Daniel Ramage
- **Venue**: arXiv · Preprint
- **First published**: 2018-11-8
- **Added**: 2026-11-12
- **Updated**: 2019-2-28
- **Version**: v2
- **arXiv**: 1811.03604
- **Category**: cs.CL
- **Original paper terms**: [CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1811.03604v2) · [PDF ↗](https://arxiv.org/pdf/1811.03604v2)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Andrew Hard, Kanishka Rao, Rajiv Mathews, Swaroop Ramaswamy, Françoise Beaufays, Sean Augenstein, Hubert Eichner, Chloé Kiddon, Daniel Ramage (2018). Federated Learning for Mobile Keyboard Prediction. arXiv:1811.03604v2. https://arxiv.org/abs/1811.03604v2

**BibTeX**

```
@misc{hard2018federated,
  title = {{Federated Learning for Mobile Keyboard Prediction}},
  author = {Andrew Hard and Kanishka Rao and Rajiv Mathews and Swaroop Ramaswamy and Françoise Beaufays and Sean Augenstein and Hubert Eichner and Chloé Kiddon and Daniel Ramage},
  year = {2018},
  eprint = {1811.03604},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1811.03604v2}
}
```

## Related papers

- [A Survey of Convolutional Neural Networks: Analysis, Applications, and Prospects](https://refivu.com/en/papers/070c8ac2-628a-4354-98cb-c9aeae701850-a-survey-of-convolutional-neural-networks-analysis.md)
- [A Critical Review of Recurrent Neural Networks for Sequence Learning](https://refivu.com/en/papers/0e786415-0fad-4e73-b947-9aa88bb3aed0-a-critical-review-of-recurrent-neural-networks-for.md)
- [Isolating Perception for Multi-View Planning under Occlusion-Induced Partial Observability](https://refivu.com/en/papers/6ac42b45-0624-43a7-9143-e917da2b7cc2-isolating-perception-for-multi-view-planning-under-occlusion.md)
- [Towards Federated Learning at Scale: System Design](https://refivu.com/en/papers/5a416c7f-9637-4efb-9bcc-4ff43e95b3bd-towards-federated-learning-at-scale-system-design.md)
- [Robust and Communication-Efficient Federated Learning from Non-IID Data](https://refivu.com/en/papers/8cfbbb74-26ed-46b1-9bcb-908c177043d6-robust-and-communication-efficient-federated-learning-from.md)
- [Advances and Open Problems in Federated Learning](https://refivu.com/en/papers/a2ee015f-6b4f-4f3b-8bd5-474f5dd3b851-advances-and-open-problems-in-federated-learning.md)

## Other paper commentary

- [Ethical and social risks of harm from Language Models](https://refivu.com/en/papers/d42d41ba-833b-45f6-8837-7bfc3f4d36d8-ethical-and-social-risks-of-harm-from-language.md)
- [PaLM 2 Technical Report](https://refivu.com/en/papers/9930c339-e7c2-4330-9ea3-867aad7f3368-palm-2-technical-report.md)
- [A Survey on In-context Learning](https://refivu.com/en/papers/e3dcb216-0b54-4a23-8e0d-f077c493f505-a-survey-on-in-context-learning.md)
- [LaMDA: Language Models for Dialog Applications](https://refivu.com/en/papers/9474e307-9624-4203-a346-57d881b1a5d9-lamda-language-models-for-dialog-applications.md)
- [Cross-lingual Language Model Pretraining](https://refivu.com/en/papers/8d4c53c4-5c75-4330-9085-1b84a43703b6-cross-lingual-language-model-pretraining.md)
- [G-Eval: NLG Evaluation using GPT-4 with Better Human Alignment](https://refivu.com/en/papers/d14a3666-4caf-4371-83b0-d44fc50735f5-g-eval-nlg-evaluation-using-gpt-4-with.md)
- [ConvNeXt V2: Co-designing and Scaling ConvNets with Masked Autoencoders](https://refivu.com/en/papers/d6599a02-0aa8-4eec-a1c3-2bdc45716f23-convnext-v2-co-designing-and-scaling-convnets-with.md)
- [Deeper Depth Prediction with Fully Convolutional Residual Networks](https://refivu.com/en/papers/4ef3d92a-82ea-4f76-8b77-ec72d726dd77-deeper-depth-prediction-with-fully-convolutional-residual.md)
- [Deep Learning for Sensor-based Activity Recognition: A Survey](https://refivu.com/en/papers/2047ba14-2bcc-42f2-a0fe-57280553acee-deep-learning-for-sensor-based-activity-recognition-a.md)
- [Attention-Based Models for Speech Recognition](https://refivu.com/en/papers/3c2117c0-4216-4c2d-8001-0377fd293004-attention-based-models-for-speech-recognition.md)
- [A Comprehensive Survey of Graph Embedding: Problems, Techniques and Applications](https://refivu.com/en/papers/ec23e11b-6984-4611-aa20-93a65865b536-a-comprehensive-survey-of-graph-embedding-problems.md)
- [Learning Fine-Grained Bimanual Manipulation with Low-Cost Hardware](https://refivu.com/en/papers/8d8af879-da03-4506-b5c4-b0f829b285cf-learning-fine-grained-bimanual-manipulation-with-low-cost.md)

## Terms in this paper

- [LSTM](https://refivu.com/en/terms/ba10547646d9-lstm)
- [Federated Learning](https://refivu.com/en/terms/c6fc55e6f812-federated-learning)
- [FederatedAveraging](https://refivu.com/en/terms/2033f8afe384-federatedaveraging)
- [next-word prediction](https://refivu.com/en/terms/09bd603eb159-next-word-prediction)
- [top-1 recall](https://refivu.com/en/terms/917701a5d3e5-top-1-recall)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/e56197ce-a521-4965-9369-f978e10dc5fe-federated-learning-for-mobile-keyboard-prediction)
