pub struct Embedding { /* private fields */ }Expand description
Embedding layer - lookup table for discrete tokens
Implementations§
Source§impl Embedding
impl Embedding
Sourcepub fn with_padding(
num_embeddings: usize,
embedding_dim: usize,
padding_idx: usize,
) -> Self
pub fn with_padding( num_embeddings: usize, embedding_dim: usize, padding_idx: usize, ) -> Self
Create embedding with padding index (embedding at padding_idx will be zeros)
Sourcepub fn from_pretrained(weight: Tensor, freeze: bool) -> Self
pub fn from_pretrained(weight: Tensor, freeze: bool) -> Self
Create embedding from pretrained weights
Sourcepub fn embedding_dim(&self) -> usize
pub fn embedding_dim(&self) -> usize
Get embedding dimension
Sourcepub fn num_embeddings(&self) -> usize
pub fn num_embeddings(&self) -> usize
Get number of embeddings
Sourcepub fn forward_indices(&self, indices: &[usize]) -> Tensor
pub fn forward_indices(&self, indices: &[usize]) -> Tensor
Forward pass with integer indices
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Embedding
impl !RefUnwindSafe for Embedding
impl Send for Embedding
impl Sync for Embedding
impl Unpin for Embedding
impl !UnwindSafe for Embedding
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> 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