On-Device Personalized Lexicon Learning for Mobile Keyboard
grammarly · Tech · 2024 · source Agentic: no · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)
Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.
Problem
Domain: Mobile keyboard personalization
Grammarly needed its iOS keyboard to learn personal vocabulary for autocorrection without sending private user text to the cloud or exceeding tight mobile memory and latency budgets.
Constraints:
- The model had to run on-device.
- Memory usage needed to stay under 5 MB RAM.
- The system had to distinguish personal vocabulary from typos.
- User privacy required avoiding cloud upload of personal vocabulary.
Architecture
Grammarly built an on-device lexicon learner using memory-mapped storage, time-based decay, noisy-input filtering, and edit-distance frequency thresholds to validate new personal words.
Diagram confidence: reconstructed (reconstructed from prose).
flowchart LR keyboard-input-stream["Keyboard Input Stream"] noisy-input-filter["Noisy Input Filter"] frequency-thresholding["Frequency Thresholding"] personal-lexicon-store["Personal Lexicon Store"] autocorrection-suggestions["Autocorrection Suggestions"] keyboard-input-stream --> noisy-input-filter noisy-input-filter --> frequency-thresholding frequency-thresholding --> personal-lexicon-store personal-lexicon-store --> autocorrection-suggestions
Components
| Component | Role | Interacts with |
|---|---|---|
Keyboard Input Stream |
Provides candidate personal vocabulary observations. | Noisy Input Filter |
Noisy Input Filter |
Filters likely typos before vocabulary learning. | Frequency Thresholding |
Frequency Thresholding |
Uses edit distance and frequency to verify new words. | Personal Lexicon Store |
Personal Lexicon Store |
Stores learned vocabulary locally using memory-mapped storage and decay. | Autocorrection Suggestions |
Autocorrection Suggestions |
Uses the personal lexicon to reduce incorrect corrections. | — |
Data flow
Keyboard usage provides candidate vocabulary, noisy input filters remove likely typos, edit-distance frequency thresholds validate new words, time-based decay manages vocabulary lifetime, and memory-mapped storage keeps the lexicon small and local.
Why this architecture
On-device learning was required to preserve privacy while memory-mapped storage and decay kept the system responsive under strict mobile constraints.
Models used: On-device machine learning model · Memory-mapped storage · Edit-distance frequency thresholding
Scale
- The deployment reached more than 5 million devices.“Deployed to over 5 million devices”summary, stated
- The model operated under a 5 MB RAM budget.“under 5 MB RAM”summary, stated
Alternatives considered (roads not taken)
Cloud-based personalized vocabulary learning
Rejected because: The design avoided sending personal vocabulary data to the cloud.
Accept every new token as personal vocabulary
Rejected because: The model had to distinguish valid personal words from typos.
Patterns
agent-memory (personalization)
The keyboard maintains a persistent local personal lexicon that changes future autocorrection behavior.
safety-policy-enforcement (privacy)
The system keeps personal vocabulary on-device rather than sending it to the cloud.
cost-aware-routing (mobile-efficiency)
Memory-mapped storage and small RAM usage keep the local model practical on mobile devices.
Tradeoffs
Keep learning on-device
Chose Local lexicon learning over Cloud-based personalization.
Rationale: On-device learning protects user text privacy while enabling personalized corrections.
Use decay and thresholds
Chose Managed vocabulary lifecycle over Permanent accumulation of all observed tokens.
Rationale: Decay and verification help distinguish true personal vocabulary from noise.
Gotchas (what bit them)
Personalization can learn typos as vocabulary.
Root cause: Keyboard input includes noisy mistakes alongside real personal words.
Resolution: Use noisy input filtering and edit-distance frequency thresholds.
Mobile personalization has severe memory and latency limits.
Root cause: Keyboard suggestions must remain responsive on-device.
Resolution: Use memory-mapped storage and a minimal memory footprint.
Evaluation
Grammarly evaluated deployed behavior with reverted suggestion rates, acceptance rates, memory footprint, and responsiveness.
Metrics: Reverted suggestion rate · Suggestion acceptance rate · Memory footprint · Latency/responsiveness
Outcomes
- The model deployed to over 5 million devices.
- Reverted suggestions decreased.
- Acceptance rates increased.
- The system maintained minimal memory footprint and responsive performance.
Deployment reached over 5 million iOS keyboard devices under a sub-5 MB RAM constraint.