guard

package
v0.1.4607 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (

	// EmbedDim is the length of an embedding
	EmbedDim = hidden
)
View Source
const Floor = 0.5

Floor is the probability under which Find drops a span: the lowest threshold a user can set.

View Source
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

View Source
var EmbedFiles = []string{"model_int8.onnx", "tokenizer.json"}

EmbedFiles are the files LoadEmbedder reads, in its folder.

View Source
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

func LoadEmbedder(dir string) (*Embedder, error)

LoadEmbedder reads the model in dir.

func (*Embedder) Embed

func (e *Embedder) Embed(text string) []float32

Embed is text's embedding, of EmbedDim numbers and length 1: the same for a search and what it searches. A text past maxPos tokens is read to there.

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 Load

func Load(dir string) (*Model, error)

Load reads the model in dir.

func (*Model) Backend added in v0.1.1997

func (m *Model) Backend() (via, device string, err error)

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

func (m *Model) Find(text string) []Span

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.

type Span

type Span struct {
	Start, End int
	Label      string
	Score      float64
}

Span is what the model found: text[Start:End], a Label of its (email, phone, account, payment_card, ip_address, url, common_secret, private_address, private_date, private_person), and the least of its tokens' probabilities.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL