enron-autocomplete
A tiny email autocomplete that runs in your browser. It learned to write from Enron's emails.
| Size | 944K parameters, 0.98 MB |
| Speed | about 4 ms per suggestion, on CPU in Chrome |
| Training | 14 minutes on one A10G with Hugging Face Jobs, 35 cents |
| Data | 119,859 Enron emails |
What it does
It finishes the word or short phrase you're typing.
| 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.
| 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. Right suggestions are about 6 characters long on average.
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.
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.
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.
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
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.
