Text annotation and entity extraction.
Extract entity spans, coreference links, and common forms of personally identifiable information from text. Model-backed extractors are optional; the rule-based extractors work offline.
In Python, spaCy and GLiNER are the usual choices for NER and Microsoft Presidio
for PII detection; use anno for these tasks from Rust, with character offsets
and offline fallbacks.
[dependencies]
anno = "0.13"fn main() -> anno::Result<()> {
let entities = anno::extract("Sophie Wilson designed the ARM processor.")?;
for entity in entities {
println!(
"{} [{}] {}..{}",
entity.text,
entity.entity_type,
entity.start(),
entity.end()
);
}
Ok(())
}For repeated extraction, create and reuse a model rather than calling
anno::extract each time. Offsets are character offsets, not UTF-8 byte
offsets. Confidence scores are backend-local and are not calibrated across
backends.
Pattern-based PII redaction covers values such as email addresses, phone numbers, and identification numbers. The ID patterns are US-centric: US Social Security numbers (structure-checked), 16-digit card numbers (Luhn-checked) and IBANs (mod-97-checked); phone and address patterns follow US formats, and other national ID numbers are not covered.
use anno::pii;
let text = "John Smith's SSN is 123-45-6789.";
let redacted = pii::redact_patterns(text);
assert_eq!(redacted, "John Smith's SSN is [ID_NUMBER_1].");cargo install anno-cli$ ANNO_NO_DOWNLOADS=1 anno extract --model heuristic --text "Lynn Conway worked at IBM and Xerox PARC in California."
PER:1 "Lynn Conway"
ORG:2 "IBM" "Xerox PARC"
LOC:1 "California"This uses the offline heuristic backend. anno extract --format json emits
JSON. Run anno help <command> for command options.
The default onnx feature may download model weights on first use. Set
ANNO_NO_DOWNLOADS=1 to use only cached or local models; the default stack then
falls back to pattern and heuristic extractors when a model is unavailable.
The backend guide lists model identifiers, feature flags,
and hardware requirements.
This crate provides inference and annotation utilities, not model training. The minimum supported Rust version is 1.91.
Further documentation:
MIT or Apache-2.0.