GautamKishore commited on
Commit
3cc07ff
·
verified ·
1 Parent(s): 266dd98

Upload MODEL_CARD.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. MODEL_CARD.md +62 -166
MODEL_CARD.md CHANGED
@@ -9,175 +9,78 @@ tags:
9
  - matryoshka
10
  - lightweight
11
  - classifier
12
- - multi-head
13
- - clipboard
14
  pipeline_tag: text-classification
15
  library_name: pico-type
16
- co2_eq_emissions: 0.02
17
- model-index:
18
- - name: pico-type
19
- results:
20
- - task:
21
- type: text-classification
22
- name: Multi-Head Content Classification
23
- metrics:
24
- - type: accuracy
25
- value: 0.998
26
- name: Coarse Accuracy
27
- - type: accuracy
28
- value: 1.0
29
- name: Modality Accuracy
30
- - type: accuracy
31
- value: 0.947
32
- name: Subtype Accuracy
33
- - type: accuracy
34
- value: 0.387
35
- name: Code Language Accuracy
36
- - type: accuracy
37
- value: 0.988
38
- name: Text Language Accuracy
39
- - type: accuracy
40
- value: 1.0
41
- name: File MIME Accuracy
42
- - type: average_precision
43
- value: 1.0
44
- name: Risk Average Precision
45
  ---
46
 
47
  # pico-type
48
 
