pub struct NerRecognizer { /* private fields */ }Expand description
NER-based recognizer using ONNX Runtime
Status: ✅ Fully operational with complete ONNX Runtime integration
This recognizer uses transformer-based Named Entity Recognition models for contextual PII detection. It automatically loads and runs ONNX models with:
- Tokenization with HuggingFace tokenizers
- ONNX Runtime inference with optimizations
- BIO tag parsing for entity span extraction
- Thread-safe session management
To enable NER:
- Export your NER model to ONNX format using
scripts/export_ner_model.py - Set
model_pathto point to your.onnxfile - Optionally provide
tokenizer_pathor placetokenizer.jsonin the same directory
Without a model, this recognizer gracefully returns empty results and the system falls back to pattern-based detection (36+ entity types).
Implementations§
Source§impl NerRecognizer
impl NerRecognizer
Sourcepub fn from_file<P: AsRef<Path>>(model_path: P) -> Result<Self>
pub fn from_file<P: AsRef<Path>>(model_path: P) -> Result<Self>
Create a new NER recognizer from a model file.
Automatically loads config.json from the model directory (if present)
to get the correct id2label and label_mappings for the exported model.
Falls back to default CoNLL-2003 mappings when no config is found.
Sourcepub fn from_config(config: NerConfig) -> Result<Self>
pub fn from_config(config: NerConfig) -> Result<Self>
Create a new NER recognizer from configuration
Sourcepub fn is_available(&self) -> bool
pub fn is_available(&self) -> bool
Check if NER is available (model and tokenizer loaded)
Trait Implementations§
Source§impl Debug for NerRecognizer
impl Debug for NerRecognizer
Source§impl Recognizer for NerRecognizer
impl Recognizer for NerRecognizer
Source§fn supported_entities(&self) -> &[EntityType]
fn supported_entities(&self) -> &[EntityType]
Source§fn analyze(&self, text: &str, _language: &str) -> Result<Vec<RecognizerResult>>
fn analyze(&self, text: &str, _language: &str) -> Result<Vec<RecognizerResult>>
Source§fn supports_language(&self, language: &str) -> bool
fn supports_language(&self, language: &str) -> bool
Auto Trait Implementations§
impl !Freeze for NerRecognizer
impl RefUnwindSafe for NerRecognizer
impl Send for NerRecognizer
impl Sync for NerRecognizer
impl Unpin for NerRecognizer
impl UnsafeUnpin for NerRecognizer
impl UnwindSafe for NerRecognizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more