paddlespeech.s2t.models.u2_st.u2_st module
U2 ASR Model Unified Streaming and Non-streaming Two-pass End-to-end Model for Speech Recognition (https://arxiv.org/pdf/2012.05481.pdf)
- class paddlespeech.s2t.models.u2_st.u2_st.U2STInferModel(configs: dict)[source]
Bases:
U2STModelMethods
__call__(*inputs, **kwargs)Call self as a function.
add_parameter(name, parameter)Adds a Parameter instance.
add_sublayer(name, sublayer)Adds a sub Layer instance.
apply(fn)Applies
fnrecursively to every sublayer (as returned by.sublayers()) as well as self.buffers([include_sublayers])Returns a list of all buffers from current layer and its sub-layers.
children()Returns an iterator over immediate children layers.
clear_gradients()Clear the gradients of all parameters for this layer.
create_parameter(shape[, attr, dtype, ...])Create parameters for this layer.
create_tensor([name, persistable, dtype])Create Tensor for this layer.
create_variable([name, persistable, dtype])Create Tensor for this layer.
ctc_activation(xs)Export interface for c++ call, apply linear transform and log
decode(feats, feats_lengths, text_feature, ...)u2 decoding.
eos_symbol()Export interface for c++ call, return eos symbol id of the model
eval()Sets this Layer and all its sublayers to evaluation mode.
extra_repr()Extra representation of this layer, you can have custom implementation of your own layer.
forward(feats, feats_lengths[, ...])export model function
forward_attention_decoder(hyps, hyps_lens, ...)Export interface for c++ call, forward decoder with multiple
forward_encoder_chunk(xs, offset, ...[, ...])Export interface for c++ call, give input chunk xs, and return
from_config(configs)init model.
from_pretrained(dataloader, config, ...)Build a DeepSpeech2Model model from a pretrained model.
full_name()Full name for this layer, composed by name_scope + "/" + MyLayer.__class__.__name__
load_dict(state_dict[, use_structured_name])Set parameters and persistable buffers from state_dict.
named_buffers([prefix, include_sublayers])Returns an iterator over all buffers in the Layer, yielding tuple of name and Tensor.
named_children()Returns an iterator over immediate children layers, yielding both the name of the layer as well as the layer itself.
named_parameters([prefix, include_sublayers])Returns an iterator over all parameters in the Layer, yielding tuple of name and parameter.
named_sublayers([prefix, include_self, ...])Returns an iterator over all sublayers in the Layer, yielding tuple of name and sublayer.
parameters([include_sublayers])Returns a list of all Parameters from current layer and its sub-layers.
register_buffer(name, tensor[, persistable])Registers a tensor as buffer into the layer.
register_forward_post_hook(hook)Register a forward post-hook for Layer.
register_forward_pre_hook(hook)Register a forward pre-hook for Layer.
right_context()Export interface for c++ call, return right_context of the model
set_dict(state_dict[, use_structured_name])Set parameters and persistable buffers from state_dict.
set_state_dict(state_dict[, use_structured_name])Set parameters and persistable buffers from state_dict.
sos_symbol()Export interface for c++ call, return sos symbol id of the model
state_dict([destination, include_sublayers, ...])Get all parameters and persistable buffers of current layer and its sub-layers.
sublayers([include_self])Returns a list of sub layers.
subsampling_rate()Export interface for c++ call, return subsampling_rate of the model
to([device, dtype, blocking])Cast the parameters and buffers of Layer by the give device, dtype and blocking.
to_static_state_dict([destination, ...])Get all parameters and buffers of current layer and its sub-layers.
train()Sets this Layer and all its sublayers to training mode.
translate(speech, speech_lengths[, ...])Apply beam search on attention decoder with length penalty Args: speech (paddle.Tensor): (batch, max_len, feat_dim) speech_length (paddle.Tensor): (batch, ) beam_size (int): beam size for beam search word_reward (float): word reward used in beam search maxlenratio (float): max length ratio to bound the length of translated text decoding_chunk_size (int): decoding chunk for dynamic chunk trained model. <0: for decoding, use full chunk. >0: for decoding, use fixed chunk size as set. 0: used for training, it's prohibited here simulate_streaming (bool): whether do encoder forward in a streaming fashion Returns: paddle.Tensor: decoding result, (batch, max_result_len).
backward
register_state_dict_hook
- class paddlespeech.s2t.models.u2_st.u2_st.U2STModel(configs: dict)[source]
Bases:
U2STBaseModelMethods
__call__(*inputs, **kwargs)Call self as a function.
add_parameter(name, parameter)Adds a Parameter instance.
add_sublayer(name, sublayer)Adds a sub Layer instance.
apply(fn)Applies
fnrecursively to every sublayer (as returned by.sublayers()) as well as self.buffers([include_sublayers])Returns a list of all buffers from current layer and its sub-layers.
children()Returns an iterator over immediate children layers.
clear_gradients()Clear the gradients of all parameters for this layer.
create_parameter(shape[, attr, dtype, ...])Create parameters for this layer.
create_tensor([name, persistable, dtype])Create Tensor for this layer.
create_variable([name, persistable, dtype])Create Tensor for this layer.
ctc_activation(xs)Export interface for c++ call, apply linear transform and log
decode(feats, feats_lengths, text_feature, ...)u2 decoding.
eos_symbol()Export interface for c++ call, return eos symbol id of the model
eval()Sets this Layer and all its sublayers to evaluation mode.
extra_repr()Extra representation of this layer, you can have custom implementation of your own layer.
forward(speech, speech_lengths, text, ...[, ...])Frontend + Encoder + Decoder + Calc loss Args: speech: (Batch, Length, ...) speech_lengths: (Batch, ) text: (Batch, Length) text_lengths: (Batch,) Returns: total_loss, attention_loss, ctc_loss
forward_attention_decoder(hyps, hyps_lens, ...)Export interface for c++ call, forward decoder with multiple
forward_encoder_chunk(xs, offset, ...[, ...])Export interface for c++ call, give input chunk xs, and return
from_config(configs)init model.
from_pretrained(dataloader, config, ...)Build a DeepSpeech2Model model from a pretrained model.
full_name()Full name for this layer, composed by name_scope + "/" + MyLayer.__class__.__name__
load_dict(state_dict[, use_structured_name])Set parameters and persistable buffers from state_dict.
named_buffers([prefix, include_sublayers])Returns an iterator over all buffers in the Layer, yielding tuple of name and Tensor.
named_children()Returns an iterator over immediate children layers, yielding both the name of the layer as well as the layer itself.
named_parameters([prefix, include_sublayers])Returns an iterator over all parameters in the Layer, yielding tuple of name and parameter.
named_sublayers([prefix, include_self, ...])Returns an iterator over all sublayers in the Layer, yielding tuple of name and sublayer.
parameters([include_sublayers])Returns a list of all Parameters from current layer and its sub-layers.
register_buffer(name, tensor[, persistable])Registers a tensor as buffer into the layer.
register_forward_post_hook(hook)Register a forward post-hook for Layer.
register_forward_pre_hook(hook)Register a forward pre-hook for Layer.
right_context()Export interface for c++ call, return right_context of the model
set_dict(state_dict[, use_structured_name])Set parameters and persistable buffers from state_dict.
set_state_dict(state_dict[, use_structured_name])Set parameters and persistable buffers from state_dict.
sos_symbol()Export interface for c++ call, return sos symbol id of the model
state_dict([destination, include_sublayers, ...])Get all parameters and persistable buffers of current layer and its sub-layers.
sublayers([include_self])Returns a list of sub layers.
subsampling_rate()Export interface for c++ call, return subsampling_rate of the model
to([device, dtype, blocking])Cast the parameters and buffers of Layer by the give device, dtype and blocking.
to_static_state_dict([destination, ...])Get all parameters and buffers of current layer and its sub-layers.
train()Sets this Layer and all its sublayers to training mode.
translate(speech, speech_lengths[, ...])Apply beam search on attention decoder with length penalty Args: speech (paddle.Tensor): (batch, max_len, feat_dim) speech_length (paddle.Tensor): (batch, ) beam_size (int): beam size for beam search word_reward (float): word reward used in beam search maxlenratio (float): max length ratio to bound the length of translated text decoding_chunk_size (int): decoding chunk for dynamic chunk trained model. <0: for decoding, use full chunk. >0: for decoding, use fixed chunk size as set. 0: used for training, it's prohibited here simulate_streaming (bool): whether do encoder forward in a streaming fashion Returns: paddle.Tensor: decoding result, (batch, max_result_len).
backward
register_state_dict_hook
- classmethod from_config(configs: dict)[source]
init model.
- Args:
configs (dict): config dict.
- Raises:
ValueError: raise when using not support encoder type.
- Returns:
nn.Layer: U2STModel
- classmethod from_pretrained(dataloader, config, checkpoint_path)[source]
Build a DeepSpeech2Model model from a pretrained model.
- Args:
dataloader (paddle.io.DataLoader): not used. config (yacs.config.CfgNode): model configs checkpoint_path (Path or str): the path of pretrained model checkpoint, without extension name
- Returns:
DeepSpeech2Model: The model built from pretrained result.