Deep CNN with Joint CTC LAS Model

Deep CNN with Joint CTC LAS Model

class openspeech.models.deep_cnn_with_joint_ctc_listen_attend_spell.model.DeepCNNWithJointCTCListenAttendSpellModel(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)

set_beam_decoder(batch_size: int, beam_size: int = 3)[source]

Setting beam search decoder

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)

Deep CNN with Joint CTC LAS Model Configuration

class openspeech.models.deep_cnn_with_joint_ctc_listen_attend_spell.configurations.DeepCNNWithJointCTCListenAttendSpellConfigs(model_name: str = 'deep_cnn_with_joint_ctc_listen_attend_spell', num_encoder_layers: int = 3, num_decoder_layers: int = 2, hidden_state_dim: int = 768, encoder_dropout_p: float = 0.3, encoder_bidirectional: bool = True, rnn_type: str = 'lstm', extractor: str = 'vgg', activation: str = 'hardtanh', joint_ctc_attention: bool = True, max_length: int = 128, num_attention_heads: int = 1, decoder_dropout_p: float = 0.2, decoder_attn_mechanism: str = 'loc', teacher_forcing_ratio: float = 1.0, optimizer: str = 'adam')[source]

This is the configuration class to store the configuration of a DeepCNNWithJointCTCListenAttendSpell.

It is used to initiated an DeepCNNWithJointCTCListenAttendSpell model.

Configuration objects inherit from :class: ~openspeech.dataclass.configs.OpenspeechDataclass.

Configurations:

model_name (str): Model name (default: deep_cnn_with_joint_ctc_listen_attend_spell) 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: 768) 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) extractor (str): The CNN feature extractor. (default: vgg) activation (str): Type of activation function (default: str) joint_ctc_attention (bool): Flag indication joint ctc attention or not (default: True) max_length (int): Max decoding length. (default: 128) num_attention_heads (int): The number of attention heads. (default: 1) decoder_dropout_p (float): The dropout probability of decoder. (default: 0.2) decoder_attn_mechanism (str): The attention mechanism for decoder. (default: loc) teacher_forcing_ratio (float): The ratio of teacher forcing. (default: 1.0) optimizer (str): Optimizer for training. (default: adam)