DeepSpeech2¶
DeepSpeech2 Model¶
-
class
openspeech.models.deepspeech2.model.
DeepSpeech2Model
(configs: omegaconf.dictconfig.DictConfig, tokenizer: openspeech.tokenizers.tokenizer.Tokenizer)[source]¶ Deep Speech2 model with configurable encoders and decoders. Paper: https://arxiv.org/abs/1512.02595
- Parameters
configs (DictConfig) – configuration set.
tokenizer (Tokenizer) – tokenizer is in charge of preparing the inputs for a model.
- 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
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 that contains y_hats, logits, output_lengths
- 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)
DeepSpeech2 Configuration¶
-
class
openspeech.models.deepspeech2.configurations.
DeepSpeech2Configs
(model_name: str = 'deepspeech2', rnn_type: str = 'gru', num_rnn_layers: int = 5, rnn_hidden_dim: int = 1024, dropout_p: float = 0.3, bidirectional: bool = True, activation: str = 'hardtanh', optimizer: str = 'adam')[source]¶ This is the configuration class to store the configuration of a
DeepSpeech2
.It is used to initiated an DeepSpeech2 model.
Configuration objects inherit from :class: ~openspeech.dataclass.configs.OpenspeechDataclass.
- Parameters
model_name (str) – Model name (default: deepspeech2)
num_rnn_layers (int) – The number of rnn layers. (default: 5)
rnn_hidden_dim (int) – The hidden state dimension of rnn. (default: 1024)
dropout_p (float) – The dropout probability of model. (default: 0.3)
bidirectional (bool) – If True, becomes a bidirectional encoders (default: True)
rnn_type (str) – Type of rnn cell (rnn, lstm, gru) (default: gru)
activation (str) – Type of activation function (default: str)
optimizer (str) – Optimizer for training. (default: adam)