pub struct WeightLearner { /* private fields */ }Expand description
Weight learner for EnsembleNER.
Learns optimal backend weights from evaluation data.
§Example
ⓘ
use anno::backends::ensemble::{EnsembleNER, WeightLearner};
let mut learner = WeightLearner::new();
// Add training examples from gold data
for (text, gold_entities) in gold_data {
learner.add_examples(&text, &gold_entities, &backends);
}
// Learn weights
let learned_weights = learner.learn_weights();
// Create ensemble with learned weights
let ensemble = EnsembleNER::new().with_weights(learned_weights);Implementations§
Source§impl WeightLearner
impl WeightLearner
Sourcepub fn with_smoothing(self, smoothing: f64) -> Self
pub fn with_smoothing(self, smoothing: f64) -> Self
Set smoothing factor.
Sourcepub fn add_example(&mut self, example: &WeightTrainingExample)
pub fn add_example(&mut self, example: &WeightTrainingExample)
Add a training example.
Sourcepub fn add_from_backends(
&mut self,
text: &str,
gold_entities: &[Entity],
backends: &[(&str, &dyn Model)],
)
pub fn add_from_backends( &mut self, text: &str, gold_entities: &[Entity], backends: &[(&str, &dyn Model)], )
Add examples from gold entities and backend predictions.
Runs each backend on the text and compares to gold entities.
Sourcepub fn learn_weights(&self) -> HashMap<String, BackendWeight>
pub fn learn_weights(&self) -> HashMap<String, BackendWeight>
Learn optimal weights from accumulated statistics.
Uses precision-based weighting with Laplace smoothing.
Sourcepub fn get_stats(&self, backend_name: &str) -> Option<&BackendStats>
pub fn get_stats(&self, backend_name: &str) -> Option<&BackendStats>
Get statistics for a backend.
Sourcepub fn backend_names(&self) -> Vec<&String>
pub fn backend_names(&self) -> Vec<&String>
Get all backend names.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WeightLearner
impl RefUnwindSafe for WeightLearner
impl Send for WeightLearner
impl Sync for WeightLearner
impl Unpin for WeightLearner
impl UnsafeUnpin for WeightLearner
impl UnwindSafe for WeightLearner
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