Simplify model card
Browse files
README.md
CHANGED
|
@@ -3,75 +3,73 @@ license: apache-2.0
|
|
| 3 |
tags:
|
| 4 |
- syntax-highlighting
|
| 5 |
- python
|
| 6 |
-
- hand-designed
|
| 7 |
-
- no-training
|
| 8 |
---
|
| 9 |
|
| 10 |
# pylexnet
|
| 11 |
|
| 12 |
-
A
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
<video src="https://huggingface.co/Pranavz/pylexnet/resolve/main/demo.mp4" controls width="100%"></video>
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
## Try it
|
| 21 |
|
| 22 |
```bash
|
| 23 |
git clone https://huggingface.co/Pranavz/pylexnet && cd pylexnet
|
| 24 |
cc -O2 -o pylexnet pylexnet.c -lm
|
| 25 |
-
./pylexnet
|
| 26 |
-
./pylexnet --classes yourfile.py # one class id per byte
|
| 27 |
-
./pylexnet --interp --classes yourfile.py # generic reference evaluation of the same weights
|
| 28 |
```
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
|
| 33 |
-
|---|---|
|
| 34 |
-
|
|
| 35 |
-
|
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
|
| 40 |
-
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
## Speed
|
| 45 |
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
|
| 49 |
-
|---|---|
|
| 50 |
-
|
|
| 51 |
-
|
|
| 52 |
-
|
|
| 53 |
-
| tree-sitter-python, parse only |
|
| 54 |
-
| tree-sitter-python, parse
|
| 55 |
-
| Pygments `PythonLexer` | 1,153 |
|
| 56 |
|
| 57 |
-
|
| 58 |
|
| 59 |
-
##
|
| 60 |
|
| 61 |
-
|
| 62 |
-
-
|
| 63 |
-
-
|
| 64 |
-
-
|
| 65 |
-
- **Runtime:** `pylexnet_kernel.h` is the architecture generated as C, like lexnet's. Weight values live only in `pylexnet_weights.bin`. The loader checks a structure hash and guard inequalities. `--interp` runs the generic evaluation of the same weights.
|
| 66 |
|
| 67 |
-
`
|
| 68 |
|
| 69 |
-
##
|
| 70 |
|
| 71 |
-
|
| 72 |
-
- **`fast-994` keeps 220 of the words** and is exact on those, ranked by frequency in the tuning corpus.
|
| 73 |
-
- **Missing in the small builds:** soft keywords `match`/`case`, the space in `yield from`, two-level nested f-strings, `{x=}`, and `.5` floats after a dot. These are why their exact-file counts trail the accurate build.
|
| 74 |
-
- **Weights come from a generator script:** the network is designed by hand, unit by unit, but the numbers are produced by `compile.py`, not typed out.
|
| 75 |
-
- **Python 3.12 vocabulary, one Pygments version.** Results don't transfer automatically to other versions.
|
| 76 |
-
- **Speeds are from one machine.** The builds table is one 100 KB file.
|
| 77 |
-
- The tools in `tools/` were written for the development setup and may need paths adjusted.
|
|
|
|
| 3 |
tags:
|
| 4 |
- syntax-highlighting
|
| 5 |
- python
|
|
|
|
|
|
|
| 6 |
---
|
| 7 |
|
| 8 |
# pylexnet
|
| 9 |
|
| 10 |
+
A neural network for Python syntax highlighting, with hand-designed weights and no training data. It has 827 parameters, counting every non-zero value.
|
| 11 |
|
| 12 |
+
A Python counterpart to [lexnet](https://huggingface.co/alpindale/lexnet). Designed with Claude Fable 5.1 and Claude Opus 5.5.
|
| 13 |
|
| 14 |
<video src="https://huggingface.co/Pranavz/pylexnet/resolve/main/demo.mp4" controls width="100%"></video>
|
| 15 |
|
| 16 |
+
## Usage
|
|
|
|
|
|
|
| 17 |
|
| 18 |
```bash
|
| 19 |
git clone https://huggingface.co/Pranavz/pylexnet && cd pylexnet
|
| 20 |
cc -O2 -o pylexnet pylexnet.c -lm
|
| 21 |
+
./pylexnet file.py
|
|
|
|
|
|
|
| 22 |
```
|
| 23 |
|
| 24 |
+
`--classes` prints one class id per byte. `--interp` runs the generic evaluation of the same weights.
|
| 25 |
+
|
| 26 |
+
## Model details
|
| 27 |
|
| 28 |
+
| | |
|
| 29 |
+
|---|---|
|
| 30 |
+
| Type | Bidirectional recurrent network, per-byte sequence tagger |
|
| 31 |
+
| Task | Token classification over Python source |
|
| 32 |
+
| Input | Bytes |
|
| 33 |
+
| Output | One of 9 classes per byte |
|
| 34 |
+
| Parameters | 827 non-zero |
|
| 35 |
+
| Activations | `Clip(x, 0, hi)` |
|
| 36 |
+
| Vocabulary | 269 keywords, builtins and special method names |
|
| 37 |
+
| Training data | None |
|
| 38 |
+
| Training compute | None |
|
| 39 |
|
| 40 |
+
## Accuracy
|
| 41 |
|
| 42 |
+
Per-byte agreement with Pygments 2.17.2 on held-out code.
|
| 43 |
|
| 44 |
+
| Set | Size | Agreement | Exact files |
|
| 45 |
+
|---|---|---|---|
|
| 46 |
+
| Python 3.12 standard library | 5.8 MB | 99.996% | 264 / 293 |
|
| 47 |
+
| Third-party packages | 30 MB | 99.995% | 3,059 / 3,177 |
|
| 48 |
|
| 49 |
+
## Speed
|
| 50 |
|
| 51 |
+
293 files from the standard library, single core, Intel i5-9400F.
|
| 52 |
|
| 53 |
+
| Executor | ns/byte |
|
| 54 |
+
|---|---|
|
| 55 |
+
| Ruff parser | 14 |
|
| 56 |
+
| pylexnet, `builds/fast-994` | 63 |
|
| 57 |
+
| **pylexnet** | **94** |
|
| 58 |
+
| tree-sitter-python, parse only | 107 |
|
| 59 |
+
| tree-sitter-python, parse and highlight query | 165 |
|
| 60 |
+
| Pygments `PythonLexer` | 1,153 |
|
| 61 |
|
| 62 |
+
pylexnet figures are from `argparse.py`; the rest are corpus-wide. Ruff and tree-sitter build a syntax tree, which pylexnet does not.
|
| 63 |
|
| 64 |
+
## Other builds
|
| 65 |
|
| 66 |
+
| Build | Parameters | ns/byte | Third-party agreement |
|
| 67 |
+
|---|---|---|---|
|
| 68 |
+
| `builds/fast-994` | 994 | 63 | 99.9945% |
|
| 69 |
+
| `builds/accurate-7370` | 7,370 | 89 | 99.9992% |
|
|
|
|
| 70 |
|
| 71 |
+
`fast-994` shares one threshold weight across rows and keeps 220 of the words; counted per row it has 1,502 parameters. `accurate-7370` is a compiled automaton, not a hand-designed network.
|
| 72 |
|
| 73 |
+
## Limitations
|
| 74 |
|
| 75 |
+
Soft keywords (`match`, `case`), two-level nested f-strings and a few other cases aren't handled. The vocabulary matcher is approximate, so a few words such as `an` are flagged as keywords.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|