Proofread: Fixes All Errors with One Tap (2024)

Abstract: The impressive capabilities in Large Language Models (LLMs) provide a powerful approach to reimagine users’ typing experience. This paper demonstrates the Proofread feature in Gboard, a virtual keyboard running on mobile phones. Proofread enables seamless sentencelevel and paragraph-level corrections with a single tap. We describe the complete system in this paper, from data generation, metrics design to model tuning and deployment. To obtain models with sufficient quality, we implement a careful data synthetic pipeline tailored to online use cases, design multifaceted metrics, employ a two-stage tuning approach to acquire the dedicated LLM for the feature: the Supervised Fine Tuning (SFT) for foundational quality, followed by the Reinforcement Learning (RL) tuning approach for targeted refinement. Specifically, we find sequential tuning on Rewrite and proofread tasks yields the best quality in SFT stage, and propose global and direct rewards in the RL tuning stage to seek further improvement. Extensive experiments on a human-labeled golden set showed our tuned PaLM2-XS model achieved 85.56% good ratio. We launched the feature to Pixel 8 devices by serving the model on TPU v5 in Google Cloud, with thousands of daily active users. Serving latency was significantly reduced by quantization, bucket inference, text segmentation, and speculative decoding. Our demo could be seen in Youtube.

heading: 1 Introduction
text: Gboard is an statistical-decoding-based keyboard on mobile devices developed by Google. Decoding (Ouyang et al., 2017) is necessary due to the errorprone process of "fat finger" touch input on small screens. According to Azenkot and Zhai (2012), the per-letter error rate is around 8%-9% without decoding.
∗Equal contribution, alphabetical order. Correspondence to {renjieliu,zhangyx,yunzhu}@google.com.
Gboard provides various error correction features, some active (automatic) and other passive (require the user’s further manual action and selection) to provide a smooth typing experience (Ouyang et al., 2017). Active key correction (KC), and active auto correction (AC), word completions and next-word predictions support the users to type the current word and next word by fixing typos and providing multiple word candidates in the suggestion bar or inline (smart compose). Post correction (PC) supports fixing errors in last one or more committed words. Furthermore, The more passive Spell Checker and Grammar Checker supported by small-sized logistic regression and seq2seq models respectively detect the possible errors in committed sentences and mark them with red underlines, users can fix the errors by clicking the incorrect words and commit the correct words from the displayed candidates.
There are two types of user experience limitations with the existing correction approaches. First, users still have to type relatively slowly and accurately to avoid making too many or too severe errors that the small (but instantly fast) on-device correction models such as KC, AC and PC cannot handle due to their limited ability to model longer-span context. Second, users need to manually engage in the multi-step passive correction features, such as the grammar checker and the spell checker, to correct the committed words one after another.
Supervising the committed words while typing and fixing errors sequentially by editing after commit take users’ cognitive and visual-motor resources and slow down their typing speed. One desired pattern of fast typing users of Gboard is to focus on keyboard only without checking the committed words while typing. To this end, a high quality sentence-or-higher-level correction feature is often called for, in order to help those ”fast and sloppy” users who prefer to focus on typing then
1 286
switch to error corrections at a higher level. In this paper, we propose the Proofread feature to alleviate the pain points of fast typers by providing the sentence-level and paragraph-level error fixes with only one-tap. Proofread falls into the area of Grammatical Error Correction (GEC), which has a long history of research from rulebased to statistical approaches to neural network models (Bryant et al., 2023). The astonishing capability growth of Large Language Models (LLMs), offers a new opportunity to unlock the high quality sentence-level grammar fixes.
We present the entire system to tune and serve the LLM model behind Proofread in this paper. The system consist of four parts, data generation, metrics design, model tuning and model serving. Firstly, dataset is generated by a carefully designed error synthetic framework which integrates errors frequently made on keyboard to simulate the users’ input, several further steps are conducted to ensure the data distribution is close to Gboard domain maximally. Secondly, several metrics are designed to measure the model from various dimensions. As the answers are always not unique specifically for long examples, the metric combined with grammar error existence check and same meaning check based on LLMs are considered as the key metrics for comparing the model quality. Thirdly, inspired by InstructGPT (Ouyang et al., 2022), Supervised Fine-tuning followed by the Reinforcement Learning (RL) tuning is adopted to obtain the LLM dedicated for Proofread feature. Results suggested that our rewrite task tuning and reinforcement learning recipe significantly improves the proofreading performance of the foundation models. To reduce the serving cost, we build our feature on top of the medium sized LLM PaLM2-XS, which could be fit int a single TPU v5 after 8-bit quantization. We further optimize latency with bucket keys, segmentation and speculative decoding (Leviathan et al., 2023). Our model now is launched to benefit thousands of users with Pixel 8 devices.
Figure 1 exhibits our model quality on one extreme corrupted case from Andrej Karpathy1, which indicates our tuned model is strong enough to handle various of heavy typo errors made by users.
The contribution of this paper can be summarized as follows:
• We propose the Proofread feature supported 1https://twitter.com/karpathy/status/1725553780878647482
by the high quality LLM to boost the user typing experiences of Gboard. We finally launched the feature to real users with Pixel 8 devices, thousands of users benefit from it daily. • We design and implement the whole system from data generation, metrics design to model tuning and deployment. • We obtain a high quality model with cautiously synthetic data generation, multiple phased supervised fine-tuning and RL tuning. Specifically, we propose the Global Reward and Direct Reward in RL tuning stage, which improve the model significantly. Results shows that RL tuning could help reduce the grammar error significantly and thus the Bad ratio of PaLM2-XS model is reduced by 5.74% relatively. • We deploy the model to TPU v5 in Cloud with highly optimized latency acquired by quantization, buckets, input segmentation and speculative decoding. Our results suggested that speculative decoding reduced the median latency by 39.4%.

