paddlespeech.s2t.modules.subsampling module

Subsampling layer definition.

class paddlespeech.s2t.modules.subsampling.Conv2dSubsampling4(idim: int, odim: int, dropout_rate: float, pos_enc_class: ~paddle.fluid.dygraph.layers.Layer = <class 'paddlespeech.s2t.modules.embedding.PositionalEncoding'>)[source]

Bases: Conv2dSubsampling

Convolutional 2D subsampling (to 1/4 length).

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(x, x_mask[, offset])

Subsample x. Args: x (paddle.Tensor): Input tensor (#batch, time, idim). x_mask (paddle.Tensor): Input mask (#batch, 1, time). offset (int): position encoding offset. Returns: paddle.Tensor: Subsampled tensor (#batch, time', odim), where time' = time // 4. paddle.Tensor: positional encoding paddle.Tensor: Subsampled mask (#batch, 1, time'), where time' = time // 4.

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

position_encoding

register_state_dict_hook

forward(x: Tensor, x_mask: Tensor, offset: int = 0) Tuple[Tensor, Tensor, Tensor][source]

Subsample x. Args:

x (paddle.Tensor): Input tensor (#batch, time, idim). x_mask (paddle.Tensor): Input mask (#batch, 1, time). offset (int): position encoding offset.

Returns:
paddle.Tensor: Subsampled tensor (#batch, time', odim),

where time' = time // 4.

paddle.Tensor: positional encoding paddle.Tensor: Subsampled mask (#batch, 1, time'),

where time' = time // 4.

class paddlespeech.s2t.modules.subsampling.Conv2dSubsampling6(idim: int, odim: int, dropout_rate: float, pos_enc_class: ~paddle.fluid.dygraph.layers.Layer = <class 'paddlespeech.s2t.modules.embedding.PositionalEncoding'>)[source]

Bases: Conv2dSubsampling

Convolutional 2D subsampling (to 1/6 length).

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(x, x_mask[, offset])

Subsample x. Args: x (paddle.Tensor): Input tensor (#batch, time, idim). x_mask (paddle.Tensor): Input mask (#batch, 1, time). offset (int): position encoding offset. Returns: paddle.Tensor: Subsampled tensor (#batch, time', odim), where time' = time // 6. paddle.Tensor: positional encoding paddle.Tensor: Subsampled mask (#batch, 1, time'), where time' = time // 6.

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

position_encoding

register_state_dict_hook

forward(x: Tensor, x_mask: Tensor, offset: int = 0) Tuple[Tensor, Tensor, Tensor][source]

Subsample x. Args:

x (paddle.Tensor): Input tensor (#batch, time, idim). x_mask (paddle.Tensor): Input mask (#batch, 1, time). offset (int): position encoding offset.

Returns:
paddle.Tensor: Subsampled tensor (#batch, time', odim),

where time' = time // 6.

paddle.Tensor: positional encoding paddle.Tensor: Subsampled mask (#batch, 1, time'),

where time' = time // 6.

class paddlespeech.s2t.modules.subsampling.Conv2dSubsampling8(idim: int, odim: int, dropout_rate: float, pos_enc_class: ~paddle.fluid.dygraph.layers.Layer = <class 'paddlespeech.s2t.modules.embedding.PositionalEncoding'>)[source]

Bases: Conv2dSubsampling

Convolutional 2D subsampling (to 1/8 length).

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(x, x_mask[, offset])

Subsample x. Args: x (paddle.Tensor): Input tensor (#batch, time, idim). x_mask (paddle.Tensor): Input mask (#batch, 1, time). offset (int): position encoding offset. Returns: paddle.Tensor: Subsampled tensor (#batch, time', odim), where time' = time // 8. paddle.Tensor: positional encoding paddle.Tensor: Subsampled mask (#batch, 1, time'), where time' = time // 8.

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

position_encoding

register_state_dict_hook

forward(x: Tensor, x_mask: Tensor, offset: int = 0) Tuple[Tensor, Tensor, Tensor][source]

Subsample x. Args:

x (paddle.Tensor): Input tensor (#batch, time, idim). x_mask (paddle.Tensor): Input mask (#batch, 1, time). offset (int): position encoding offset.

Returns:
paddle.Tensor: Subsampled tensor (#batch, time', odim),

where time' = time // 8.

paddle.Tensor: positional encoding paddle.Tensor: Subsampled mask (#batch, 1, time'),

where time' = time // 8.

class paddlespeech.s2t.modules.subsampling.DepthwiseConv2DSubsampling4(idim: int, odim: int, pos_enc_class: Layer, dw_stride: bool = False, input_size: int = 80, input_dropout_rate: float = 0.1, init_weights: bool = True)[source]

Bases: BaseSubsampling

Depthwise Convolutional 2D subsampling (to 1/4 length).

Args:

idim (int): Input dimension. odim (int): Output dimension. pos_enc_class (nn.Layer): position encoding class. dw_stride (int): Whether do depthwise convolution. input_size (int): filter bank 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(x, x_mask[, offset])

Defines the computation performed at every call.

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

position_encoding

register_state_dict_hook

forward(x: Tensor, x_mask: Tensor, offset: int = 0) Tuple[Tensor, Tensor, Tensor][source]

Defines the computation performed at every call. Should be overridden by all subclasses.

Parameters:

*inputs(tuple): unpacked tuple arguments **kwargs(dict): unpacked dict arguments

class paddlespeech.s2t.modules.subsampling.LinearNoSubsampling(idim: int, odim: int, dropout_rate: float, pos_enc_class: ~paddle.fluid.dygraph.layers.Layer = <class 'paddlespeech.s2t.modules.embedding.PositionalEncoding'>)[source]

Bases: BaseSubsampling

Linear transform the input without subsampling.

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(x, x_mask[, offset])

Input x. Args: x (paddle.Tensor): Input tensor (#batch, time, idim). x_mask (paddle.Tensor): Input mask (#batch, 1, time). offset (int): position encoding offset. Returns: paddle.Tensor: linear input tensor (#batch, time', odim), where time' = time . paddle.Tensor: positional encoding paddle.Tensor: linear input mask (#batch, 1, time'), where time' = time .

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

position_encoding

register_state_dict_hook

forward(x: Tensor, x_mask: Tensor, offset: int = 0) Tuple[Tensor, Tensor, Tensor][source]

Input x. Args:

x (paddle.Tensor): Input tensor (#batch, time, idim). x_mask (paddle.Tensor): Input mask (#batch, 1, time). offset (int): position encoding offset.

Returns:
paddle.Tensor: linear input tensor (#batch, time', odim),

where time' = time .

paddle.Tensor: positional encoding paddle.Tensor: linear input mask (#batch, 1, time'),

where time' = time .