pub struct BoxEmbeddingTrainer { /* private fields */ }Expand description
Trainer for box embedding models.
Implementations§
Source§impl BoxEmbeddingTrainer
impl BoxEmbeddingTrainer
Sourcepub fn new(
config: TrainingConfig,
dim: usize,
initial_embeddings: Option<HashMap<usize, Vec<f32>>>,
) -> Self
pub fn new( config: TrainingConfig, dim: usize, initial_embeddings: Option<HashMap<usize, Vec<f32>>>, ) -> Self
Create a new trainer.
§Arguments
config- Training configurationdim- Embedding dimensioninitial_embeddings- Optional initial vector embeddings (entity_id → vector)
Sourcepub fn initialize_boxes(
&mut self,
examples: &[TrainingExample],
initial_embeddings: Option<&HashMap<usize, Vec<f32>>>,
)
pub fn initialize_boxes( &mut self, examples: &[TrainingExample], initial_embeddings: Option<&HashMap<usize, Vec<f32>>>, )
Initialize boxes from entities.
Creates trainable boxes for all entities, either from provided vector embeddings or random initialization.
Key insight: For positive pairs (entities that corefer), initialize boxes to overlap so gradients can flow from the start.
§Arguments
examples- Training examples with entities and coreference chainsinitial_embeddings- Optional pre-computed vector embeddings (entity_id → vector) If provided, boxes are initialized around these vectors. If None, uses smart random initialization with shared centers for coreferent entities.
Sourcepub fn train(&mut self, examples: &[TrainingExample]) -> Vec<f32>
pub fn train(&mut self, examples: &[TrainingExample]) -> Vec<f32>
Train on a dataset with mini-batching and early stopping. Uses adaptive negative weighting: starts with low weight to learn positives, then gradually increases to separate negatives.
Sourcepub fn get_boxes(&self) -> HashMap<usize, BoxEmbedding>
pub fn get_boxes(&self) -> HashMap<usize, BoxEmbedding>
Get trained boxes for inference.
Sourcepub fn get_overlap_stats(&self, examples: &[TrainingExample]) -> (f32, f32, f32)
pub fn get_overlap_stats(&self, examples: &[TrainingExample]) -> (f32, f32, f32)
Get diagnostic statistics about box overlaps.
Returns (avg_positive_score, avg_negative_score, overlap_rate)
Sourcepub fn evaluate(
&self,
examples: &[TrainingExample],
threshold: f32,
) -> (f32, f32, f32, f32)
pub fn evaluate( &self, examples: &[TrainingExample], threshold: f32, ) -> (f32, f32, f32, f32)
Evaluate coreference accuracy on a test set.
Returns (accuracy, precision, recall, f1) where:
- Accuracy: fraction of pairs correctly classified
- Precision: fraction of predicted positives that are correct
- Recall: fraction of true positives that are predicted
- F1: harmonic mean of precision and recall
Note: This is a simple pair-wise evaluation. For standard coreference metrics
(MUC, B³, CEAF, LEA, BLANC, CoNLL F1), use evaluate_standard_metrics() instead.
Sourcepub fn load_boxes(
path: &str,
dim: usize,
) -> Result<HashMap<usize, TrainableBox>, Box<dyn Error>>
pub fn load_boxes( path: &str, dim: usize, ) -> Result<HashMap<usize, TrainableBox>, Box<dyn Error>>
Auto Trait Implementations§
impl Freeze for BoxEmbeddingTrainer
impl RefUnwindSafe for BoxEmbeddingTrainer
impl Send for BoxEmbeddingTrainer
impl Sync for BoxEmbeddingTrainer
impl Unpin for BoxEmbeddingTrainer
impl UnsafeUnpin for BoxEmbeddingTrainer
impl UnwindSafe for BoxEmbeddingTrainer
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