pub trait Encoder {
// Required methods
fn encode(
&self,
input: &Tensor,
attention_mask: Option<&Tensor>,
train: bool,
) -> Result<Vec<LayerOutput>, TransformerError>;
fn n_layers(&self) -> i64;
}
Expand description
Encoder networks.
Required Methods§
Sourcefn encode(
&self,
input: &Tensor,
attention_mask: Option<&Tensor>,
train: bool,
) -> Result<Vec<LayerOutput>, TransformerError>
fn encode( &self, input: &Tensor, attention_mask: Option<&Tensor>, train: bool, ) -> Result<Vec<LayerOutput>, TransformerError>
Apply the encoder.
Returns the output and attention per layer. The (optional)
attention mask of shape [batch_size, time_steps]
indicates
which tokens should be included (true
) and excluded (false
) from
attention. This can be used to mask inactive timesteps.