pyprobound.layers.roll.Roll

class Roll(layer_spec, input_shape, min_input_length, max_input_length)

Bases: Layer

Layer for changing between left, right, and center padding.

__init__(layer_spec, input_shape, min_input_length, max_input_length)

Initializes the rolling layer.

Parameters:
  • layer_spec (RollSpec) – The specification of the rolling 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)

Justifies the sequences to the specified end.

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_channels

The number of input channels.

input_shape

The number of elements in an input sequence.

max_input_length

The maximum number of finite elements in an input sequence.

min_input_length

The minimum number of finite elements in an input sequence.

out_channels

The number of output channels.

unfreezable

alias of Literal['all']

Non-Inherited Members

classmethod from_spec(spec, prev)

Creates a new instance from a specification and an input component.

Parameters:
  • spec (RollSpec) – The specification of the roll 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)

Justifies the sequences to the specified end.

Parameters:

seqs (Tensor) – A sequence tensor of shape \((\text{minibatch},\text{length})\) or \((\text{minibatch},\text{channels},\text{length})\).

Return type:

Tensor

Returns:

The re-justified tensor with same dimensions as the input, of shape \((\ldots,\text{max_length is None ? length : max_length})\).