pub struct TrainableBox {
pub mu: Vec<f32>,
pub delta: Vec<f32>,
pub dim: usize,
}Expand description
A trainable box embedding with learnable parameters.
Uses reparameterization to ensure min <= max:
- min = mu - exp(delta)/2
- max = mu + exp(delta)/2
This ensures boxes are always valid (min <= max).
Fields§
§mu: Vec<f32>Mean position in each dimension (d-dimensional vector).
delta: Vec<f32>Log-width in each dimension (width = exp(delta)).
dim: usizeDimension
Implementations§
Source§impl TrainableBox
impl TrainableBox
Sourcepub fn new(mu: Vec<f32>, delta: Vec<f32>) -> Self
pub fn new(mu: Vec<f32>, delta: Vec<f32>) -> Self
Create a new trainable box.
§Arguments
mu- Mean position (center of box)delta- Log-width (width = exp(delta))
The box will have:
- min = mu - exp(delta) / 2
- max = mu + exp(delta) / 2
Sourcepub fn from_vector(vector: &[f32], init_width: f32) -> Self
pub fn from_vector(vector: &[f32], init_width: f32) -> Self
Initialize from a vector embedding.
Creates a small box around the vector with initial width init_width.
Sourcepub fn to_box(&self) -> BoxEmbedding
pub fn to_box(&self) -> BoxEmbedding
Convert to a BoxEmbedding (for inference).
Source§impl TrainableBox
impl TrainableBox
Sourcepub fn update_amsgrad(
&mut self,
grad_mu: &[f32],
grad_delta: &[f32],
state: &mut AMSGradState,
)
pub fn update_amsgrad( &mut self, grad_mu: &[f32], grad_delta: &[f32], state: &mut AMSGradState, )
Update box parameters using AMSGrad optimizer.
Trait Implementations§
Source§impl Clone for TrainableBox
impl Clone for TrainableBox
Source§fn clone(&self) -> TrainableBox
fn clone(&self) -> TrainableBox
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TrainableBox
impl Debug for TrainableBox
Source§impl<'de> Deserialize<'de> for TrainableBox
impl<'de> Deserialize<'de> for TrainableBox
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for TrainableBox
impl RefUnwindSafe for TrainableBox
impl Send for TrainableBox
impl Sync for TrainableBox
impl Unpin for TrainableBox
impl UnsafeUnpin for TrainableBox
impl UnwindSafe for TrainableBox
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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