Skip to main content

RotatEScoring

Struct RotatEScoring 

Source
pub struct RotatEScoring {
    pub entity_re: Array2<f64>,
    pub entity_im: Array2<f64>,
    pub relation_phase: Array2<f64>,
    pub n_entities: usize,
    pub n_relations: usize,
    pub dim: usize,
}
Expand description

RotatE scoring model (Sun et al. 2019).

Entity embeddings are complex-valued: each entity e has a real part entity_re[e] and an imaginary part entity_im[e], both of shape (n_entities, dim/2) (so the full complex embedding has dim real parameters per entity).

Relation embeddings are phase angles θ_r ∈ (−π, π] of shape (n_relations, dim/2). The unit-modulus rotation vector is r_e = cos(θ_r) + i sin(θ_r).

Score function (negated L2 in complex space):

  score(h, r, t) = − ‖ h_re ⊙ cos(θ_r) − h_im ⊙ sin(θ_r) − t_re
                      + i ( h_re ⊙ sin(θ_r) + h_im ⊙ cos(θ_r) − t_im ) ‖

Higher scores (less negative) imply a more plausible triple.

Fields§

§entity_re: Array2<f64>

Real part of entity embeddings (n_entities, dim).

§entity_im: Array2<f64>

Imaginary part of entity embeddings (n_entities, dim).

§relation_phase: Array2<f64>

Relation phase angles (n_relations, dim).

§n_entities: usize

Number of entities.

§n_relations: usize

Number of relation types.

§dim: usize

Half-embedding dimension (complex degree of freedom per entity/relation).

Implementations§

Source§

impl RotatEScoring

Source

pub fn new(n_entities: usize, n_relations: usize, dim: usize) -> Self

Create a new RotatE model with random initialisation.

Entity embeddings are Xavier-initialised; relation phases are uniform in (−π, π].

§Arguments
  • n_entities – Number of distinct entities.
  • n_relations – Number of distinct relation types.
  • dim – Complex embedding half-dimension (full parameter count per entity is 2 * dim).
Source

pub fn score_triple(&self, h: usize, r: usize, t: usize) -> f64

Compute the RotatE score for triple (h, r, t).

Returns the negated L2 norm of h ∘ r − t in complex space. Scores closer to 0 indicate a more plausible triple.

Trait Implementations§

Source§

impl Clone for RotatEScoring

Source§

fn clone(&self) -> RotatEScoring

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RotatEScoring

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl KgScorer for RotatEScoring

Source§

fn score(&self, h: usize, r: usize, t: usize) -> f64

Return a scalar score for the triple (h, r, t). Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V