pub struct CharacterEmbedding {
pub weight: Array2<f64>,
/* private fields */
}Expand description
Trainable character embedding layer.
Maps character indices to dense vectors.
Fields§
§weight: Array2<f64>Implementations§
Source§impl CharacterEmbedding
impl CharacterEmbedding
Sourcepub fn new(vocab_size: usize, embed_dim: usize) -> Self
pub fn new(vocab_size: usize, embed_dim: usize) -> Self
Create new embedding with random initialization.
Sourcepub fn new_zeros(vocab_size: usize, embed_dim: usize) -> Self
pub fn new_zeros(vocab_size: usize, embed_dim: usize) -> Self
Create embedding with zero initialization.
Sourcepub fn from_weights(weight: Array2<f64>) -> Self
pub fn from_weights(weight: Array2<f64>) -> Self
Create embedding from existing weights.
Sourcepub fn vocab_size(&self) -> usize
pub fn vocab_size(&self) -> usize
Get vocabulary size.
Sourcepub fn forward(&mut self, char_indices: &[usize]) -> Array2<f64>
pub fn forward(&mut self, char_indices: &[usize]) -> Array2<f64>
Forward pass for sequence of indices. Returns (seq_len, embed_dim) matrix.
Sourcepub fn backward(&self, grad_output: &Array2<f64>) -> EmbeddingGradients
pub fn backward(&self, grad_output: &Array2<f64>) -> EmbeddingGradients
Backward pass - compute gradients. grad_output shape: (seq_len, embed_dim)
Sourcepub fn update_parameters<O: Optimizer>(
&mut self,
gradients: &EmbeddingGradients,
optimizer: &mut O,
prefix: &str,
)
pub fn update_parameters<O: Optimizer>( &mut self, gradients: &EmbeddingGradients, optimizer: &mut O, prefix: &str, )
Update parameters with optimizer.
Sourcepub fn num_parameters(&self) -> usize
pub fn num_parameters(&self) -> usize
Get number of parameters.
Trait Implementations§
Source§impl Clone for CharacterEmbedding
impl Clone for CharacterEmbedding
Source§fn clone(&self) -> CharacterEmbedding
fn clone(&self) -> CharacterEmbedding
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 moreAuto Trait Implementations§
impl Freeze for CharacterEmbedding
impl RefUnwindSafe for CharacterEmbedding
impl Send for CharacterEmbedding
impl Sync for CharacterEmbedding
impl Unpin for CharacterEmbedding
impl UnwindSafe for CharacterEmbedding
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