pub struct RelationClassifier { /* private fields */ }Expand description
Embedding-based relation classifier (logistic regression on MiniLM embeddings).
Implementations§
Source§impl RelationClassifier
impl RelationClassifier
Sourcepub fn new(model_path: &Path) -> Result<Self, RelError>
pub fn new(model_path: &Path) -> Result<Self, RelError>
Load the ONNX model from disk.
The model expects a single input “embedding” of shape [1, 384] and produces “logits” of shape [1, 10].
Sourcepub fn with_threshold(self, threshold: f32) -> Self
pub fn with_threshold(self, threshold: f32) -> Self
Set the confidence threshold for accepting a classification.
Sourcepub fn classify_embedding(
&self,
embedding: &[f32],
) -> Result<Option<(String, f32)>, RelError>
pub fn classify_embedding( &self, embedding: &[f32], ) -> Result<Option<(String, f32)>, RelError>
Classify a relation from a pre-computed 384-dim embedding.
Returns Some((relation_type, confidence)) if a relation is detected,
or None if the “none” class wins or confidence is below threshold.
Sourcepub fn classify_batch<F>(
&self,
text: &str,
entities: &[ExtractedEntity],
embed_fn: &F,
) -> Result<Vec<ExtractedRelation>, RelError>
pub fn classify_batch<F>( &self, text: &str, entities: &[ExtractedEntity], embed_fn: &F, ) -> Result<Vec<ExtractedRelation>, RelError>
Classify all unique entity pairs using entity-pair embeddings.
For each pair, generates 3 embeddings (head_ctx, tail_ctx, pair_ctx)
and concatenates them into a 1152-dim vector for classification.
embed_fn takes text and returns a 384-dim vector.
Auto Trait Implementations§
impl Freeze for RelationClassifier
impl !RefUnwindSafe for RelationClassifier
impl Send for RelationClassifier
impl Sync for RelationClassifier
impl Unpin for RelationClassifier
impl UnsafeUnpin for RelationClassifier
impl !UnwindSafe for RelationClassifier
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