pub struct TransEModel { /* private fields */ }Expand description
TransE knowledge graph embedding model.
Implementations§
Source§impl TransEModel
impl TransEModel
Sourcepub fn with_config(config: TransEConfig) -> Self
pub fn with_config(config: TransEConfig) -> Self
Create a new TransE model with the given configuration.
Sourcepub fn config(&self) -> &TransEConfig
pub fn config(&self) -> &TransEConfig
Get model configuration.
Sourcepub fn stats(&self) -> &TrainingStats
pub fn stats(&self) -> &TrainingStats
Get training statistics.
Sourcepub fn entity_count(&self) -> usize
pub fn entity_count(&self) -> usize
Number of entities.
Sourcepub fn relation_count(&self) -> usize
pub fn relation_count(&self) -> usize
Number of relations.
Sourcepub fn triple_count(&self) -> usize
pub fn triple_count(&self) -> usize
Number of known triples.
Sourcepub fn add_entity(&mut self, name: impl Into<String>) -> usize
pub fn add_entity(&mut self, name: impl Into<String>) -> usize
Register an entity and return its ID.
Sourcepub fn add_relation(&mut self, name: impl Into<String>) -> usize
pub fn add_relation(&mut self, name: impl Into<String>) -> usize
Register a relation and return its ID.
Sourcepub fn add_triple(
&mut self,
head: impl Into<String>,
relation: impl Into<String>,
tail: impl Into<String>,
)
pub fn add_triple( &mut self, head: impl Into<String>, relation: impl Into<String>, tail: impl Into<String>, )
Add a triple (by entity/relation names).
Sourcepub fn train(&mut self, epochs: usize) -> TrainingStats
pub fn train(&mut self, epochs: usize) -> TrainingStats
Train the model on the known triples.
Sourcepub fn score(&self, head: &str, relation: &str, tail: &str) -> Option<f64>
pub fn score(&self, head: &str, relation: &str, tail: &str) -> Option<f64>
Score a triple (lower score = better).
Sourcepub fn predict_tail(
&self,
head: &str,
relation: &str,
k: usize,
) -> Vec<ScoredTriple>
pub fn predict_tail( &self, head: &str, relation: &str, k: usize, ) -> Vec<ScoredTriple>
Predict the top-k tail entities given (head, relation, ?).
Sourcepub fn predict_head(
&self,
relation: &str,
tail: &str,
k: usize,
) -> Vec<ScoredTriple>
pub fn predict_head( &self, relation: &str, tail: &str, k: usize, ) -> Vec<ScoredTriple>
Predict the top-k head entities given (?, relation, tail).
Sourcepub fn entity_embedding(&self, name: &str) -> Option<&Vec<f64>>
pub fn entity_embedding(&self, name: &str) -> Option<&Vec<f64>>
Get the embedding for an entity.
Sourcepub fn relation_embedding(&self, name: &str) -> Option<&Vec<f64>>
pub fn relation_embedding(&self, name: &str) -> Option<&Vec<f64>>
Get the embedding for a relation.
Sourcepub fn nearest_entities(&self, query: &[f64], k: usize) -> Vec<(String, f64)>
pub fn nearest_entities(&self, query: &[f64], k: usize) -> Vec<(String, f64)>
Find nearest entities to a query embedding.
Sourcepub fn entity_name(&self, id: usize) -> Option<&str>
pub fn entity_name(&self, id: usize) -> Option<&str>
Get entity name by ID.
Sourcepub fn relation_name(&self, id: usize) -> Option<&str>
pub fn relation_name(&self, id: usize) -> Option<&str>
Get relation name by ID.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TransEModel
impl RefUnwindSafe for TransEModel
impl Send for TransEModel
impl Sync for TransEModel
impl Unpin for TransEModel
impl UnsafeUnpin for TransEModel
impl UnwindSafe for TransEModel
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