pub struct RotatE { /* private fields */ }Expand description
RotatE: rotation in complex space.
Entities are complex vectors. Relations are element-wise rotations (unit-modulus complex numbers parameterized by angles).
Score: ||head * relation - tail||_2 where * is element-wise complex
multiplication and |relation_i| = 1.
Initialization: entities from Uniform(-gamma/sqrt(dim), gamma/sqrt(dim)),
relation angles from Uniform(-pi, pi).
Reference: Sun et al. (2019), “RotatE: Knowledge Graph Embedding by Relational Rotation in Complex Space.”
Implementations§
Source§impl RotatE
impl RotatE
Sourcepub fn new(
num_entities: usize,
num_relations: usize,
dim: usize,
gamma: f32,
) -> Self
pub fn new( num_entities: usize, num_relations: usize, dim: usize, gamma: f32, ) -> Self
Create a new RotatE model with random initialization.
dim is the complex dimension (each entity stores 2 * dim floats).
gamma is the margin, used to scale entity initialization to
Uniform(-gamma/sqrt(dim), gamma/sqrt(dim)).
Sourcepub fn from_vecs(
entities: Vec<Vec<f32>>,
relation_angles: Vec<Vec<f32>>,
dim: usize,
gamma: f32,
) -> Self
pub fn from_vecs( entities: Vec<Vec<f32>>, relation_angles: Vec<Vec<f32>>, dim: usize, gamma: f32, ) -> Self
Create from pre-built embedding vectors.
entities must have inner length dim * 2 (interleaved re/im).
relation_angles must have inner length dim.
§Panics
Panics if any dimension is wrong.
Sourcepub fn relation_angles(&self) -> &[Vec<f32>]
pub fn relation_angles(&self) -> &[Vec<f32>]
Relation angles.
Trait Implementations§
Source§impl Scorer for RotatE
impl Scorer for RotatE
Source§fn score(&self, head: usize, relation: usize, tail: usize) -> f32
fn score(&self, head: usize, relation: usize, tail: usize) -> f32
(head, relation, tail). Lower = more likely.Source§fn num_entities(&self) -> usize
fn num_entities(&self) -> usize
Source§fn score_all_tails(&self, head: usize, relation: usize) -> Vec<f32>
fn score_all_tails(&self, head: usize, relation: usize) -> Vec<f32>
(head, relation, ?). Read moreSource§fn score_all_heads(&self, relation: usize, tail: usize) -> Vec<f32>
fn score_all_heads(&self, relation: usize, tail: usize) -> Vec<f32>
(?, relation, tail).Auto Trait Implementations§
impl Freeze for RotatE
impl RefUnwindSafe for RotatE
impl Send for RotatE
impl Sync for RotatE
impl Unpin for RotatE
impl UnsafeUnpin for RotatE
impl UnwindSafe for RotatE
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> 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