pub struct GRU<B>where
B: Backend,{ /* private fields */ }Expand description
A multi-step GRU that unrolls a GRUCell over the sequence dimension.
§Shapes
- input:
[batch, seq_len, input_size] - output:
[batch, seq_len, hidden_size] - h_n:
[batch, hidden_size]
Implementations§
Source§impl<B> GRU<B>where
B: Backend,
impl<B> GRU<B>where
B: Backend,
Sourcepub fn new(
input_size: usize,
hidden_size: usize,
use_bias: bool,
dtype: DType,
device: &<B as Backend>::Device,
) -> Result<GRU<B>, Error>
pub fn new( input_size: usize, hidden_size: usize, use_bias: bool, dtype: DType, device: &<B as Backend>::Device, ) -> Result<GRU<B>, Error>
Create a new GRU layer.
Sourcepub fn forward(
&self,
x: &Tensor<B>,
h0: Option<&Tensor<B>>,
) -> Result<(Tensor<B>, Tensor<B>), Error>
pub fn forward( &self, x: &Tensor<B>, h0: Option<&Tensor<B>>, ) -> Result<(Tensor<B>, Tensor<B>), Error>
Forward pass over the full sequence.
x:[batch, seq_len, input_size]h0: optional initial hidden state[batch, hidden_size]. If None, zeros are used.
Returns (output, h_n) where:
output:[batch, seq_len, hidden_size]h_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 GRU<B>
impl<B> RefUnwindSafe for GRU<B>
impl<B> Send for GRU<B>
impl<B> Sync for GRU<B>
impl<B> Unpin for GRU<B>
impl<B> UnwindSafe for GRU<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