On Google Pixel 6 smartphones, the keyboard has built-in automatic detection and correction of grammatical errors using a neural network. Text processing is performed in real time and is fully performed on the device.
The creation of such functionality required developers to take into account the limitations on RAM, the requirements for delay time and the need to process incomplete proposals.
A neural network with seq2seq architecture was trained to accept a sentence or part of it as input and issue a grammatically correct version. If the source text does not contain errors, then the input and output sentences are the same. The model uses a hybrid architecture that combines a transformer encoder and an LSTM decoder – a combination that provides the required balance of quality and delay time.
The model takes up 20 MB of memory and processes 60 input characters in less than 22 ms on a Pixel 6 processor.
To train the model, a dataset of pairs of sentences was used, one of which contained grammatical errors, and the second did not. To collect it, several hundred million sentences taken on the Internet were corrected by a large cloud model used in Google Docs.
Currently, this function is able to correct only sentences in English (in the near future it is planned to expand its functionality to more languages) and works in any application.