tinynext: suggests the next few words, Tab to take them

params: 12.5M size: 13.3 MB speed: ~5 ms runs: in browser data sent: none

Gray text that finishes your sentence.
A 13 MB model that runs in a browser tab.

Write with it in offlinepage.app →


tinynext is the autocomplete in offlinepage.app. It reads the text around the cursor and, when it's sure enough, shows the next few words in gray. Press Tab to take them. It runs in a Web Worker with ONNX Runtime Web, so nothing you type is sent anywhere.

The model the app uses is in v2/. The files at the root of this repo are v1, an earlier and much smaller character model, described at the end.

What it does

You type: Please accept my resignation. I will be o. You get: the same text with “ut of the office” offered in gray, and Tab to take it.

You type It suggests
Please accept my resignation. I will be o ut of the office
See you on the ground. I look f orward to

It stays quiet most of the time. A suggestion only appears when the model is at least 40% sure of the whole phrase, and it has to be four characters or longer.

How well it works

Every model here is scored the same way by v2/eval.py: type held-out text character by character, pause every 12 characters, and count a suggestion only if the text really continues that way. These numbers use a 50% cutoff; the app now uses 40%, so it suggests a little more often and is right a little less often.

How much typing it saves:

Writing v1 v2 SmolLM2-135M (about 100 MB)
Articles (Wikipedia) 1.5% 3.9% 8.1%
Messages (OpenAssistant) 2.0% 8.8% 16.8%
Email (Enron, unseen senders) 3.0% 4.0% 5.7%

How often it speaks up, and how often it's right:

Writing Suggests at Right 2+ words suggested at 2+ words right
Articles (Wikipedia) 10% 78% 4% 71%
Messages (OpenAssistant) 19% 75% 9% 70%
Email (Enron, unseen senders) 11% 78% 4% 51%

“Suggests at” is the share of pauses where it offered anything. “Right” means the suggestion exactly matched what the person typed next.

Limits

  • offlinepage.app only suggests at the end of a paragraph. Mid-line suggestions, where reading the text after the cursor should help most, aren't built yet.
  • It still leans toward office email, and it only sees keyboard characters.
  • English only.

In the browser

Setting Value
Download 13.3 MB: 8-bit weights with one scale per 64 values, expanded to float32 when the page loads
Matches full precision Same next word 96% of the time, same 5-word path 90%
Speed 5 ms per suggestion (13 ms at the slow end) in a Web Worker, Chrome on an M3 Max

The browser computes in float32 on purpose. ONNX Runtime Web's 8-bit kernels were 8 to 11 times slower than its float kernels for this model, and 8-bit activations changed the top word too often. Only the download is compressed.

How it was trained

The task. Predict the next word piece. Half of the training examples are fill-in-the-middle: the model also sees the text after a gap, so it can suggest in the middle of a paragraph as well as at the end.

The data. 3 billion tokens of writing like what people type: 60% FineWeb-Edu articles, 30% SmolTalk conversations and 10% Enron email, with the emails split by sender so the test senders are never seen.

The model. A small transformer that reads up to about 1,500 characters before the cursor.

Setting Value
Parameters 12.5 million
Layers / width / heads 8 / 320 / 5
Tokenizer 8,192 byte-level BPE pieces, so one step can be a whole word
Context 512 tokens
Training One pass over 3 billion tokens, batch 512, learning rate 0.003
Time 56 minutes on one A100 at 920,000 tokens a second, with Hugging Face Jobs
Validation loss 2.89

The data is tokenized once on a CPU job, and the GPU job trains from the prepared files. Training curves are on Trackio.

What the runs showed. Three runs of the same model, scored as typing saved on articles / messages / email. Editing is the same test with text after the cursor.

Run Training tokens Fill-in-the-middle Typing Editing Val loss
v2 (this one) 3B half the examples 3.9 / 8.8 / 4.0 3.1 / 7.6 / 4.2 2.89
First v2 1.5B half the examples 4.0 / 7.3 / 4.3 2.8 / 6.3 / 3.6 2.99
No fill-in-the-middle 1.5B none 3.9 / 8.8 / 4.2 3.0 / 6.9 / 4.1 2.94

At 1.5 billion tokens, fill-in-the-middle cost more than it gave: half the training went to a task the model rarely uses. With twice the tokens it stops costing anything on typing and helps when editing.

Would a bigger model help?

Pythia models are trained the same way at every size, so they show what size alone buys. Typing saved, 300 pauses per kind of writing (tinynext: 1,000):

Model Parameters Articles Messages Email
Pythia 14M 3.6% 6.1% 2.4%
Pythia 31M 4.0% 6.6% 4.0%
Pythia 70M 7.0% 8.0% 4.9%
Pythia 160M 7.3% 10.5% 7.9%
SmolLM2 135M 8.1% 16.8% 5.7%
tinynext v2 12.5M 3.9% 8.8% 4.0%

tinynext matches Pythia models two to three times its size because it trained on writing like what people type. Size starts to pay off between 30M and 70M parameters, and better data (SmolLM2) matters as much as size.

