pub struct GnnEncoder { /* private fields */ }Expand description
Multi-layer mean-aggregation GNN encoder.
After calling GnnEncoder::fit on a set of RDF triples the encoder can
produce a fixed-dimensional embedding for any entity seen during training
via GnnEncoder::embed_entity. Unknown entities return a zero vector.
Implementations§
Source§impl GnnEncoder
impl GnnEncoder
Sourcepub fn new(config: GnnEncoderConfig) -> Self
pub fn new(config: GnnEncoderConfig) -> Self
Create a new, untrained encoder.
Sourcepub fn fit(
&mut self,
triples: &[(String, String, String)],
) -> Result<(), GraphRAGError>
pub fn fit( &mut self, triples: &[(String, String, String)], ) -> Result<(), GraphRAGError>
Fit the encoder to the provided RDF triples.
Builds the adjacency graph, initialises embeddings and weight matrices, then runs stochastic gradient descent with a margin-based link-prediction loss.
Sourcepub fn embed_entity(&self, entity: &str) -> Vec<f64>
pub fn embed_entity(&self, entity: &str) -> Vec<f64>
Return the embedding vector for a named entity.
Returns a zero vector of length hidden_dim if the entity is unknown.
Sourcepub fn mean_aggregate(embeddings: &[&Vec<f64>]) -> Vec<f64>
pub fn mean_aggregate(embeddings: &[&Vec<f64>]) -> Vec<f64>
Compute the mean embedding of a non-empty slice of embedding vectors.
Sourcepub fn relu_and_normalize(v: &mut [f64])
pub fn relu_and_normalize(v: &mut [f64])
Apply ReLU activation then L2-normalise the vector in-place. If the L2 norm is near zero the vector is left unchanged.
Auto Trait Implementations§
impl Freeze for GnnEncoder
impl RefUnwindSafe for GnnEncoder
impl Send for GnnEncoder
impl Sync for GnnEncoder
impl Unpin for GnnEncoder
impl UnsafeUnpin for GnnEncoder
impl UnwindSafe for GnnEncoder
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
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