ali77a commited on
Commit
61a4255
·
verified ·
1 Parent(s): 5935ae3

tinyfix-ar 1.0.0

Browse files
Files changed (9) hide show
  1. .gitattributes +2 -0
  2. README.md +73 -0
  3. kinds.json +12 -0
  4. manifest.json +32 -0
  5. model.onnx +3 -0
  6. neighbor_kinds.u8 +3 -0
  7. neighbors.u32 +3 -0
  8. valid.u8 +0 -0
  9. vocab.txt +0 -0
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ neighbor_kinds.u8 filter=lfs diff=lfs merge=lfs -text
37
+ neighbors.u32 filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: onnx
4
+ language: ar
5
+ tags:
6
+ - arabic
7
+ - autocorrect
8
+ - spelling-correction
9
+ - browser
10
+ - onnx
11
+ ---
12
+
13
+ # tinyfix-ar
14
+
15
+ A 9 MB model that fixes Arabic spelling as you type, in the browser. It catches mistakes spell checkers miss because the typed word is a real word or a common misspelling: `الى` → `إلى`, `المدرسه` → `المدرسة`, `الرياظ` → `الرياض`.
16
+
17
+ ![tinyfix-ar fixing Arabic spelling as it is typed](demo.gif)
18
+
19
+ **[Try it in your browser](https://tinyfix-ar.ali77dhamen.workers.dev)** · **[npm package](https://www.npmjs.com/package/tinyfix-ar)** · **[Code](https://github.com/y0u-0/tinyfix-ar)**
20
+
21
+ ```ts
22
+ import { loadTinyfixAr } from "tinyfix-ar";
23
+
24
+ const tinyfix = await loadTinyfixAr();
25
+ const { text } = await tinyfix.fix("ذهبت الى المدرسه في الرياظ");
26
+ // "ذهبت إلى المدرسة في الرياض"
27
+ ```
28
+
29
+ ## How it works
30
+
31
+ Each of the 100,000 words in the vocabulary has up to 8 precomputed candidates: curated confusions, spelling variants, sound-alikes and one-edit typos. The model reads 16 words to the left and 4 to the right, scores the typed word against its candidates, and swaps in the best one only when its margin passes a calibrated threshold. Typed Saudi dialect words have no candidates, so they are never changed.
32
+
33
+ - **Architecture:** 64-dim word vectors, two 512-unit GRUs (left and right context) and a dot product against candidate vectors. 8.9M parameters.
34
+ - **Size:** `model.onnx` is 9.0 MB (int8). The whole folder is 14 MB.
35
+ - **Thresholds:** one per kind of edit for valid words, and one for known misspellings, calibrated so it makes about 1 wrong change per 2,000 correct words. They are in `manifest.json`.
36
+
37
+ ## Files
38
+
39
+ | File | What it holds |
40
+ |---|---|
41
+ | `model.onnx` | The int8 model. Inputs `left`, `right`, `candidates`, `kinds`; output `scores`. |
42
+ | `vocab.txt` | 100,000 words, one per line. The line number is the token id. |
43
+ | `neighbors.u32` | Up to 8 candidate ids per word, little-endian uint32. |
44
+ | `neighbor_kinds.u8` | The kind of edit for each candidate. |
45
+ | `valid.u8` | 1 for words that are correct spellings in some context, 0 for known misspellings. |
46
+ | `kinds.json` | Edit kind names by id. |
47
+ | `manifest.json` | Context windows, vocabulary size and thresholds. |
48
+
49
+ ## Evaluation
50
+
51
+ Measured on the int8 model with the shipped thresholds, counting only the words it is built to fix.
52
+
53
+ | Test set | Mistakes fixed | Changes that are right | Wrong changes per 1,000 correct words |
54
+ |---|---:|---:|---:|
55
+ | QALB-2014 test (news comments) | 59.1% | 95.7% | 0.35 |
56
+ | QALB-2015 L1 test | 62.4% | 96.0% | 0.63 |
57
+ | ZAEBUC (university essays) | 54.8% | 95.2% | 0.54 |
58
+ | Saudi writing, standard Arabic | 60.5% | 97.1% | 0.00 |
59
+ | Clean held-out text | | | 0.38 |
60
+
61
+ ## Limits
62
+
63
+ - It fixes one word for another from its candidate list. It doesn't fix grammar, word order or words outside its vocabulary.
64
+ - On Saudi dialect text it fixes fewer mistakes (24%) and is right less often (73%) than on standard Arabic.
65
+ - It would rather miss a mistake than change a word you meant, so it misses about 4 in 10 of the mistakes it targets.
66
+
67
+ ## Training data
68
+
69
+ About 165M tokens: Arabic Wikipedia (CC BY-SA 3.0), FineWeb2-HQ and FineWeb2 Saudi sites (ODC-By), Hindawi books (CC BY 4.0), Arabic chat sets and Aya (Apache-2.0), Al Jazeera news, UN General Assembly text, QALB-2014 corrected text and about 8,500 hand-checked sentences. Training makes mistakes by swapping words for their candidates and for known misspellings. The test sets come from CAMeL Lab's `arabic-gec` repository and were not used for training.
70
+
71
+ ## License
72
+
73
+ MIT.
kinds.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "typed": 0,
3
+ "hamza": 1,
4
+ "taa_marbuta": 2,
5
+ "alif_maqsura": 3,
6
+ "alif_fariqa": 4,
7
+ "spelling_mixed": 5,
8
+ "sound_alike": 6,
9
+ "clitic": 7,
10
+ "typo": 8,
11
+ "other": 9
12
+ }
manifest.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "left_window": 16,
3
+ "right_window": 4,
4
+ "candidates": 9,
5
+ "vocabulary": 100000,
6
+ "thresholds": {
7
+ "misspelled": -1.5773,
8
+ "valid": {
9
+ "typo": 8.9871,
10
+ "alif_maqsura": 2.9935,
11
+ "taa_marbuta": 3.4579,
12
+ "sound_alike": 4.2528,
13
+ "hamza": 2.1668,
14
+ "default": 5.2339
15
+ }
16
+ },
17
+ "export": {
18
+ "parity_cases": 4315,
19
+ "model-fp32.onnx": {
20
+ "mb": 35.51,
21
+ "max_score_difference": 0.0101,
22
+ "pick_agreement": 1.0,
23
+ "mean_margin_difference": 0.0
24
+ },
25
+ "model.onnx": {
26
+ "mb": 9.03,
27
+ "max_score_difference": 5.4233,
28
+ "pick_agreement": 0.9717,
29
+ "mean_margin_difference": 0.3771
30
+ }
31
+ }
32
+ }
model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1a799fbc68ff6ee1547228df41179e4f34c173de21c0233bd7cd8a3afa4c04b8
3
+ size 9027149
neighbor_kinds.u8 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:872f76a9e8d5c690d024290820fd21476e271be7fd3f2e387358373550a3907d
3
+ size 800000
neighbors.u32 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9314d8dd21b85abf5d221ebcf5b134c7ee3b4010a340bb534e83331453f6b341
3
+ size 3200000
valid.u8 ADDED
Binary file (100 kB). View file
 
vocab.txt ADDED
The diff for this file is too large to render. See raw diff