Train it yourself
# Prepare data once on a CPU job, then train on a GPU from the prepared files.
hf jobs uv run --flavor cpu-xl --secrets HF_TOKEN train.py --stage prepare --tokens 3e9 --fineweb-files 4
hf jobs uv run --flavor a100-large --secrets HF_TOKEN train.py --stage train --tokens 3e9 --fineweb-files 4
v2 files
File What it is
v2/web/graph.onnx, weights.q8, weights.json The browser model: graph, int8 weights and how to expand them
v2/web/tokenizer.json, config.json 8K byte-level BPE tokenizer and model shape
v2/model.safetensors Float32 weights
v2/train.py Data prep, training, eval, export and upload in one script
v2/eval.py, v2/eval_set.json The eval harness and the fixed text it scores
v2/export.py, v2/compress.py Re-export to ONNX, and the int8 download format
v2/metrics/*.json Eval results for v1, v2, the browser format, SmolLM2-135M and Pythia 14M–160M
v2/experiments/ The no-FIM run, for comparison
v2/report.json Training settings, loss history and export checks

v1: the original character model

The files at the root of this repo. v1 guesses one letter at a time, so its suggestions are short word endings. It has 944,000 parameters, is 0.98 MB, and learned only from Enron's emails. It is the same model as cfahlgren1/enron-autocomplete, and it has its own demo.

Everything about v1

What it does

It finishes the word or short phrase you're typing. Press Tab to take the suggestion.

You type It suggests
Please accept my resig nation
Please accept my resignation. I will be o ut of the office
The books are fine. Please call me i f you have any
Enron N orth America Corp.

How sure it has to be

The model knows how sure it is of each guess. You pick a cutoff, and it only suggests when it's at least that sure. A higher cutoff means fewer suggestions, and more of them right.

80%

of suggestions are right
at a 50% cutoff

11%

of the time it suggests
at a 50% cutoff

~6

characters per right suggestion
Cutoff How often it suggests How often it's right
20% 30% of the time 48%
35% 18% of the time 66%
50% 11% of the time 80%
70% 7% of the time 90%

The demo uses 40%.

These numbers come from 5,000 places in emails from people the model never saw in training. “Right” means the suggestion exactly matched what the person typed next.

Limits

  • It only knows office email from 2001. Outside that it has little to say.
  • With no cutoff it rambles. “Dear Santa,” becomes “I am attaching a copy of the agreement to the Enron Corp.”
  • It learned real names and sign-offs from the emails, so keep suggestions short.
  • English only.

Use it

The model takes one character and its memory of the text so far. It returns its guess for the next character and an updated memory. So each key press is one small step.

JavaScript example
import * as ort from "onnxruntime-web";

const session = await ort.InferenceSession.create("model_quint8.onnx", {
  executionProviders: ["wasm"],
});
let state = new ort.Tensor("float32", new Float32Array(512), [1, 512]);

async function step(id) {
  const input_id = new ort.Tensor("int64", BigInt64Array.of(BigInt(id)), [1]);
  const { logits, next_state } = await session.run({ input_id, state });
  state = next_state;
  return logits.data;
}

let logits = await step(1); // 1 starts a new email
for (const char of "Let me kn") logits = await step(char.charCodeAt(0) - 29);

A character's id is its character code minus 29. A new line is 2 and the end of an email is 1. Only English keyboard characters are supported.

To build a suggestion, keep taking the most likely next character and multiply the probabilities together as you go. Stop at a new line, or when that running product drops below your cutoff. Show the text up to the last finished word.

Files
File What it is
model_quint8.onnx The model to use. 0.98 MB.
model.onnx The same model before shrinking. 3.8 MB.
best.pt The PyTorch checkpoint.
vocab.json The character ids.
report.json The full training and test results.
train.py The training script.

I also tried a bigger version with 3.46M parameters and 3.5 MB. It wasn't better. When both models suggest equally often, 9% of the time, the small one is right about 85% of the time and the big one 82%. The big one got the same training settings and may need different ones to do well.

Training

It read 40 million characters from 119,859 emails sent from enron.com addresses, 30 times over. Typos were added to what it read, so it keeps predicting when you make one. The run took 14 minutes on one A10G with Hugging Face Jobs and cost 35 cents.

train.py is the whole thing: it downloads the emails, trains, tests and exports the model. To train your own:

hf jobs uv run --flavor a10g-large --secrets HF_TOKEN train.py --repo your-name/your-model

tinynext is one of two tiny models behind offlinepage.app, a writing app that works in airplane mode.
Its partner, tinyfix, fixes typos from context.
Both are made by paperweight, purpose-built small models.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Datasets used to train paperweight/tinynext

Space using paperweight/tinynext 1

Evaluation results

  • Typing saved (%) on Wikipedia articles (held out)
    self-reported
    3.900
  • Suggestions that were right (%) on Wikipedia articles (held out)
    self-reported
    78.000
  • Typing saved (%) on OpenAssistant messages, validation split
    self-reported
    8.800
  • Suggestions that were right (%) on OpenAssistant messages, validation split
    self-reported
    75.000
  • Typing saved (%) on Enron emails from held-out senders
    self-reported
    4.000
  • Suggestions that were right (%) on Enron emails from held-out senders
    self-reported
    78.000