pyprobound.layers.pad.Pad
- class Pad(layer_spec, input_shape, min_input_length, max_input_length)
Bases:
LayerLayer wrapper for F.pad.
- __init__(layer_spec, input_shape, min_input_length, max_input_length)
Initializes the padding layer.
- Parameters:
layer_spec (
PadSpec) – The specification of the padding 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 a padding over the last dimension.
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.
- forward(seqs)
Applies a padding over the last dimension.
- Parameters:
seqs (
Tensor) – A sequence tensor of shape \((\text{minibatch},\text{channels},\text{length})\).- Return type:
Tensor- Returns:
The maxpooled tensor of shape \((\text{minibatch},\text{channels},\) \(\text{ceil_mode ? ceil : floor} (\text{length} / \text{kernel_size}))\).