tinynext card with banner
Browse files- README.md +70 -34
- banner.png +0 -0
README.md
CHANGED
|
@@ -10,66 +10,85 @@ tags:
|
|
| 10 |
- gru
|
| 11 |
- onnxruntime-web
|
| 12 |
- in-browser
|
|
|
|
| 13 |
---
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
A tiny email autocomplete that runs in your browser.
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
| Speed | about 4 ms per suggestion, on CPU in Chrome |
|
| 27 |
-
| Training | 14 minutes on one A10G with Hugging Face Jobs, 35 cents |
|
| 28 |
-
| Data | 119,859 Enron emails |
|
| 29 |
|
| 30 |
## What it does
|
| 31 |
|
| 32 |
-
It finishes the word or short phrase you're typing.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
| You type | It suggests |
|
| 35 |
|---|---|
|
| 36 |
-
| Please accept my resig | nation |
|
| 37 |
-
| Please accept my resignation. I will be o | ut of the office |
|
| 38 |
-
| The books are fine. Please call me i | f you have any |
|
| 39 |
-
| Enron N | orth America Corp. |
|
| 40 |
|
| 41 |
## How sure it has to be
|
| 42 |
|
| 43 |
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.
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
| Cutoff | How often it suggests | How often it's right |
|
| 46 |
|---|---|---|
|
| 47 |
| 20% | 30% of the time | 48% |
|
| 48 |
| 35% | 18% of the time | 66% |
|
| 49 |
-
| 50% | 11% of the time | 80% |
|
| 50 |
| 70% | 7% of the time | 90% |
|
| 51 |
|
| 52 |
-
The demo uses 40%.
|
| 53 |
-
|
| 54 |
-
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.
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|---|---|
|
| 60 |
-
| `model_quint8.onnx` | The model to use. 0.98 MB. |
|
| 61 |
-
| `model.onnx` | The same model before shrinking. 3.8 MB. |
|
| 62 |
-
| `best.pt` | The PyTorch checkpoint. |
|
| 63 |
-
| `vocab.json` | The character ids. |
|
| 64 |
-
| `report.json` | The full training and test results. |
|
| 65 |
-
| `train.py` | The training script. |
|
| 66 |
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
## Use it
|
| 70 |
|
| 71 |
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.
|
| 72 |
|
|
|
|
|
|
|
|
|
|
| 73 |
```js
|
| 74 |
import * as ort from "onnxruntime-web";
|
| 75 |
|
|
@@ -93,6 +112,24 @@ A character's id is its character code minus 29. A new line is 2 and the end of
|
|
| 93 |
|
| 94 |
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.
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
## Training
|
| 97 |
|
| 98 |
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.
|
|
@@ -103,9 +140,8 @@ It read 40 million characters from 119,859 emails sent from enron.com addresses,
|
|
| 103 |
hf jobs uv run --flavor a10g-large --secrets HF_TOKEN train.py --repo your-name/your-model
|
| 104 |
```
|
| 105 |
|
| 106 |
-
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
- English only.
|
|
|
|
| 10 |
- gru
|
| 11 |
- onnxruntime-web
|
| 12 |
- in-browser
|
| 13 |
+
- offline-page
|
| 14 |
---
|
| 15 |
|
| 16 |
+
<p align="center">
|
| 17 |
+
<img src="banner.png" alt="tinynext: suggests the next few words, Tab to take them" width="880">
|
| 18 |
+
</p>
|
| 19 |
|
| 20 |
+
<p align="center">
|
| 21 |
+
<img alt="params: 944K" src="https://img.shields.io/badge/params-944K-6e6e73?style=flat-square&labelColor=1d1d1f">
|
| 22 |
+
<img alt="size: 0.98 MB" src="https://img.shields.io/badge/size-0.98%20MB-6e6e73?style=flat-square&labelColor=1d1d1f">
|
| 23 |
+
<img alt="speed: ~4 ms / suggestion" src="https://img.shields.io/badge/speed-~4%20ms%20%2F%20suggestion-6e6e73?style=flat-square&labelColor=1d1d1f">
|
| 24 |
+
<img alt="trained: 14 min, $0.35" src="https://img.shields.io/badge/trained-14%20min,%20$0.35-6e6e73?style=flat-square&labelColor=1d1d1f">
|
| 25 |
+
<img alt="data: Enron email" src="https://img.shields.io/badge/data-Enron%20email-6e6e73?style=flat-square&labelColor=1d1d1f">
|
| 26 |
+
</p>
|
| 27 |
|
| 28 |
+
<h3 align="center">A tiny email autocomplete that runs in your browser.<br>It learned to write from Enron's emails.</h3>
|
| 29 |
|
| 30 |
+
<p align="center">
|
| 31 |
+
<a href="https://huggingface.co/spaces/cfahlgren1/enron-autocomplete"><b>Try the demo →</b></a>
|
| 32 |
+
·
|
| 33 |
+
<a href="https://github.com/cfahlgren1/offline-page"><b>Write with it in offline.page →</b></a>
|
| 34 |
+
</p>
|
| 35 |
|
| 36 |
+
<br>
|
| 37 |
+
|
| 38 |
+
tinynext is the autocomplete in [offline.page](https://github.com/cfahlgren1/offline-page). It's the same model as [`cfahlgren1/enron-autocomplete`](https://huggingface.co/cfahlgren1/enron-autocomplete), copied here under its new name.
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
## What it does
|
| 41 |
|
| 42 |
+
It finishes the word or short phrase you're typing. Press <kbd>Tab</kbd> to take the suggestion.
|
| 43 |
+
|
| 44 |
+
<p align="center">
|
| 45 |
+
<a href="https://huggingface.co/spaces/cfahlgren1/enron-autocomplete"><img src="hero.png" alt="Typing “Please accept my resignation. I will be o” and the model suggesting “ut of the office”" width="760"></a>
|
| 46 |
+
</p>
|
| 47 |
|
| 48 |
| You type | It suggests |
|
| 49 |
|---|---|
|
| 50 |
+
| Please accept my resig | **nation** |
|
| 51 |
+
| Please accept my resignation. I will be o | **ut of the office** |
|
| 52 |
+
| The books are fine. Please call me i | **f you have any** |
|
| 53 |
+
| Enron N | **orth America Corp.** |
|
| 54 |
|
| 55 |
## How sure it has to be
|
| 56 |
|
| 57 |
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.
|
| 58 |
|
| 59 |
+
<table>
|
| 60 |
+
<tr>
|
| 61 |
+
<td align="center" width="33%"><h2>80%</h2>of suggestions are right<br><sub>at a 50% cutoff</sub></td>
|
| 62 |
+
<td align="center" width="33%"><h2>11%</h2>of the time it suggests<br><sub>at a 50% cutoff</sub></td>
|
| 63 |
+
<td align="center" width="33%"><h2>~6</h2>characters per right suggestion</td>
|
| 64 |
+
</tr>
|
| 65 |
+
</table>
|
| 66 |
+
|
| 67 |
| Cutoff | How often it suggests | How often it's right |
|
| 68 |
|---|---|---|
|
| 69 |
| 20% | 30% of the time | 48% |
|
| 70 |
| 35% | 18% of the time | 66% |
|
| 71 |
+
| **50%** *(offline.page)* | **11% of the time** | **80%** |
|
| 72 |
| 70% | 7% of the time | 90% |
|
| 73 |
|
| 74 |
+
The demo uses 40%, and offline.page uses 50%.
|
|
|
|
|
|
|
| 75 |
|
| 76 |
+
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.
|
| 77 |
|
| 78 |
+
### Limits
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
+
- It only knows office email from 2001. Outside that it has little to say.
|
| 81 |
+
- With no cutoff it rambles. “Dear Santa,” becomes “I am attaching a copy of the agreement to the Enron Corp.”
|
| 82 |
+
- It learned real names and sign-offs from the emails, so keep suggestions short.
|
| 83 |
+
- English only.
|
| 84 |
|
| 85 |
## Use it
|
| 86 |
|
| 87 |
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.
|
| 88 |
|
| 89 |
+
<details>
|
| 90 |
+
<summary><b>JavaScript example</b></summary>
|
| 91 |
+
|
| 92 |
```js
|
| 93 |
import * as ort from "onnxruntime-web";
|
| 94 |
|
|
|
|
| 112 |
|
| 113 |
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.
|
| 114 |
|
| 115 |
+
</details>
|
| 116 |
+
|
| 117 |
+
<details>
|
| 118 |
+
<summary><b>Files</b></summary>
|
| 119 |
+
|
| 120 |
+
| File | What it is |
|
| 121 |
+
|---|---|
|
| 122 |
+
| `model_quint8.onnx` | The model to use. 0.98 MB. |
|
| 123 |
+
| `model.onnx` | The same model before shrinking. 3.8 MB. |
|
| 124 |
+
| `best.pt` | The PyTorch checkpoint. |
|
| 125 |
+
| `vocab.json` | The character ids. |
|
| 126 |
+
| `report.json` | The full training and test results. |
|
| 127 |
+
| `train.py` | The training script. |
|
| 128 |
+
|
| 129 |
+
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.
|
| 130 |
+
|
| 131 |
+
</details>
|
| 132 |
+
|
| 133 |
## Training
|
| 134 |
|
| 135 |
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.
|
|
|
|
| 140 |
hf jobs uv run --flavor a10g-large --secrets HF_TOKEN train.py --repo your-name/your-model
|
| 141 |
```
|
| 142 |
|
| 143 |
+
<br>
|
| 144 |
|
| 145 |
+
<p align="center">
|
| 146 |
+
<sub>tinynext is one of two tiny models behind <a href="https://github.com/cfahlgren1/offline-page">offline.page</a>, a writing app that works in airplane mode.<br>Its partner, <a href="https://huggingface.co/cfahlgren1/tinyfix">tinyfix</a>, fixes typos from context.</sub>
|
| 147 |
+
</p>
|
|
|
banner.png
ADDED
|