pub struct EnsembleNER { /* private fields */ }Expand description
Ensemble NER that runs ALL backends and resolves conflicts via weighted voting.
Unlike StackedNER (priority-based cascade), EnsembleNER:
- Runs ALL backends in parallel (conceptually)
- Groups overlapping spans into conflict clusters
- Resolves via weighted voting with type-conditioned weights
- Applies agreement bonus when multiple backends agree
§When to Use
- EnsembleNER: Maximum accuracy, latency not critical
- StackedNER: Production, predictable latency, early exit
§Example
use anno::{EnsembleNER, Model, RegexNER, HeuristicNER};
// Default: uses all available backends
let ensemble = EnsembleNER::new();
// Custom: specific backends
let custom = EnsembleNER::with_backends(vec![
Box::new(RegexNER::new()),
Box::new(HeuristicNER::new()),
]);
let entities = custom.extract_entities("Contact us at test@example.com", None)?;§Algorithm
- Collect candidates: Run each backend, tag results with provenance
- Cluster overlaps: Group candidates with >50% span overlap
- Weighted vote: Score each candidate by
backend_weight * confidence - Agreement bonus: Add +0.10 when 2+ backends agree on type
- Select winner: Highest weighted score wins the cluster
Implementations§
Source§impl EnsembleNER
impl EnsembleNER
Sourcepub fn with_backends(backends: Vec<Box<dyn Model + Send + Sync>>) -> Self
pub fn with_backends(backends: Vec<Box<dyn Model + Send + Sync>>) -> Self
Create with custom backends.
Sourcepub fn with_weights(self, weights: HashMap<String, BackendWeight>) -> Self
pub fn with_weights(self, weights: HashMap<String, BackendWeight>) -> Self
Set custom backend weights.
Sourcepub fn with_agreement_bonus(self, bonus: f64) -> Self
pub fn with_agreement_bonus(self, bonus: f64) -> Self
Set the agreement bonus (added when multiple backends agree).
Sourcepub fn with_min_confidence(self, min: f64) -> Self
pub fn with_min_confidence(self, min: f64) -> Self
Set minimum confidence threshold.
Trait Implementations§
Source§impl BatchCapable for EnsembleNER
impl BatchCapable for EnsembleNER
Source§impl Default for EnsembleNER
impl Default for EnsembleNER
Source§impl Model for EnsembleNER
impl Model for EnsembleNER
Source§fn extract_entities(
&self,
text: &str,
language: Option<&str>,
) -> Result<Vec<Entity>>
fn extract_entities( &self, text: &str, language: Option<&str>, ) -> Result<Vec<Entity>>
Extract entities from text.
Source§fn supported_types(&self) -> Vec<EntityType>
fn supported_types(&self) -> Vec<EntityType>
Get supported entity types.
Source§fn is_available(&self) -> bool
fn is_available(&self) -> bool
Check if model is available and ready.
Source§fn description(&self) -> &'static str
fn description(&self) -> &'static str
Get a description of the model.
Source§fn capabilities(&self) -> ModelCapabilities
fn capabilities(&self) -> ModelCapabilities
Get capability summary for this model. Read more
Source§impl StreamingCapable for EnsembleNER
impl StreamingCapable for EnsembleNER
Source§fn recommended_chunk_size(&self) -> usize
fn recommended_chunk_size(&self) -> usize
Get the recommended chunk size for streaming extraction. Read more
impl NamedEntityCapable for EnsembleNER
Auto Trait Implementations§
impl !Freeze for EnsembleNER
impl !RefUnwindSafe for EnsembleNER
impl Send for EnsembleNER
impl Sync for EnsembleNER
impl Unpin for EnsembleNER
impl UnsafeUnpin for EnsembleNER
impl !UnwindSafe for EnsembleNER
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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