49
- **A tiny byte-level multi-head content classifier** (~1.5M parameters) built by [**eulogik**](https://eulogik.com).
50
-
51
- Classifies any content into **7 categories** simultaneously from raw bytes in a single forward pass — no tokenizer, no pretrained embeddings, no GPU required.
52
-
53
- ## Model Details
54
-
55
- | Property | Value |
56
- |----------|-------|
57
- | **Developer** | [eulogik](https://eulogik.com) |
58
- | **Release Date** | June 2026 |
59
- | **License** | Apache 2.0 |
60
- | **Model Type** | Byte-level neural classifier |
61
- | **Input** | Raw UTF-8 bytes (0–255), up to 1024 bytes |
62
- | **Output** | 7 classification heads |
63
- | **Parameters** | 1.43M–1.56M (4 Matryoshka tiers) |
64
- | **ONNX Size** | ~200 KB (FP32) |
65
- | **Inference** | ~5ms on CPU (base tier) |
66
- | **Training Hardware** | Apple M4 (MPS), 16GB |
67
 
68
  ## Architecture
69
 
70
  ```
71
- ByteEmbed(256→96d)Conv1D(k=3,5,7)BiAttention(RoPE) → Pool → Matryoshka Heads
72
  ```
73
 
74
- - **Byte-level**: No tokenizer, no subword vocabulary, no pretrained embeddings
75
- - **Matryoshka**: 4 tiered variants share the same trunk; head dimensions vary (16/64/192/576)
76
- - **Multi-head**: 7 independent classification heads trained jointly with per-task loss weighting
 
77
 
78
  ## Classification Heads
79
 
80
- | Head | Classes | Gated | Examples |
81
- |------|---------|-------|----------|
82
- | **coarse** | 12 | — | text, code, link, image, file, config, markup, data, error, secret, archive, binary |
83
- | **modality** | 8 | — | textual, binary_image, binary_archive, binary_executable, binary_document, binary_audio, binary_video, binary_other |
84
- | **subtype** | 24 | coarse∈{config,markup,data} | json, yaml, toml, ini, csv, html, xml, markdown, sql, log, diff, dockerfile |
85
- | **code_lang** | 62 | coarse=code | python, javascript, typescript, java, c, cpp, go, rust, swift, kotlin, bash, sql, ruby, php, perl, lua, r, julia, haskell, scala, dart, elixir, clojure, erlang, zig, nim |
86
- | **text_lang** | 30 | coarse=text | en, es, fr, de, it, pt, ru, zh, ja, ko, ar, hi, tr, nl, pl, sv, da, fi, nb, cs, hu, ro, uk, el, he, th, vi, id, ms, ta |
87
- | **file_mime** | 90 | coarse∈{image,file} | text/html, application/json, application/pdf, image/png, image/jpeg, video/mp4, audio/mpeg, application/zip |
88
- | **risk** | 6 | — | api_key, jwt, password, email, phone, ssh_key (independent probabilities) |
89
 
90
  ## Performance
91
 
92
- ### Synthetic Benchmark (1000 samples, base tier)
93
 
94
  | Head | Accuracy | Support |
95
  |------|----------|---------|
96
- | coarse | 99.8% | 1000 |
97
- | modality | 100.0% | 1000 |
98
- | subtype | 94.7% | ~250 |
99
- | code_lang | 38.7% | ~90 |
100
- | text_lang | 98.8% | ~80 |
101
- | file_mime | 100.0% | ~250 |
102
  | risk (mAP) | 100.0% | — |
103
 
104
- **Inference**: 5.0ms on M4 CPU via ONNX Runtime (base tier, 1024 bytes)
105
-
106
- ### Real-World Evaluation (21 hand-curated inputs)
107
-
108
- | Category | Accuracy |
109
- |----------|----------|
110
- | Coarse | **86%** (18/21) |
111
- | Modality | **100%** (21/21) |
112
- | Overall | **52%** (11/21 exact match) |
113
-
114
- _Diverse training improved real-world accuracy from 23% to 52%._
115
-
116
- ### Tier Comparison
117
-
118
- | Tier | Dim | Params | ONNX Size | Speed |
119
- |------|-----|--------|-----------|-------|
120
- | tiny | 16 | 1.43M | 8.7 MB | ~3ms |
121
- | small | 64 | 1.45M | 8.7 MB | ~4ms |
122
- | base | 192 | 1.48M | 8.8 MB | ~5ms |
123
- | pro | 576 | 1.56M | 9.1 MB | ~12ms |
124
-
125
- ## Training
126
-
127
- The model is trained using a multi-task loss:
128
-
129
- ```
130
- L = Σ w_h · L_h
131
- ```
132
-
133
- - **Single-label heads**: Cross-entropy with ignore_index=-100 for gated samples
134
- - **Risk head**: Binary cross-entropy
135
- - **Head weights**: coarse=8.0, modality=2.0, code_lang=2.0, text_lang=1.5, others=1.0
136
-
137
- ### Training Data
138
-
139
- 1. **Synthetic data** — 11 content buckets with per-language templates (62 code langs, 30 text langs, 90 MIME types, 22 binary formats)
140
- 2. **Diverse synthetic** — Realistic error traces, markdown with code blocks, nested configs, environment files, multi-language prose
141
- 3. **Real GitHub code** — ~650 files across 62 languages via GitHub Search API (30% training mix)
142
-
143
- ### Training Hyperparameters
144
 
145
- | Parameter | Value |
146
- |-----------|-------|
147
- | Optimizer | AdamW (β₁=0.9, β₂=0.999) |
148
- | Learning Rate | 3e-3 (cosine decay) |
149
- | Warmup Steps | 200 |
150
- | Weight Decay | 0.01 (trunk), 0.0 (heads) |
151
- | Batch Size | 16 |
152
- | Total Steps | 4000 |
153
- | Gradient Clip | 1.0 |
154
- | Hardware | Apple M4 16GB (MPS) |
155
 
156
  ## Usage
157
 
158
  ### CLI
159
  ```bash
160
- pip install picotype
161
  echo "def hello(): pass" | picotype --pretty
 
 
162
  picotype --file document.txt
 
 
163
  picotype --clip
164
  ```
165
 
166
  ### Python
167
  ```python
168
- from picotype import PicoType, PicoTypeConfig, load_checkpoint, decode_output
169
 
170
- model = PicoType(PicoTypeConfig()).eval()
171
- load_checkpoint("checkpoints/best.pt", model)
172
- logits = model(encode_bytes(b"input content"))
173
- result = decode_output(logits)
174
- ```
175
-
176
- ### ONNX Runtime
177
- ```python
178
- import onnxruntime as ort
179
- session = ort.InferenceSession("picotype_base.onnx")
180
- # input: int64[1, seq_len], bool[1, seq_len]
181
  ```
182
 
183
  ### MCP Server
@@ -187,44 +90,37 @@ PICOTYPE_MODEL_DIR=./checkpoints python -m model.pico_type.mcp_server
187
 
188
  ## Model Tiers
189
 
190
- All tiers share the same trunk; only the Matryoshka head linears differ. You can switch tiers at inference time with zero overhead:
 
 
 
 
 
191
 
192
- ```python
193
- logits_tiny = model(x, mask, tier="tiny")
194
- logits_base = model(x, mask, tier="base")
195
- ```
196
 
197
  ## Deployment
198
 
199
- | Platform | URL |
200
- |----------|-----|
201
- | HuggingFace Space | [eulogik/pico-type](https://huggingface.co/spaces/eulogik/pico-type) |
202
- | HuggingFace Model | [eulogik/pico-type](https://huggingface.co/eulogik/pico-type) |
203
- | GitHub | [eulogik/pico-type](https://github.com/eulogik/pico-type) |
204
- | PyPI | `pip install picotype` |
205
- | Zenodo | [10.5281/zenodo.20758542](https://doi.org/10.5281/zenodo.20758542) |
206
-
207
- ## Limitations
208
-
209
- - **code_lang accuracy**: 62-way classification with minimal per-class support. Real GitHub data helps (+10% absolute) but authentic code patterns (imports, type hints, decorators) remain challenging.
210
- - **Synthetic-only training**: Model overfits to template patterns. Diverse synthetic + real data significantly improves real-world robustness.
211
- - **Max input length**: 1024 bytes. Longer content is truncated.
212
- - **No fine-grained text understanding**: Designed for content classification, not NLP tasks like sentiment analysis or NER.
213
-
214
- ## Citation
215
-
216
- ```bibtex
217
- @software{eulogik2026picotype,
218
- author = {eulogik},
219
- title = {pico-type: A Tiny Byte-Level Multi-Head Content Classifier},
220
- year = {2026},
221
- url = {https://github.com/eulogik/pico-type},
222
- doi = {10.5281/zenodo.20758542}
223
- }
224
  ```
225
 
226
- ---
 
 
 
 
 
 
 
 
227
 
228
- <div align="center">
229
- <sub>Built by <a href="https://eulogik.com">eulogik</a> — AI infrastructure for developers.</sub>
230
- </div>
 
9
  - matryoshka
10
  - lightweight
11
  - classifier
 
 
12
  pipeline_tag: text-classification
13
  library_name: pico-type
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  ---
15
 
16
  # pico-type
17
 
18
+ A tiny **byte-level multi-head content classifier** (~1.5M parameters) that classifies any content into **7 categories** simultaneously from raw bytes — no tokenizer, no pretrained embeddings.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  ## Architecture
21
 
22
  ```
23
+ ByteEmbed → Conv1D×3 → BiAttention×2 → Pool → Matryoshka Heads
24
  ```
25
 
26
+ - **Byte-level**: operates directly on UTF-8 bytes, supports any language
27
+ - **Matryoshka heads**: 7 independent classification heads with 4 tiers (tiny/small/base/pro)
28
+ - **1.5M params**: fits in ~9MB single-file ONNX (FP32), runs in ~18ms on CPU
29
+ - **No tokenizer**: zero vocabulary dependencies
30
 
31
  ## Classification Heads
32
 
33
+ | Head | Classes | Description |
34
+ |------|---------|-------------|
35
+ | **coarse** | 12 | text, code, link, image, file, config, markup, data, error, secret, archive, binary |
36
+ | **modality** | 8 | textual, binary_image, binary_archive, binary_executable, binary_document, binary_audio, binary_video, binary_other |
37
+ | **subtype** | 24 | json, yaml, toml, ini, csv, html, xml, markdown, sql, log, diff, dockerfile, etc. |
38
+ | **code_lang** | 62 | python, javascript, typescript, java, c, cpp, go, rust, swift, bash, sql, etc. |
39
+ | **text_lang** | 30 | en, es, fr, de, it, pt, ru, zh, ja, ko, ar, hi, etc. |
40
+ | **file_mime** | 90 | text/html, application/json, application/pdf, image/png, video/mp4, etc. |
41
+ | **risk** | 6 | api_key, jwt, password, email, phone, ssh_key (probabilities) |
42
 
43
  ## Performance
44
 
45
+ Benchmarked on synthetic data (500 samples, 1024 bytes max, base tier, 1700 training steps):
46
 
47
  | Head | Accuracy | Support |
48
  |------|----------|---------|
49
+ | coarse | 100.0% | 500 |
50
+ | modality | 100.0% | 500 |
51
+ | subtype | 93.8% | 128 |
52
+ | code_lang | 41.7% | 48 |
53
+ | text_lang | 94.3% | 35 |
54
+ | file_mime | 100.0% | 131 |
55
  | risk (mAP) | 100.0% | — |
56
 
57
+ - **Inference**: ~18ms per sample on CPU (ONNX Runtime, M2)
58
+ - **Model size**: ~9.25MB single-file FP32 (base tier; 206 KB graph + 9.05 MB weights)
59
+ - **Loss**: 1.97 eval_loss (best, step 1700)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
+ > **code_lang** accuracy (54.2%) reflects 62-class coverage; improves with longer sequences (>256 bytes). v0.2 will target better code language discrimination.
 
 
 
 
 
 
 
 
 
62
 
63
  ## Usage
64
 
65
  ### CLI
66
  ```bash
67
+ # Pipe content
68
  echo "def hello(): pass" | picotype --pretty
69
+
70
+ # File
71
  picotype --file document.txt
72
+
73
+ # Clipboard (macOS)
74
  picotype --clip
75
  ```
76
 
77
  ### Python
78
  ```python
79
+ from model.pico_type.labels import decode_output
80
 
81
+ # Run with ONNX session
82
+ result = {"coarse": "code", "modality": "textual", ...}
83
+ decoded = decode_output(result, tier="base")
 
 
 
 
 
 
 
 
84
  ```
85
 
86
  ### MCP Server
 
90
 
91
  ## Model Tiers
92
 
93
+ | Tier | Head Dim | Params | ONNX Size |
94
+ |------|----------|--------|-----------|
95
+ | tiny | 16 | 1.43M | 9.09 MB |
96
+ | small | 64 | 1.45M | 9.13 MB |
97
+ | base | 192 | 1.48M | 9.25 MB |
98
+ | pro | 576 | 1.56M | 9.61 MB |
99
 
100
+ All tiers share the same trunk; only the final linear layer differs per tier.
 
 
 
101
 
102
  ## Deployment
103
 
104
+ ### HuggingFace Space
105
+ The [Gradio Space](https://huggingface.co/spaces/eulogik/pico-type) provides:
106
+ - Text input and file upload
107
+ - Real-time 7-head classification
108
+ - Tier selection (tiny/small/base/pro)
109
+
110
+ ### ONNX Runtime
111
+ ```python
112
+ import onnxruntime
113
+ session = ort.InferenceSession("picotype_base.onnx")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  ```
115
 
116
+ ## Training
117
+
118
+ Trained on synthetic data (11 content buckets, 62 code languages, 30 text languages, 90 MIME types) using multi-task loss with 500 optimization steps.
119
+
120
+ - **Loss**: weighted cross-entropy (coarse) + binary cross-entropy (risk)
121
+ - **Optimizer**: AdamW (lr=1e-3, weight_decay=0.01)
122
+ - **GPU**: ~100ms/step on MPS, ~3.5s/step on CPU
123
+
124
+ ## License
125
 
126
+ Apache 2.0