pyprobound.layers.module.ModuleLayer
- class ModuleLayer(layer_spec, input_shape, min_input_length, max_input_length)
Bases:
LayerLayer wrapper for torch.nn.Module.
The forward implementation of the module must take a sequence tensor of shape \((\text{minibatch},\text{in_channels},\text{in_length})\) and return a tensor of shape \((\text{minibatch},1,1)\).
- __init__(layer_spec, input_shape, min_input_length, max_input_length)
Initializes the Module layer.
- Parameters:
layer_spec (
ModuleSpec) – The specification of the Module layer.input_shape (
int) – The number of elements in an input sequence.min_input_length (
int) – The minimum number of finite elements in an input sequence.max_input_length (
int) – The maximum number of finite elements in an input sequence.
Methods
cache(fun)Decorator for a function to cache its output.
check_length_consistency()Checks that input lengths of Binding components are consistent.
components()Iterator of child components.
forward(seqs)Applies the module.
freeze()Turns off gradient calculation for all parameters.
from_spec(spec, prev)Creates a new instance from a specification and an input component.
in_len(length[, mode])Calculates the receptive field.
lengths(seqs)Counts the number of finite elements in each sequence.
max_embedding_size()The maximum number of bytes needed to encode a sequence.
optim_procedure([ancestry, current_order])The sequential optimization procedure for all Binding components.
out_len(length[, mode])Calculates the number of elements in the output length dimension.
reload(checkpoint)Loads the model from a checkpoint file.
reload_from_state_dict(state_dict)Loads the model from a state dict.
save(checkpoint[, flank_lengths])Saves the model to a file with "state_dict" and "metadata" fields.
unfreeze([parameter])Turns on gradient calculation for the specified parameter.
update_binding_optim(binding_optim)Updates a BindingOptim with the specification's optimization steps.
update_input_length([left_shift, ...])Updates input shapes, called by a child LayerSpec after its update.
Attributes
in_channelsThe number of input channels.
input_shapeThe number of elements in an input sequence.
max_input_lengthThe maximum number of finite elements in an input sequence.
min_input_lengthThe minimum number of finite elements in an input sequence.
out_channelsThe number of output channels.
unfreezablealias of
Literal['all']Non-Inherited Members
- classmethod from_spec(spec, prev)
Creates a new instance from a specification and an input component.
- Parameters:
spec (
ModuleSpec) – The specification of the Module layer.prev (
Union[Table[Any],Layer]) – If used as the first layer, the table that will be passed as an input; otherwise, the layer that precedes it.
- Return type:
Self
- forward(seqs)
Applies the module.
- Parameters:
seqs (
Tensor) – A sequence tensor of shape \((\text{minibatch},\text{length})\) or \((\text{minibatch},\text{in_channels},\text{in_length})\).- Return type:
Tensor- Returns:
A tensor of shape \((\text{minibatch},1,1)\).