pub struct LSTM<B>where
B: Backend,{ /* private fields */ }Expand description
A multi-step LSTM that unrolls an LSTMCell over the sequence dimension.
§Shapes
- input:
[batch, seq_len, input_size] - output:
[batch, seq_len, hidden_size] - h_n:
[batch, hidden_size] - c_n:
[batch, hidden_size]
Implementations§
Source§impl<B> LSTM<B>where
B: Backend,
impl<B> LSTM<B>where
B: Backend,
Sourcepub fn new(
input_size: usize,
hidden_size: usize,
use_bias: bool,
dtype: DType,
device: &<B as Backend>::Device,
) -> Result<LSTM<B>, Error>
pub fn new( input_size: usize, hidden_size: usize, use_bias: bool, dtype: DType, device: &<B as Backend>::Device, ) -> Result<LSTM<B>, Error>
Create a new LSTM layer.
Sourcepub fn forward(
&self,
x: &Tensor<B>,
hc0: Option<(&Tensor<B>, &Tensor<B>)>,
) -> Result<(Tensor<B>, (Tensor<B>, Tensor<B>)), Error>
pub fn forward( &self, x: &Tensor<B>, hc0: Option<(&Tensor<B>, &Tensor<B>)>, ) -> Result<(Tensor<B>, (Tensor<B>, Tensor<B>)), Error>
Forward pass over the full sequence.
x:[batch, seq_len, input_size]hc0: optional initial(h0, c0), each[batch, hidden_size]. If None, zeros are used.
Returns (output, (h_n, c_n)) where:
output:[batch, seq_len, hidden_size]h_n,c_n:[batch, hidden_size]
Sourcepub fn parameters(&self) -> Vec<Tensor<B>>
pub fn parameters(&self) -> Vec<Tensor<B>>
Return all trainable parameters.
Sourcepub fn named_parameters(&self) -> Vec<(String, Tensor<B>)>
pub fn named_parameters(&self) -> Vec<(String, Tensor<B>)>
Return all trainable parameters with names.
Auto Trait Implementations§
impl<B> Freeze for LSTM<B>
impl<B> RefUnwindSafe for LSTM<B>
impl<B> Send for LSTM<B>
impl<B> Sync for LSTM<B>
impl<B> Unpin for LSTM<B>
impl<B> UnwindSafe for LSTM<B>
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