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 allLayer
methods.LayerDict
is an ordered dictionary that respectsthe order of insertion, and
in
update()
, the order of the mergedOrderedDict
,dict
(started from Python 3.6) or anotherLayerDict
(the argument toupdate()
).
Note that
update()
with other unordered mapping types (e.g., Python's plaindict
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
- 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 anOrderedDict
, aLayerDict
, 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
)
- modules (iterable): a mapping (dictionary) from string to
- paddlespeech.s2t.new_full(x: Tensor, size: Union[List[int], Tuple[int], Tensor], fill_value: Union[float, int, bool, Tensor], dtype=None)[source]
Subpackages
- paddlespeech.s2t.decoders package
- paddlespeech.s2t.exps package
- paddlespeech.s2t.frontend package
- paddlespeech.s2t.io package
- paddlespeech.s2t.models package
- paddlespeech.s2t.modules package
- Submodules
- paddlespeech.s2t.modules.activation module
- paddlespeech.s2t.modules.align module
- paddlespeech.s2t.modules.attention module
- paddlespeech.s2t.modules.cmvn module
- paddlespeech.s2t.modules.conformer_convolution module
- paddlespeech.s2t.modules.crf module
- paddlespeech.s2t.modules.ctc module
- paddlespeech.s2t.modules.decoder module
- paddlespeech.s2t.modules.decoder_layer module
- paddlespeech.s2t.modules.embedding module
- paddlespeech.s2t.modules.encoder module
- paddlespeech.s2t.modules.encoder_layer module
- paddlespeech.s2t.modules.initializer module
- paddlespeech.s2t.modules.loss module
- paddlespeech.s2t.modules.mask module
- paddlespeech.s2t.modules.positionwise_feed_forward module
- paddlespeech.s2t.modules.subsampling module
- Submodules
- paddlespeech.s2t.training package
- Subpackages
- Submodules
- paddlespeech.s2t.utils package
- Submodules
- paddlespeech.s2t.utils.asr_utils module
- paddlespeech.s2t.utils.bleu_score module
- paddlespeech.s2t.utils.check_kwargs module
- paddlespeech.s2t.utils.checkpoint module
- paddlespeech.s2t.utils.cli_readers module
- paddlespeech.s2t.utils.cli_utils module
- paddlespeech.s2t.utils.cli_writers module
- paddlespeech.s2t.utils.ctc_utils module
- paddlespeech.s2t.utils.dynamic_import module
- paddlespeech.s2t.utils.dynamic_pip_install module
- paddlespeech.s2t.utils.error_rate module
- paddlespeech.s2t.utils.layer_tools module
- paddlespeech.s2t.utils.log module
- paddlespeech.s2t.utils.mp_tools module
- paddlespeech.s2t.utils.profiler module
- paddlespeech.s2t.utils.socket_server module
- paddlespeech.s2t.utils.spec_augment module
- paddlespeech.s2t.utils.tensor_utils module
- paddlespeech.s2t.utils.text_grid module
- paddlespeech.s2t.utils.utility module
- Submodules