pub struct EmbeddingLayer<T: Float + Debug + ScalarOperand + Send + Sync + 'static> { /* private fields */ }Expand description
Input projection layer.
Optimization traces are continuous vectors, not token ids, so this is a
dense linear projection input @ W rather than a vocabulary lookup. The
previous implementation cast each float to a usize index, which mapped
every value in (-1, 1) onto row 0 and discarded the input entirely.
Implementations§
Source§impl<T: Float + Debug + ScalarOperand + Send + Sync + 'static> EmbeddingLayer<T>
impl<T: Float + Debug + ScalarOperand + Send + Sync + 'static> EmbeddingLayer<T>
Sourcepub fn new(input_dimension: usize, output_dimension: usize) -> Result<Self>
pub fn new(input_dimension: usize, output_dimension: usize) -> Result<Self>
Create a new input projection with Xavier-initialized weights.
Sourcepub fn forward(&self, input: &Array2<T>) -> Result<Array2<T>>
pub fn forward(&self, input: &Array2<T>) -> Result<Array2<T>>
Project a (sequence_length, input_dimension) matrix to the model dimension.
Sourcepub fn parameter_count(&self) -> usize
pub fn parameter_count(&self) -> usize
Get parameter count
Sourcepub fn set_weights(&mut self, weights: Array2<T>) -> Result<()>
pub fn set_weights(&mut self, weights: Array2<T>) -> Result<()>
Replace the projection weights
Auto Trait Implementations§
impl<T> Freeze for EmbeddingLayer<T>
impl<T> RefUnwindSafe for EmbeddingLayer<T>
impl<T> Send for EmbeddingLayer<T>
impl<T> Sync for EmbeddingLayer<T>
impl<T> Unpin for EmbeddingLayer<T>
impl<T> UnsafeUnpin for EmbeddingLayer<T>
impl<T> UnwindSafe for EmbeddingLayer<T>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.