Listen Attend Spell (multi-head) Model¶
Listen Attend Spell (multi-head) Model¶
-
class
openspeech.models.listen_attend_spell_with_multi_head.model.
ListenAttendSpellWithMultiHeadModel
(configs: omegaconf.dictconfig.DictConfig, vocab: openspeech.vocabs.vocab.Vocabulary)[source]¶ Listen, Attend and Spell model with configurable encoder and decoder. Paper: https://arxiv.org/abs/1508.01211
- Parameters
configs (DictConfig) – configuration set.
vocab (Vocabulary) – the class of vocabulary
- Inputs:
- inputs (torch.FloatTensor): A input sequence passed to encoders. Typically for inputs this will be
a padded FloatTensor of size
(batch, seq_length, dimension)
.
input_lengths (torch.LongTensor): The length of input tensor.
(batch)
- Returns
Result of model predictions.
- Return type
outputs (dict)
-
forward
(inputs: torch.Tensor, input_lengths: torch.Tensor) → Dict[str, torch.Tensor][source]¶ Forward propagate a inputs and targets pair for inference.
- Inputs:
- inputs (torch.FloatTensor): A input sequence passed to encoders. Typically for inputs this will be a padded
FloatTensor of size
(batch, seq_length, dimension)
.
input_lengths (torch.LongTensor): The length of input tensor.
(batch)
- Returns
Result of model predictions.
- Return type
outputs (dict)
-
test_step
(batch: tuple, batch_idx: int) → collections.OrderedDict[source]¶ Forward propagate a inputs and targets pair for test.
- Inputs:
batch (tuple): A train batch contains inputs, targets, input_lengths, target_lengths batch_idx (int): The index of batch
- Returns
loss for training
- Return type
loss (torch.Tensor)
-
training_step
(batch: tuple, batch_idx: int) → collections.OrderedDict[source]¶ Forward propagate a inputs and targets pair for training.
- Inputs:
batch (tuple): A train batch contains inputs, targets, input_lengths, target_lengths batch_idx (int): The index of batch
- Returns
loss for training
- Return type
loss (torch.Tensor)
-
validation_step
(batch: tuple, batch_idx: int) → collections.OrderedDict[source]¶ Forward propagate a inputs and targets pair for validation.
- Inputs:
batch (tuple): A train batch contains inputs, targets, input_lengths, target_lengths batch_idx (int): The index of batch
- Returns
loss for training
- Return type
loss (torch.Tensor)
Listen Attend Spell (multi-head) Model Configuration¶
-
class
openspeech.models.listen_attend_spell_with_multi_head.configurations.
ListenAttendSpellWithMultiHeadConfigs
(model_name: str = 'listen_attend_spell_with_multi_head', num_encoder_layers: int = 3, num_decoder_layers: int = 2, hidden_state_dim: int = 512, encoder_dropout_p: float = 0.3, encoder_bidirectional: bool = True, rnn_type: str = 'lstm', joint_ctc_attention: bool = False, max_length: int = 128, num_attention_heads: int = 4, decoder_dropout_p: float = 0.2, decoder_attn_mechanism: str = 'multi-head', teacher_forcing_ratio: float = 1.0, optimizer: str = 'adam')[source]¶ This is the configuration class to store the configuration of a
ListenAttendSpellWithMultiHead
.It is used to initiated an ListenAttendSpellWithMultiHead model.
Configuration objects inherit from :class: ~openspeech.dataclass.configs.OpenspeechDataclass.
- Configurations:
model_name (str): Model name (default: listen_attend_spell_with_multi_head) num_encoder_layers (int): The number of encoder layers. (default: 3) num_decoder_layers (int): The number of decoder layers. (default: 2) hidden_state_dim (int): The hidden state dimension of encoder. (default: 512) encoder_dropout_p (float): The dropout probability of encoder. (default: 0.3) encoder_bidirectional (bool): If True, becomes a bidirectional encoders (default: True) rnn_type (str): Type of rnn cell (rnn, lstm, gru) (default: lstm) joint_ctc_attention (bool): Flag indication joint ctc attention or not (default: False) max_length (int): Max decoding length. (default: 128) num_attention_heads (int): The number of attention heads. (default: 4) decoder_dropout_p (float): The dropout probability of decoder. (default: 0.2) decoder_attn_mechanism (str): The attention mechanism for decoder. (default: multi-head) teacher_forcing_ratio (float): The ratio of teacher forcing. (default: 1.0) optimizer (str): Optimizer for training. (default: adam)