paddlespeech.s2t package

class paddlespeech.s2t.LayerDict(modules: Optional[Mapping[str, Layer]] = None)[source]

Bases: Layer

Holds submodules in a dictionary.

LayerDict can be indexed like a regular Python dictionary, but modules it contains are properly registered, and will be visible by all Layer methods.

LayerDict is an ordered dictionary that respects

  • the order of insertion, and

  • in update(), the order of the merged OrderedDict, dict (started from Python 3.6) or another LayerDict (the argument to update()).

Note that update() with other unordered mapping types (e.g., Python's plain dict before Python version 3.6) does not preserve the order of the merged mapping.

Args:
modules (iterable, optional): a mapping (dictionary) of (string: module)

or an iterable of key-value pairs of type (string, module)

Example:

class MyModule(nn.Layer):
    def __init__(self):
        super(MyModule, self).__init__()
        self.choices = nn.LayerDict({
                'conv': nn.Conv2d(10, 10, 3),
                'pool': nn.MaxPool2d(3)
        })
        self.activations = nn.LayerDict([
                ['lrelu', nn.LeakyReLU()],
                ['prelu', nn.PReLU()]
        ])

    def forward(self, x, choice, act):
        x = self.choices[choice](x)
        x = self.activations[act](x)
        return x

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

Remove all items from the LayerDict.

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(*inputs, **kwargs)

Defines the computation performed at every call.

full_name()

Full name for this layer, composed by name_scope + "/" + MyLayer.__class__.__name__

items()

Return an iterable of the LayerDict key/value pairs.

keys()

Return an iterable of the LayerDict keys.

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.

pop(key)

Remove key from the LayerDict and return its module.

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.

update(modules)

Update the LayerDict with the key-value pairs from a mapping or an iterable, overwriting existing keys.

values()

Return an iterable of the LayerDict values.

backward

register_state_dict_hook

clear() None[source]

Remove all items from the LayerDict.

items() Iterable[Tuple[str, Layer]][source]

Return an iterable of the LayerDict key/value pairs.

keys() Iterable[str][source]

Return an iterable of the LayerDict keys.

pop(key: str) Layer[source]

Remove key from the LayerDict and return its module.

Args:

key (string): key to pop from the LayerDict

update(modules: Mapping[str, Layer]) None[source]

Update the LayerDict with the key-value pairs from a mapping or an iterable, overwriting existing keys.

Note

If modules is an OrderedDict, a LayerDict, or an iterable of key-value pairs, the order of new elements in it is preserved.

Args:
modules (iterable): a mapping (dictionary) from string to Layer,

or an iterable of key-value pairs of type (string, Layer)

values() Iterable[Layer][source]

Return an iterable of the LayerDict values.

paddlespeech.s2t.broadcast_shape(shp1, shp2)[source]
paddlespeech.s2t.cat(xs, dim=0)[source]
paddlespeech.s2t.contiguous(xs: Tensor) Tensor[source]
paddlespeech.s2t.fill_(xs: Tensor, value: Union[float, int]) Tensor[source]
paddlespeech.s2t.func_float(x: Tensor) Tensor[source]
paddlespeech.s2t.func_int(x: Tensor) Tensor[source]
paddlespeech.s2t.func_long(x: Tensor)[source]
paddlespeech.s2t.is_broadcastable(shp1, shp2)[source]
paddlespeech.s2t.item(x: Tensor)[source]
paddlespeech.s2t.masked_fill(xs: Tensor, mask: Tensor, value: Union[float, int])[source]
paddlespeech.s2t.masked_fill_(xs: Tensor, mask: Tensor, value: Union[float, int]) Tensor[source]
paddlespeech.s2t.new_full(x: Tensor, size: Union[List[int], Tuple[int], Tensor], fill_value: Union[float, int, bool, Tensor], dtype=None)[source]
paddlespeech.s2t.repeat(xs: Tensor, *size: Any) Tensor[source]
paddlespeech.s2t.to(x: Tensor, *args, **kwargs) Tensor[source]
paddlespeech.s2t.tolist(x: Tensor) List[Any][source]
paddlespeech.s2t.type_as(x: Tensor, other: Tensor) Tensor[source]
paddlespeech.s2t.view(xs: Tensor, *args: int) Tensor[source]
paddlespeech.s2t.view_as(xs: Tensor, ys: Tensor) Tensor[source]

Subpackages