heading: 2 Related Work

heading: 2.1 Controllable Text Generation
text: Controllable text generation using transformerbased pre-trained language models has become a rapid growing yet challenging new research hotspot (Zhang et al., 2023). Proofread falls into this scope with the requirement of modifying the input to fix the grammar errors without changing the original intention in the corrupted text.
Lots of applications could inherit from controllable text generation. Shu et al. (2023); Zhu et al. (2023) focus on text rewrite tasks, including paraphrasing (Xu et al., 2012; Siddique et al., 2020), style transfer (Riley et al., 2020; Zhang et al., 2020; Reif et al., 2021) and sentence fusion (Mallinson et al., 2022) and so on. Similarly, Text editing (Malmi et al., 2022) task also covers a wide range of sub-tasks such as paraphrasing, style transfer, spelling and grammatical error correction (Napoles et al., 2017), formalization (Rao and Tetreault, 2018), simplification (Xu et al., 2016) and elaboration (Logan IV et al., 2021).
Unlike these mentioned works, our paper only addresses a single application – Proofread but provides systematic approaches that optimize the model from different perspective such as quality,
2
latency and resource usage.

heading: 2.2 Grammatical Error Correction (GEC)
text: Proofread falls into the area of GEC. Bryant et al. (2023) offers a comprehensive survey of the history and the current state of GEC. Specifically, before LLM, the popular solutions of GEC are editbased approaches which corrections are applied on a sequence labelling (Omelianchuk et al., 2020) or sequence-to-sequence basis (Stahlberg and Kumar, 2020).
The recent studies to apply LLM to GEC mainly focus on prompting the LLM rather than supervised fine-tuning. Wu et al. (2023) compares ChatGPT to Grammarly, Coyne et al. (2023) compares GPT-3.5 and GPT-4 to two GEC system on English benchmarks. Davis et al. (2024) conducts a more comprehensive study by evaluating seven open-source and three commercial LLMs on four established GEC benchmarks.
Following the LLM trend, our system is built upon latest LLM backbone. But we apply instruction tuning approach to customize the LLM.

