Documentation
¶
Overview ¶
Package guard runs AstrLink Guard (QuantumNous/astrlink-guard, Apache-2.0), a token classifier for secrets and personal data in Chinese and English text: its int8 ONNX model (37 MB) read by onnx.go and run by bert.go on the CPU in Go, or on a Mac by CoreML (coreml.go), its tokenizer by tokenizer.go. Nothing is started.
Index ¶
Constants ¶
const (
// EmbedDim is the length of an embedding
EmbedDim = hidden
)
const Floor = 0.5
Floor is the probability under which Find drops a span: the lowest threshold a user can set.
const MinScore = 0.8
MinScore is the publisher's default threshold, under which masking drops a span unless the user set another (internal/masking).
Variables ¶
var EmbedFiles = []string{"model_int8.onnx", "tokenizer.json"}
EmbedFiles are the files LoadEmbedder reads, in its folder.
var Files = []string{"model_int8.onnx", "model_int8.onnx_data", "tokenizer.json"}
Files are the model's files Load reads, in its folder.
Functions ¶
func Cores ¶ added in v0.1.1891
func Cores() int
Cores is how many cores the model reads on at most: half of them, and never more than 4. It reads beside the agents and everything else on the computer, and on all of them a long history unread kept every core busy for as long as requests came (xinvxueyuan and shensmart on Discord, 10-28: a 32-core Linux box spent 45 CPU seconds on each request).
Types ¶
type Embedder ¶
type Embedder struct {
// contains filtered or unexported fields
}
Embedder is paraphrase-multilingual-MiniLM-L12-v2, loaded.
func LoadEmbedder ¶
LoadEmbedder reads the model in dir.
type Model ¶
type Model struct {
// MLErr is why CoreML isn't used, on a Mac.
MLErr error
// contains filtered or unexported fields
}
Model is the model, loaded.
func (*Model) Backend ¶ added in v0.1.1997
Backend is what reads the model now, as Settings › Privacy names it: via "CoreML" on the device its compute plan puts most of the program on ("Neural Engine", "GPU" or "CPU"; "" where the plan can't be read), or bert.go on the CPU (via ""), and then on a Mac why not CoreML: it couldn't be made, or its last read failed. Settings said "on the CPU" while CoreML read every window (yyhhyyyyyy on Discord, 10-27).
func (*Model) Find ¶
Find is what the model finds in text, at Floor, each span with its score. A text longer than a window is read a window at a time, overlapping. On the CPU those windows are read at once, one a core (of Cores()): a window's own matmuls split over the cores leave most of each idle in the steps between them (a 4-core server read a long prompt for minutes). Finds called at once share those cores (cores): a window takes one, waiting while others have them all, and splits its matmuls over as many more as are free, up to its share of them, so a lone short text is read on every core and several texts at once a core each.