pub struct BiRnn<B>where
B: Backend,{
pub forward: Rnn<B>,
pub reverse: Rnn<B>,
pub d_hidden: usize,
pub batch_first: bool,
}Expand description
The BiRnn module. This implementation is for Bidirectional RNN. Should be created with BiRnnConfig.
Fields§
§forward: Rnn<B>RNN for the forward direction.
reverse: Rnn<B>RNN for the reverse direction.
The size of the hidden state.
batch_first: boolIf true, input is [batch_size, seq_length, input_size].
If false, input is [seq_length, batch_size, input_size].
Implementations§
Source§impl<B> BiRnn<B>where
B: Backend,
impl<B> BiRnn<B>where
B: Backend,
Sourcepub fn forward(
&self,
batched_input: Tensor<B, 3>,
state: Option<RnnState<B, 3>>,
) -> (Tensor<B, 3>, RnnState<B, 3>)
pub fn forward( &self, batched_input: Tensor<B, 3>, state: Option<RnnState<B, 3>>, ) -> (Tensor<B, 3>, RnnState<B, 3>)
Applies the forward pass on the input tensor. This Bidirectional RNN implementation returns the state for each element in a sequence (i.e., across seq_length) and a final state.
§Parameters:
- batched_input: The input tensor of shape:
[batch_size, sequence_length, input_size]ifbatch_firstis true (default)[sequence_length, batch_size, input_size]ifbatch_firstis false
- state: An optional
RnnStaterepresenting the hidden state. Each state tensor has shape[2, batch_size, hidden_size]. If no initial state is provided, these tensors are initialized to zeros.
§Returns:
- output: A tensor represents the output features of RNN. Shape:
[batch_size, sequence_length, hidden_size * 2]ifbatch_firstis true[sequence_length, batch_size, hidden_size * 2]ifbatch_firstis false
- state: A
RnnStaterepresents the final forward and reverse states. Thestate.hiddenhave the shape[2, batch_size, hidden_size].
Trait Implementations§
Source§impl<B> AutodiffModule<B> for BiRnn<B>
impl<B> AutodiffModule<B> for BiRnn<B>
Source§type InnerModule = BiRnn<<B as AutodiffBackend>::InnerBackend>
type InnerModule = BiRnn<<B as AutodiffBackend>::InnerBackend>
Inner module without auto-differentiation.
Source§fn valid(&self) -> <BiRnn<B> as AutodiffModule<B>>::InnerModule
fn valid(&self) -> <BiRnn<B> as AutodiffModule<B>>::InnerModule
Returns the same module, but on the inner backend without auto-differentiation.
Source§fn from_inner(module: <BiRnn<B> as AutodiffModule<B>>::InnerModule) -> BiRnn<B>
fn from_inner(module: <BiRnn<B> as AutodiffModule<B>>::InnerModule) -> BiRnn<B>
Wraps an inner module back into an auto-diff module.
Source§impl<B> HasAutodiffModule<B> for BiRnn<<B as AutodiffBackend>::InnerBackend>
impl<B> HasAutodiffModule<B> for BiRnn<<B as AutodiffBackend>::InnerBackend>
Source§type TrainModule = BiRnn<B>
type TrainModule = BiRnn<B>
The module with auto-differentiation.
Source§impl<B> Module<B> for BiRnn<B>where
B: Backend,
impl<B> Module<B> for BiRnn<B>where
B: Backend,
Source§type Record = BiRnnRecord<B>
type Record = BiRnnRecord<B>
Type to save and load the module.
Source§fn load_record(self, record: <BiRnn<B> as Module<B>>::Record) -> BiRnn<B>
fn load_record(self, record: <BiRnn<B> as Module<B>>::Record) -> BiRnn<B>
Load the module state from a record.
Source§fn into_record(self) -> <BiRnn<B> as Module<B>>::Record
fn into_record(self) -> <BiRnn<B> as Module<B>>::Record
Convert the module into a record containing the state.
Source§fn num_params(&self) -> usize
fn num_params(&self) -> usize
Get the number of parameters the module has, including all of its sub-modules.
Source§fn visit<Visitor>(&self, visitor: &mut Visitor)where
Visitor: ModuleVisitor<B>,
fn visit<Visitor>(&self, visitor: &mut Visitor)where
Visitor: ModuleVisitor<B>,
Visit each tensor parameter in the module with a visitor.
Source§fn map<Mapper>(self, mapper: &mut Mapper) -> BiRnn<B>where
Mapper: ModuleMapper<B>,
fn map<Mapper>(self, mapper: &mut Mapper) -> BiRnn<B>where
Mapper: ModuleMapper<B>,
Map each tensor parameter in the module with a mapper.
Source§fn collect_devices(
&self,
devices: Vec<<B as BackendTypes>::Device>,
) -> Vec<<B as BackendTypes>::Device>
fn collect_devices( &self, devices: Vec<<B as BackendTypes>::Device>, ) -> Vec<<B as BackendTypes>::Device>
Return all the devices found in the underneath module tree added to the given vector
without duplicates.
Source§fn to_device(self, device: &<B as BackendTypes>::Device) -> BiRnn<B>
fn to_device(self, device: &<B as BackendTypes>::Device) -> BiRnn<B>
Move the module and all of its sub-modules to the given device. Read more
Source§fn fork(self, device: &<B as BackendTypes>::Device) -> BiRnn<B>
fn fork(self, device: &<B as BackendTypes>::Device) -> BiRnn<B>
Fork the module and all of its sub-modules to the given device. Read more
Source§fn devices(&self) -> Vec<<B as BackendTypes>::Device>
fn devices(&self) -> Vec<<B as BackendTypes>::Device>
Return all the devices found in the underneath module tree without duplicates.
Source§fn train<AB>(self) -> Self::TrainModulewhere
AB: AutodiffBackend<InnerBackend = B>,
Self: HasAutodiffModule<AB>,
fn train<AB>(self) -> Self::TrainModulewhere
AB: AutodiffBackend<InnerBackend = B>,
Self: HasAutodiffModule<AB>,
Move the module and all of its sub-modules to the autodiff backend. Read more
Source§fn save_file<FR, PB>(
self,
file_path: PB,
recorder: &FR,
) -> Result<(), RecorderError>
fn save_file<FR, PB>( self, file_path: PB, recorder: &FR, ) -> Result<(), RecorderError>
Save the module to a file using the provided file recorder. Read more
Source§fn load_file<FR, PB>(
self,
file_path: PB,
recorder: &FR,
device: &<B as BackendTypes>::Device,
) -> Result<Self, RecorderError>
fn load_file<FR, PB>( self, file_path: PB, recorder: &FR, device: &<B as BackendTypes>::Device, ) -> Result<Self, RecorderError>
Load the module from a file using the provided file recorder. Read more
Source§fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
Quantize the weights of the module.
Source§impl<B> ModuleDisplay for BiRnn<B>where
B: Backend,
impl<B> ModuleDisplay for BiRnn<B>where
B: Backend,
Source§fn custom_settings(&self) -> Option<DisplaySettings>
fn custom_settings(&self) -> Option<DisplaySettings>
Custom display settings for the module. Read more
Auto Trait Implementations§
impl<B> !Freeze for BiRnn<B>
impl<B> !RefUnwindSafe for BiRnn<B>
impl<B> Send for BiRnn<B>
impl<B> Sync for BiRnn<B>
impl<B> Unpin for BiRnn<B>where
<B as BackendTypes>::FloatTensorPrimitive: Unpin,
<B as BackendTypes>::QuantizedTensorPrimitive: Unpin,
<B as BackendTypes>::Device: Unpin,
impl<B> UnsafeUnpin for BiRnn<B>where
<B as BackendTypes>::Device: UnsafeUnpin,
<B as BackendTypes>::FloatTensorPrimitive: UnsafeUnpin,
<B as BackendTypes>::QuantizedTensorPrimitive: UnsafeUnpin,
impl<B> !UnwindSafe for BiRnn<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