heading: 2.3 Instruction Tuning(IT)
text: Instruction tuning has been proven to be an efficient approach to boost model performance and generalization to unseen tasks (Chung et al., 2022; Sanh et al., 2021). Reinforcement learning with human feedback (RLHF) is leveraged to further extend instruction tuning in InstructGPT (Ouyang et al., 2022). Reinforcement learning with AI feedback (RLAIF) (Bai et al., 2022) could alleviate
the heavy human preference data dependency, Zhu et al. (2023); Cheng et al. (2021) further replace the reward model in RLAIF with a heuristic model, which will be adopted in this paper to boost the quality. Our instruction tuning approach is inspired by the previous works and also follows the 2-step tuning process. We designed the synthetic data generation and RL strategy in a heuristic way that favors the proofreading task.

heading: 2.4 Latency Optimization
text: Numerous techniques aim to speed up inference of LLMs, which can be categorized into two major lines according to the focus point. The first line mainly focuses on model or algorithm side, including model compression with pruning (Xia et al., 2023b) and sparsity (Xia et al., 2023a), quantization (Dettmers et al., 2022), small model design (Timiryasov and Tastet, 2023; Liu et al., 2024), attention computation optimizations like low-rank approximation (Katharopoulos et al., 2020), sparse attention (Roy et al., 2021) etc.
The other line explores acceleration along with hardwares, exemplified works includes FlashAttention (Dao et al., 2022), FlexGen (Sheng et al., 2023), which considers hardware scheduling and weight movement, and speculative decoding (Leviathan et al., 2023; Chen et al., 2023), which leverages the parallism of hardwares to pre-conduct computation with sampling method.
We adopt quantization and speculative decoding to accelerate the inference speed in the model deployment.
3

heading: 3 Dataset
text: The upper half of Figure 2 illustrates the pipeline to generate the dataset. We initially sample data from the web crawled dataset, which is then processed by a GEC model to fix the grammar errors. Each item in the dataset consists of a source sentence with several possible reference sentences.
Grammar errors are then synthesized into the source sentence to simulate users’ inputs, various kinds of errors which frequently happen in Gboard real scenarios are involved in this step, including:
• character omission, e.g., "hello" as "hllo" • character insertion, e.g., "hello" as "hpello" • transposition, e.g., "hello" as "hlelo" • double tap, e.g., "hello" as "heello" • omit double characters, e.g., "hello" as "helo" • Gaussian-based positional errors, e.g., "hello"
as "jello" To align the dataset with real use cases, the data with synthetic errors are then passed to the Gboard simulator to fix errors by leveraging Gboard’s builtin literal decoding, KC and AC functions. Moreover, several heuristic rules were then applied to fix cases such as emoji/emoticons alignment, date time formatting, and URL patterns.
The last step is to filter the noise data by utilizing LLM with careful designed instructions to avoid polluting the model. Data is diagnosed by various dimensions, including:
• The reference sentence still has errors remaining. • The reference sentence itself is not fluent or clear enough. • The reference sentence has different meaning as the source sentence. • The reference sentence has different tones, aspects and tense from the source sentence.
To maximally benefit the model quality, the criteria above coordinates to the metrics defined in the following section.
An example of the synthetic dataset is showcased below:
Source: "Good Moning! hey si, how. a u dou?" Reference1: "Good morning! Hey sir, how are you doing?" Reference2: "Good morning! Hey sister, how are you doing?"
Moreover, part of the examples labeled by human rater are used as the golden set for evaluation.

