paddlespeech.t2s.modules.tacotron2.attentions module
Attention modules for RNN.
- class paddlespeech.t2s.modules.tacotron2.attentions.AttForward(eprojs, dunits, att_dim, aconv_chans, aconv_filts)[source]
Bases:
Layer
Forward attention module. Reference ---------- Forward attention in sequence-to-sequence acoustic modeling for speech synthesis
- Args:
- eprojs (int):
projection-units of encoder
- dunits (int):
units of decoder
- att_dim (int):
attention dimension
- aconv_chans (int):
channels of attention convolution
- aconv_filts (int):
filter size of attention convolution
Methods
__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
fn
recursively 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.
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
(enc_hs_pad, enc_hs_len, dec_z, att_prev)Calculate AttForward forward propagation.
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.
reset
()reset states
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.
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.
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.
backward
register_state_dict_hook
- forward(enc_hs_pad, enc_hs_len, dec_z, att_prev, scaling=1.0, last_attended_idx=None, backward_window=1, forward_window=3)[source]
Calculate AttForward forward propagation.
- Args:
- enc_hs_pad(Tensor):
padded encoder hidden state (B, T_max, D_enc)
- enc_hs_len(list):
padded encoder hidden state length (B,)
- dec_z(Tensor):
decoder hidden state (B, D_dec)
- att_prev(Tensor):
attention weights of previous step (B, T_max)
- scaling(float, optional):
scaling parameter before applying softmax (Default value = 1.0)
- last_attended_idx(int, optional):
index of the inputs of the last attended (Default value = None)
- backward_window(int, optional):
backward window size in attention constraint (Default value = 1)
- forward_window(int, optional):
(Default value = 3)
- Returns:
- Tensor:
attention weighted encoder state (B, D_enc)
- Tensor:
previous attention weights (B, T_max)
- class paddlespeech.t2s.modules.tacotron2.attentions.AttForwardTA(eunits, dunits, att_dim, aconv_chans, aconv_filts, odim)[source]
Bases:
Layer
Forward attention with transition agent module. Reference:
- Forward attention in sequence-to-sequence acoustic modeling for speech synthesis
- Args:
- eunits (int):
units of encoder
- dunits (int):
units of decoder
- att_dim (int):
attention dimension
- aconv_chans (int):
channels of attention convolution
- aconv_filts (int):
filter size of attention convolution
- odim (int):
output dimension
Methods
__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
fn
recursively 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.
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
(enc_hs_pad, enc_hs_len, dec_z, ...)Calculate AttForwardTA forward propagation.
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.
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.
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.
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.
backward
register_state_dict_hook
reset
- forward(enc_hs_pad, enc_hs_len, dec_z, att_prev, out_prev, scaling=1.0, last_attended_idx=None, backward_window=1, forward_window=3)[source]
Calculate AttForwardTA forward propagation.
- Args:
- enc_hs_pad(Tensor):
padded encoder hidden state (B, Tmax, eunits)
- enc_hs_len(list Tensor):
padded encoder hidden state length (B,)
- dec_z(Tensor):
decoder hidden state (B, dunits)
- att_prev(Tensor):
attention weights of previous step (B, T_max)
- out_prev(Tensor):
decoder outputs of previous step (B, odim)
- scaling(float, optional):
scaling parameter before applying softmax (Default value = 1.0)
- last_attended_idx(int, optional):
index of the inputs of the last attended (Default value = None)
- backward_window(int, optional):
backward window size in attention constraint (Default value = 1)
- forward_window(int, optional):
(Default value = 3)
- Returns:
- Tensor:
attention weighted encoder state (B, dunits)
- Tensor:
previous attention weights (B, Tmax)
- class paddlespeech.t2s.modules.tacotron2.attentions.AttLoc(eprojs, dunits, att_dim, aconv_chans, aconv_filts, han_mode=False)[source]
Bases:
Layer
location-aware attention module.
- Reference: Attention-Based Models for Speech Recognition
- Args:
- eprojs (int):
projection-units of encoder
- dunits (int):
units of decoder
- att_dim (int):
attention dimension
- aconv_chans (int):
channels of attention convolution
- aconv_filts (int):
filter size of attention convolution
- han_mode (bool):
flag to swith on mode of hierarchical attention and not store pre_compute_enc_h
Methods
__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
fn
recursively 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.
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
(enc_hs_pad, enc_hs_len, dec_z, att_prev)Calculate AttLoc forward propagation. Args: enc_hs_pad(Tensor): padded encoder hidden state (B, T_max, D_enc) enc_hs_len(Tensor): padded encoder hidden state length (B) dec_z(Tensor dec_z): decoder hidden state (B, D_dec) att_prev(Tensor): previous attention weight (B, T_max) scaling(float, optional): scaling parameter before applying softmax (Default value = 2.0) forward_window(Tensor, optional): forward window size when constraining attention (Default value = 3) last_attended_idx(int, optional): index of the inputs of the last attended (Default value = None) backward_window(int, optional): backward window size in attention constraint (Default value = 1) forward_window(int, optional): forward window size in attetion constraint (Default value = 3) Returns: Tensor: attention weighted encoder state (B, D_enc) Tensor: previous attention weights (B, T_max).
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.
reset
()reset states
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.
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.
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.
backward
register_state_dict_hook
- forward(enc_hs_pad, enc_hs_len, dec_z, att_prev, scaling=2.0, last_attended_idx=-1, backward_window=1, forward_window=3)[source]
Calculate AttLoc forward propagation. Args:
- enc_hs_pad(Tensor):
padded encoder hidden state (B, T_max, D_enc)
- enc_hs_len(Tensor):
padded encoder hidden state length (B)
- dec_z(Tensor dec_z):
decoder hidden state (B, D_dec)
- att_prev(Tensor):
previous attention weight (B, T_max)
- scaling(float, optional):
scaling parameter before applying softmax (Default value = 2.0)
- forward_window(Tensor, optional):
forward window size when constraining attention (Default value = 3)
- last_attended_idx(int, optional):
index of the inputs of the last attended (Default value = None)
- backward_window(int, optional):
backward window size in attention constraint (Default value = 1)
- forward_window(int, optional):
forward window size in attetion constraint (Default value = 3)
- Returns:
- Tensor:
attention weighted encoder state (B, D_enc)
- Tensor:
previous attention weights (B, T_max)