juliaoverflow commited on
Commit
1cc24ff
·
verified ·
1 Parent(s): 86c6a0a

Add the model card

Browse files
Files changed (1) hide show
  1. README.md +122 -0
README.md ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: picacho
4
+ tags:
5
+ - email
6
+ - smart-reply
7
+ - multilingual
8
+ ---
9
+
10
+ # Echo Replies: the reply suggestion model
11
+
12
+ The model behind **Settings → Local AI → Suggest replies**. It reads a
13
+ received message and offers a few short replies under it, worded in the
14
+ message's language: a meeting request gets "That works for me." and "Let me
15
+ check my calendar.", a German one "Das passt mir." and "Ich schaue in meinen
16
+ Kalender.", news of a new job "Congratulations!". Choosing one starts a reply
17
+ with it written in, ready to send or to go on writing.
18
+
19
+ It doesn't write text. It picks from the replies in `catalog.json`: 59 of
20
+ them, each worded by hand in 37 languages (38 codes: Chinese in simplified
21
+ and traditional characters). So every suggestion is a sentence a person
22
+ wrote, and the model stays small and fast enough to run whenever a message
23
+ opens.
24
+
25
+ | File | Used on | Runtime |
26
+ | --- | --- | --- |
27
+ | `replies-v1.bin` | every platform | Picacho's own (`NativeTagger` in `src/manage/local_ai/runtime.rs`) |
28
+
29
+ Like the other models, it isn't kept in git: it is published on Hugging Face
30
+ as [pinaltech/echo-replies](https://huggingface.co/pinaltech/echo-replies),
31
+ and Picacho downloads it from there when the feature is turned on, checking
32
+ its size and SHA-256 (`REPLIES` in `src/manage/local_ai/mod.rs`). A model
33
+ trained again here with `train.py` needs a new file name, size and digest
34
+ there, and publishing.
35
+
36
+ ## Languages
37
+
38
+ English, Spanish, German, French, Portuguese, Italian, Dutch, Swedish,
39
+ Danish, Norwegian, Polish, Russian, Ukrainian, Czech, Slovak, Croatian,
40
+ Bulgarian, Romanian, Hungarian, Finnish, Greek, Turkish, Arabic, Persian,
41
+ Hebrew, Hindi, Bengali, Indonesian, Malay, Vietnamese, Thai, Japanese,
42
+ Chinese (simplified and traditional), Korean, Tagalog, Swahili and Catalan:
43
+ the date model's languages.
44
+
45
+ The wordings were written for this catalog and haven't been reviewed by
46
+ native speakers yet. Where a language marks the speaker's gender in the
47
+ verb (Hebrew, Hindi, Polish, Russian…), most wordings are phrased to avoid
48
+ it; a few in Hindi ("मैं इसे देखता हूँ।", "मैं जाँच करके बताता हूँ।") are
49
+ masculine. Review before relying on them.
50
+
51
+ ## How it works
52
+
53
+ 1. **Cleaning.** The body up to the sender's signature (`--`) or a
54
+ forwarded or quoted original (`-----`, `_____`), without quoted lines
55
+ (`>`), at most 4,000 characters.
56
+ 2. **Words.** The sign-in code model's (`../otp/features.py`): lowercase
57
+ runs of letters, marks and digits, with scripts written without spaces
58
+ split into pairs of characters.
59
+ 3. **Features.** The subject's words, the body's words and word pairs (the
60
+ first 160), the words of up to four lines that ask something (`?`, `?`,
61
+ `؟`), the **concepts** (`lexicon.json`) the body, those lines and the
62
+ subject name, how many questions there are, whether the message exclaims,
63
+ and its length. Concepts (invite, meet, call, thank, sorry, sick, late,
64
+ cancel, deadline, birthday, holiday, introduce, interview, invoice,
65
+ opinion, how-are-you, follow-up, news, loss, offer of help, automated…)
66
+ list word stems in every language above, so "Einladung", "invitación" and
67
+ "招待" all name *invite*. Everything is hashed into 32,768 slots.
68
+ 4. **Network.** The features, summed into 32 hidden units, then a softmax
69
+ over the 59 replies and "none" (mail that wants no reply). The embedding
70
+ is stored as 8-bit integers with a scale per row (the date model's
71
+ `PICAWHN1` format): about 1.2 MB.
72
+ 5. **Suggestions** (`src/manage/local_ai/replies.rs`). Nothing when "none"
73
+ wins; else the likeliest replies (at most four, each at least 3%),
74
+ worded in the message's language. The language is told from the script
75
+ of its letters and, among languages sharing one, their common words
76
+ (`stopwords.json`) and particular letters (ñ, ø, ő, ș…); when it can't be
77
+ told, the computer's language is used, or English. What the person
78
+ chooses makes it likelier (up to three times), and a reply turned away
79
+ ("Don't Suggest This") isn't offered again; this history stays on the
80
+ device and can be forgotten in Settings.
81
+
82
+ The app also offers nothing for mail from addresses like `no-reply@`, for
83
+ mailing lists (`List-Unsubscribe`), sign-in codes, receipts and package
84
+ updates, and for drafts and sent mail.
85
+
86
+ ## Data
87
+
88
+ `languages.py` and `phrases_a.py` to `phrases_d.py` write the mail; nothing in
89
+ it is real. For each language there are, for each of 33 situations
90
+ (thanks, a meeting request, an invitation, a request, a review, an
91
+ attachment, news, bad news, a sick day, running late, an apology, a yes/no
92
+ question, a call, a deadline, a check-in, wishes, an introduction, an
93
+ interview, praise, a cancellation, a follow-up…) and automated mail, a few
94
+ ways a message might say it, and greetings, small talk, sign-offs and
95
+ subjects to wrap them in; `SITUATIONS` says which replies fit each.
96
+ `data.py` builds messages of one or two situations, sometimes all lowercase,
97
+ without question marks or accents, and trains on the share of each
98
+ situation's fitting replies.
99
+
100
+ English has four wordings of each situation and the other languages two.
101
+ That is the model's main weakness: real mail says things in many more ways.
102
+ Training leaves out all the words of 30% of messages, keeping their
103
+ concepts, so wording it never saw still names concepts it knows; more
104
+ wordings, and native speakers' review of them, would help most.
105
+
106
+ ## Training
107
+
108
+ ```sh
109
+ python3 train.py --quick # a small run, scored on wording it never saw
110
+ python3 train.py # numpy only: replies-v1.bin, classes.json, parity.json, eval.json
111
+ ```
112
+
113
+ `train.py` first trains on half of the wordings and reports how the model
114
+ does on the other half, by language, then trains the published model on all
115
+ of them. Afterwards update `REPLIES`' size and SHA-256 in
116
+ `src/manage/local_ai/mod.rs`. `parity.json` holds messages whose features,
117
+ vectors and scores the app must reproduce (`cargo test replies`), and
118
+ `eval.json` held-out messages in every language, on which the app's tests
119
+ check that the language is told and the best suggestion fits.
120
+
121
+ `catalog.json`'s wordings can change without retraining. Its list of
122
+ replies can't: the model's outputs are in `classes.json`'s order.