heading: 4 Metrics
text: It’s of key importance to define the correct metrics which are aligned to user experiences online before the feature goes to public. In this section, several metrics are designed to measure the model quality.
Given the three elements, input (corrupted text), answer (predicted candidate from the model) and target (ground truth), we present the following metrics.
• EM / Exact Match Ratio: ratio of answer equal to target exactly. • NEM / Normalized Exact Match Ratio : ratio of answer equal to target ignoring capitalization and punctuation. • Error Ratio: ratio of answer containing grammar errors, which is conducted by LLM with specific instruction. • Diff Meaning Ratio: ratio of answer and target don’t have the same meaning, which is also conducted by LLM with specific instruction. • Good Ratio: ratio of answer without grammar error and has the same meaning with target. • Bad Ratio: ratio of answer either have grammar error or has different meaning with target.
From the definition, the Good/Bad ratios combining Error check and Diff Meaning check, are the primary metrics due to their robustness from LLM. The bad ratio is a bit more important as it portrays how much the users could tolerate the errors made by model. The combination of Error / Diff Meaning checks is also leveraged as the reward in RL phase of model tuning. EM/NEM ratios are referenced as supporting indicators as they are too strict for examples with multiple references.

heading: 5 Model tuning
text: The lower half of Figure 2 illustrates the tuning steps of the model for Proofread. We start from instruction-tuned models. PaLM2-XS model from Anil et al. (2023) is the candidate model.

heading: 5.1 Supervised Fine-tuning
text: The initial step after choosing the checkpoint is to fine-tune the model on the rewrite dataset, which contains hundreds of text rewriting tasks from Shu et al. (2023); Zhu et al. (2023). We assume that fine-tuning on similar tasks is beneficial to the final quality of Proofread. After that, the models are fine-tuned on synthetic dataset.
The evaluation results of multiple phased tuning are displayed in Table 1. It’s natural to observe
4
that after supervised fine-tuning on the synthetic dataset, the model quality can be largely improved from 65.48% to 83.80%. An interesting finding is that though fine-tuning on Rewrite dataset degrades the quality, sequential fine-tuning on Rewrite and Proofread datasets yields the best results with Good ratio 84.68% and Bad ratio 15.32%, which we argue the robustness is enhanced by the large size of the combined dataset, by comparing M2 and M3, we can further conclude that Rewrite tuning contributes to the intent preservation.

heading: 5.2 Reinforcement Learning
text: RLAIF is leveraged with heuristic rewards in our model tuning following Zhu et al. (2023) to avoid relying on human labelers. Two alternative heuristic rewards based on LLM are designed in this paper.
• Global Reward: With few-shot examples, the LLM tells whether a candidate is a good fix of the corrupted inputs. • Direct Reward: As the goal is to improve the Good Ratio, we directly convert the grammar error check and diff meaning check into rewards, both relying on LLM and will be combined as the final reward. This requires the ground truth included in the example.
Proximal Policy Optimization (PPO) (Schulman et al., 2017) is facilitated to optimize the model. KL divergence is involved to help model keep the ability to recover the original text (Peters et al., 2010; Mitchell et al., 2023).
The second part of Table 1 exhibits the results of RL tuning with different rewards. It’s observed that the Bad ratio of PaLm2-XS model could be improved by 3.65% and 5.74% relatively through applying the RL with Global Reward and RL with Direct Reward respectively.
Specifically, RL excels at reducing the grammatical error but struggles to maintain meaning alignment between prediction and ground truth by comparing M3, M4 and M5. We argue that the optimizing meaning is inherently more subjective and complex comparing than grammar. Additionally, RL reduces the EM and NEM ratios, indicating a shift in the output distribution for both correct and incorrect cases. While increasing the KL divergence penalty can mitigate this (See M5 and M6), it doesn’t significantly improve the Good/Bad ratios. We suspect the defined metrics might have inherent conflicts. Future work will reply on online metrics and real user data to drive further improvement.

