xezpeleta commited on
Commit
0a17629
Β·
verified Β·
1 Parent(s): 920873a

Add model card

Browse files
Files changed (1) hide show
  1. README.md +154 -0
README.md ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-sa-4.0
3
+ base_model: itzune/gector-eus-v2
4
+ language: eu
5
+ pipeline_tag: token-classification
6
+ tags:
7
+ - grammatical-error-correction
8
+ - gector
9
+ - basque
10
+ - euskara
11
+ - seq2edit
12
+ - error-type-classification
13
+ - multitask
14
+ - onnx
15
+ - in-browser
16
+ library_name: onnx
17
+ ---
18
+
19
+ # GECToR v2 ONNX β€” In-browser Basque Grammatical Error Correction
20
+
21
+ **int4-quantized ONNX** version of [`itzune/gector-eus-v2`](https://huggingface.co/itzune/gector-eus-v2)
22
+ for in-browser/edge deployment via ONNX Runtime Web (WASM) or
23
+ Transformers.js. ~83 MB download, ~50-100ms per sentence, runs on all
24
+ browsers (no WebGPU required).
25
+
26
+ This is the **explainable** GEC model β€” it outputs both corrections **and**
27
+ error-type labels (spelling, morphology, punctuation, etc.) per token,
28
+ enabling rich linting UIs like [txukun](https://github.com/itzune/txukun).
29
+
30
+ ## Model details
31
+
32
+ | | |
33
+ |---|---|
34
+ | **Architecture** | GECToR (RoBERTa-eus-base encoder + 3 heads: edit-label, detect, type) |
35
+ | **Source model** | [`itzune/gector-eus-v2`](https://huggingface.co/itzune/gector-eus-v2) |
36
+ | **Quantization** | int4 MatMul weights + int8 embeddings (via onnxruntime) |
37
+ | **Model size** | 83 MB (int4) / 128 MB (int8 fallback) |
38
+ | **License** | CC-BY-SA 4.0 |
39
+ | **Error types** | `none, spelling, punctuation, capitalization, word_level, zalantza, morphology, proper_noun, calque` |
40
+
41
+ ## ONNX outputs
42
+
43
+ The model takes `input_ids` + `attention_mask` and returns three logit tensors:
44
+
45
+ | Output | Shape | Description |
46
+ |--------|-------|-------------|
47
+ | `logits_labels` | `[batch, seq_len, 5000]` | Edit-label logits (GECToR tag vocabulary) |
48
+ | `logits_d` | `[batch, seq_len, 2]` | Detection logits (correct / incorrect) |
49
+ | `logits_t` | `[batch, seq_len, 9]` | Error-type logits (8 types + none) |
50
+
51
+ The `logits_t` output is **new in v2** β€” v1 only had `logits_labels` and
52
+ `logits_d`. This enables per-token error-type classification in the browser.
53
+
54
+ ## File structure
55
+
56
+ ```
57
+ gector-eus-v2-onnx/
58
+ β”œβ”€β”€ onnx/
59
+ β”‚ β”œβ”€β”€ model_q4.onnx # int4 (83 MB) β€” primary browser model
60
+ β”‚ └── model_quantized.onnx # int8 (128 MB) β€” fallback
61
+ β”œβ”€β”€ gector_vocab.json # label vocabulary + type vocab + config
62
+ β”œβ”€β”€ tokenizer.json # HF tokenizer (for AutoTokenizer)
63
+ β”œβ”€β”€ sentencepiece.bpe.model # SentencePiece model
64
+ β”œβ”€β”€ tokenizer_config.json
65
+ β”œβ”€β”€ special_tokens_map.json
66
+ β”œβ”€β”€ config.json # model config (reference)
67
+ β”œβ”€β”€ README.md
68
+ └── LICENSE
69
+ ```
70
+
71
+ ## Usage (browser)
72
+
73
+ ```javascript
74
+ import { AutoTokenizer } from '@huggingface/transformers';
75
+ import { InferenceSession, Tensor } from 'onnxruntime-web';
76
+
77
+ const REPO = 'itzune/gector-eus-v2-onnx';
78
+ const BASE = `https://huggingface.co/${REPO}/resolve/main`;
79
+
80
+ // Load tokenizer, vocab, and model
81
+ const [tokenizer, vocab, modelBuf] = await Promise.all([
82
+ AutoTokenizer.from_pretrained(REPO),
83
+ fetch(`${BASE}/gector_vocab.json`).then(r => r.json()),
84
+ fetch(`${BASE}/onnx/model_q4.onnx`).then(r => r.arrayBuffer()),
85
+ ]);
86
+
87
+ const session = await InferenceSession.create(modelBuf, {
88
+ executionProviders: ['wasm'],
89
+ });
90
+
91
+ // Tokenize (pre-tokenized input: punctuation split from words)
92
+ const words = 'Ni uste hiru hilabetez ohean egoteak eragin zidala .'.split(' ');
93
+ const enc = tokenizer(words, { add_special_tokens: true, padding: true, truncation: true });
94
+
95
+ // Run inference
96
+ const outputs = await session.run({
97
+ input_ids: new Tensor('int64', enc.input_ids.data, enc.input_ids.dims),
98
+ attention_mask: new Tensor('int64', enc.attention_mask.data, enc.attention_mask.dims),
99
+ });
100
+
101
+ // outputs.logits_labels β†’ [batch, seq_len, 5000] edit labels
102
+ // outputs.logits_d β†’ [batch, seq_len, 2] detection
103
+ // outputs.logits_t β†’ [batch, seq_len, 9] error types (NEW)
104
+ ```
105
+
106
+ See [`txukun/src/gector.js`](https://github.com/itzune/txukun/blob/main/src/gector.js)
107
+ for a full production implementation with iterative correction, verb-form
108
+ reinflection, and error-type surfacing.
109
+
110
+ ## Evaluation
111
+
112
+ See [`itzune/gector-eus-v2`](https://huggingface.co/itzune/gector-eus-v2) for
113
+ full evaluation results. Summary:
114
+
115
+ | Metric | Value |
116
+ |--------|-------|
117
+ | F0.5 (correction) | 77.6 |
118
+ | Exact match | 51.3% |
119
+ | Clean FP | 1.8% |
120
+ | Type accuracy (error words) | 75.8% |
121
+
122
+ Quantization (int4) has negligible impact on accuracy β€” the model is
123
+ robust to 4-bit weight quantization due to the large label vocabulary
124
+ (5000 labels) being stored in full precision.
125
+
126
+ ## Comparison with v1 ONNX
127
+
128
+ | | v1 (`gector-eus-onnx`) | **v2** (`gector-eus-v2-onnx`) |
129
+ |---|---|---|
130
+ | Error types | ❌ no type head | βœ… 8 categories |
131
+ | Model size | 87 MB | 83 MB |
132
+ | Training data | Elhuyar (NC license) | horkonpon (CC-BY-SA) |
133
+ | License | CC-BY-NC-SA 4.0 | **CC-BY-SA 4.0** (commercial OK) |
134
+ | Outputs | `logits_labels`, `logits_d` | + `logits_t` (error types) |
135
+
136
+ ## Citation
137
+
138
+ ```bibtex
139
+ @misc{ezpeleta2026gectoreusv2onnx,
140
+ author = {Ezpeleta, Xabi},
141
+ title = {GECToR v2 ONNX: In-browser Basque Grammatical Error Correction},
142
+ year = {2026},
143
+ howpublished = {Hugging Face model},
144
+ url = {https://huggingface.co/itzune/gector-eus-v2-onnx}
145
+ }
146
+ ```
147
+
148
+ ## Related
149
+
150
+ - [itzune/gector-eus-v2](https://huggingface.co/itzune/gector-eus-v2) β€” source PyTorch model
151
+ - [itzune/gector-eus-onnx](https://huggingface.co/itzune/gector-eus-onnx) β€” v1 ONNX (no type head, NC license)
152
+ - [itzune/gemma-4-e4b-horkonpon](https://huggingface.co/itzune/gemma-4-e4b-horkonpon) β€” LLM-based Basque GEC
153
+ - [horkonpon-corpus](https://github.com/itzune/horkonpon-corpus) β€” training data
154
+ - [txukun](https://github.com/itzune/txukun) β€” Basque writing assistant (consumes this model)