How a small neural language model in Keyboard beat server-side suggestions

Vadim Shchukin2 Aug 2023

Problem

Yandex Keyboard inherited an n-gram language model from the server-side Speller. The device allows a few tens of megabytes, 10 ms per key press and 200 ms for suggestions, on any phone. N-gram quality grows only with corpus size and model order, so the model cannot get bigger on the device. Cloud suggestions partly solved the size problem. Open questions remained: app information, personalization, unfamiliar words in context and long contexts.

Example from the article: a typo in a previous word breaks the context for an n-gram model, and the same prefix "p" should give "privet" in a messenger but "prospekt" or "Pasha" in a maps or contacts app.

Solution in brief

Replace the n-gram model with a small word-level neural model: an LSTM encoder, convolutional character-level embeddings and a Differentiated Softmax output layer. The model is about 18 MB in total (1 + 5 + 12 MB), fits the 200 ms budget and beats the cloud model that was more than 200 times larger. Feeding an application embedding into the same model gives app-specific suggestions.

Questions this case answers
  • How to replace a large statistical language model with a compact neural one that fits strict size, latency and power limits on a client device without losing quality
  • How to condition next-word suggestions on a categorical context signal when the existing model can only use text
  • How to replace an n-gram language model in a mobile keyboard with a neural one under a size limit of tens of megabytes and a 200 ms suggestion budget?
  • How to keep a neural language model fast on a phone when the embedding table and the softmax layer dominate its size?

Tools and methods

  • LSTM encoder — one state update per new token.
  • Character CNN embeddings — word vectors from letter convolutions: small, deterministic.
  • Differentiated Softmax — larger projections for frequent words, smaller for rare ones.
  • Letter-level decoder — next-letter prediction on the shared encoder.
  • Application embedding — tells the model where the user types.
Continue reading — it's free

Google or a one-time email code. No password.