Transformer with CTC Model

Transformer with CTC Model

class openspeech.models.transformer_with_ctc.model.TransformerWithCTCModel(configs: omegaconf.dictconfig.DictConfig, vocab: openspeech.vocabs.vocab.Vocabulary)[source]

Transformer Encoder Only Model.

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 that contains y_hats, logits, output_lengths

Return type

  • dict (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 that contains y_hats, logits, output_lengths

Return type

  • dict (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)

Transformer with CTC Model Configuration

class openspeech.models.transformer_with_ctc.configurations.TransformerWithCTCConfigs(model_name: str = 'transformer_with_ctc', d_model: int = 512, d_ff: int = 2048, num_attention_heads: int = 8, num_encoder_layers: int = 12, encoder_dropout_p: float = 0.3, ffnet_style: str = 'ff', optimizer: str = 'adam')[source]

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

It is used to initiated an TransformerWithCTC model.

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

Configurations:

model_name (str): Model name (default: transformer_with_ctc) extractor (str): The CNN feature extractor. (default: vgg) d_model (int): Dimension of model. (default: 512) d_ff (int): Dimenstion of feed forward network. (default: 2048) num_attention_heads (int): The number of attention heads. (default: 8) num_encoder_layers (int): The number of encoder layers. (default: 12) encoder_dropout_p (float): The dropout probability of encoder. (default: 0.3) ffnet_style (str): Style of feed forward network. (ff, conv) (default: ff) optimizer (str): Optimizer for training. (default: adam)