Files
magpie/internal/pii/guard/testdata
yetone 6e9820a3a4 pii/guard: run AstrLink Guard's int8 model in Go (#3578)
AstrLink Guard (QuantumNous/astrlink-guard, Apache-2.0, on Microsoft's
MIT Multilingual-MiniLM-L12-H384) is a 36.9M-parameter BERT token
classifier for Chinese and English: 21 BIO labels (email, phone,
account, payment_card, ip_address, url, common_secret, private_address,
private_date, private_person), 512-token windows overlapping by 128,
a 0.8 score floor. Its int8 ONNX is 37 MB.

This package runs it with no new dependency and nothing native: an ONNX
protobuf reader for the graph and its external data (onnx.go), the
XLM-R Unigram tokenizer from tokenizer.json (tokenizer.go), and the
encoder with int8 x int8 matmuls (bert.go) on NEON/SDOT kernels on
arm64, SSE2 on amd64 and Go elsewhere (kernel*). Word embeddings stay
quantized (15 MB in memory, not 61 MB). uax29 moves from an indirect to
a direct requirement for the tokenizer's pre-split.

Checked against onnxruntime on the publisher's files: the same spans
on 69 of 71 eval texts, 232 of 234 real code segments and 24 of 25
positive samples; the rest differ by a span edge at the score floor.
One 512-token window takes ~0.5s CPU on arm64 and ~1.2s under Rosetta
on amd64, on a box at load ~100.

Run: go test ./internal/pii/guard (kernels against the Go reference,
tokenizer against the publisher's tokenizer on testdata/tokens.json),
gofmt -l, go vet, GOOS=linux go vet -tags nogui and GOOS=windows go
vet on amd64 and arm64, at the pushed head.
2026-10-27 02:01:16 +08:00
..