heading: 6 Model Serving
text: Google’s TPUv5e (Google, 2023) is utilized to serve the Proofread model, which is the latest Google TPU chip with 16GB HBM. 8-bit quantization is facilitated to reduce the memory footprint and latency without observing quality degradation.
In the context of our research, which predominantly focuses on deployment within chat applications, it has been observed that the average sentence length seldom exceeds 20 words. Consequently, we have established a discrete set of bucket keys, specifically [16, 32, 64, 128], to categorize the input data accordingly. Furthermore, we have calibrated the temperature parameter to a value of 0.3, aiming to maintain a constrained level of creativity in the proofreading outcomes, thereby ensuring relevance and coherence.
To be capable of handling more extensive documents, a systematic approach is employed wherein the document is segmented into individual paragraphs. All paragraphs are then processed in parallel, allowing for a more manageable and efficient analysis.
5
Table 1: The metrics of PaLM2-XS tuned on various phases on the Golden dataset. The upper half focuses on the supervised fine-tuning, and model variants in Reinforcement Learning phase are listed in the lower half.
Model ID PaLM variant EM(%) NEM(%) Good(%) Bad(%) DIFF(%) ERROR(%) M0 PALM2-XS 29.96 45.80 65.48 34.52 18.56 30.32 M1 M0 + Rewrite 23.44 40.90 59.48 40.52 19.04 37.04 M2 M0 + Proofread 37.88 55.30 83.80 16.20 12.08 8.12 M3 M0 + Rewrite + Proofread 39.16 56.20 84.68 15.32 10.60 9.68 M4 M3 + RL Global Reward 35.92 53.80 85.24 14.76 11.12 6.80 M5 M3 + RL Direct Reward 32.20 50.20 85.56 14.44 11.52 5.68 M6 M5 + Large weight on KL 39.08 55.40 84.76 15.24 10.96 8.88
Additionally, our methodology incorporates the use of speculative decoding (Leviathan et al., 2023), complemented by heuristic drafter models that are tailored to align with user history patterns. Under our proofreading case, the initial input would naturally fit into the speculative draft so external drafter models are needed. We share an example to illustrate the process in Figure 3. This innovative approach significantly contributes to the reduction of operational costs. Through empirical evaluation in Table 2, we have recorded a 39.4% reduction on median latency per serving request, as measured on Tensor Processing Unit (TPU) cycles, underscoring the efficiency of our system in real-time applications.

heading: 7 Conclusions
text: This paper presents a novel Proofread feature implemented within Gboard, powered by a carefully refined LLM. Our work demonstrates the significant potential of LLMs to enhance the users’ typing experiences by providing high-quality sentenceand paragraph-level corrections. We detailed our comprehensive approach, encompassing synthetic data generation pipeline aligned with real-world use cases, multifaceted metrics design, two-stage model tuning (multiple phased SFT followed by RL) and the efficient model deployment.
Specifically, our findings reveal that rewrite task tuning benefited the SFT model by enhancing the meaning alignment ability of the model. Additionally, we discovered the value of global and direct rewards during RL tuning, which could further improve the model by reduce grammar errors significantly. Rigorous experiments demonstrated that our tuned PaLM2-XS model achieved an impressive 85.56% good ratio and 14.44% bad ratio. The successful deployment of the model on TPU v5, leveraging optimizations such as quantization, bucket inference and speculative decoding, highlights its real-world viability.
This work underscores the transformative power of LLMs in the realm of user input experiences. Future research directions include leveraging real-user data, multilingual adaption, personalized assistance for diverse writing styles and privacy-preserving on-device solutions. This technology has the potential to fundamentally improve how we interact with our devices.

heading: Acknowledgments
text: The authors would like to thank Ananda Theertha Suresh, Jae Ro, Ziteng Sun, Shankar Kumar, Lan Wei, Yuki Zhong, Zhe Su, JinDong Chen for their insightful discussions and support.
6

heading: Future Work
text: Future research directions include leveraging real-user data, multilingual adaption, personalized assistance for diverse writing styles and privacy-preserving on-device solutions. This technology has the potential to fundamentally improve how we interact with our devices