Skip to content
fordpepperPublic

About

A tiny in-browser model that guesses your next letter and learns how you type

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pretype

A very small model that guesses the next letter you type and learns how you write. It runs entirely in your browser. Try it at https://fordpepper.github.io/pretype/.

How it works

Every keystroke goes through two models, and a third one blends them:

  1. A tiny character GRU (264k parameters, 256 hidden units, int8 weights, ~300 KB). It was pretrained on ~84M characters of Wikipedia, public-domain novels and short stories. The embedding is folded into the input projection, so one step costs one 256×768 matrix-vector product: well under a millisecond in plain JavaScript.
  2. An adaptive n-gram model of you. Hashed counts for contexts of 1, 2, 3, 4, 6 and 8 characters, built only from what you type. Each order's estimate uses the GRU's distribution as its prior, so unseen contexts fall back to the network.
  3. A geometric mixer (PAQ-style logistic mixing) that learns, per context, how much to trust each source. It starts as "pure GRU" and shifts towards your own patterns as they prove themselves.

On top of that the GRU's output layer is fine-tuned online with SGD on your text. Characters are learned three keystrokes late, so a typo you fix right away is never learned.

Numbers

  • Held-out text, before it knows you: 62.5% of next letters guessed right first try, 82% within the top three, 1.76 bits per character. Int8 quantisation costs nothing measurable.
  • Learning: on 20k characters of unseen Markdown READMEs, typed once, accuracy rose from 40% (frozen model) to 53% within that single pass.
  • Speed: about 0.2 ms per keystroke in Node, ~0.4 ms in Chrome. 100 wpm is one key every ~120 ms, so it has several hundred times the headroom it needs.

What you've taught it (recent text, mixer weights and the output-layer changes) lives in localStorage. Nothing is sent anywhere. Forget me clears it.

Layout

  • docs/ is the GitHub Pages site: engine.js (the model and online learning), app.js (UI), model.bin (weights).
  • train/ holds the PyTorch side: prep.py builds the corpus, train.py trains the GRU (stateful truncated BPTT, so it behaves like the endless keystroke stream it sees in the browser) and export.py quantises it to docs/model.bin and checks the int8 accuracy.
  • test/sim.mjs replays a text file keystroke by keystroke through the real engine, with typos and backspaces, and reports accuracy and latency.
cd train && uv venv .venv && uv pip install --python .venv/bin/python torch numpy pyarrow
.venv/bin/python prep.py && .venv/bin/python train.py && .venv/bin/python export.py
node test/sim.mjs some-text.txt 2

About

A tiny in-browser model that guesses your next letter and learns how you type

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages