Files
README.md
# spacez spaCy's `en_core_web_sm` NER pipeline, reimplemented in zig. hash embeddings → residual CNN → BILUO transition parser, all from the original weights. no python, no runtime dependencies, ~6MB binary. ## install ```bash zig fetch --save https://tangled.sh/@zzstoatzz.io/spacez/archive/main ``` then in `build.zig`: ```zig const spacez = b.dependency("spacez", .{}).module("spacez"); exe.root_module.addImport("spacez", spacez); ``` ## usage ```zig const spacez = @import("spacez"); var model = try spacez.Model.load(spacez.en_core_web_sm); var entities: [64]spacez.SpanEntity = undefined; const n = spacez.recognize(&model, "Barack Obama visited Paris.", &entities); for (entities[0..n]) |e| { // e.label = .PERSON, .GPE, etc. // e.start / e.end = byte offsets into source text // e.margin = how far the winning action led its best alternative } ``` ## how sure was it? each span carries the parser's own decision data: - **`margin`** — the gap between the winning action's score and the best valid alternative at the moment it was chosen. a span built from several actions reports its weakest link, since a span is only as certain as the least certain decision behind it. `inf` when the winner had no valid competitor. - **`score`** — the winning action's raw output, likewise the minimum across the span. these are **not probabilities**. the parser decodes greedily with no softmax and no beam, so the numbers are unnormalized and carry no calibrated meaning on their own. `margin` is the more useful of the two: a gap is scale-relative, so it survives the shifts in raw score that come with different contexts. **what the runner-up usually is.** the competing action is most often a *different label for the same span*, not "no entity here". so a small margin tends to mean the parser was torn over the label, and says little about whether a span is an entity at all. measured on `en_core_web_sm`: | span | label | margin | |---|---|---| | `Paris` | GPE | 8.75 | | `Kira` | PERSON | 6.57 | | `Barack O…