SequentialBlock#

class deeplay.blocks.sequential.SequentialBlock(*args, **kwargs)#

Bases: Block

Methods Summary

append(layer[, name])

Append a layer to the block, executing it after all the other layers.

append_dropout(p[, name])

Append a dropout layer to the block.

configure(*args, **kwargs)

Configures the module with specified arguments.

forward(x)

Define the computation performed at every call.

insert(layer, after[, name])

Insert a layer to the block, executing it after a specific layer.

insert_dropout(p, after[, name])

Insert a dropout layer to the block.

prepend(layer[, name])

Prepend a layer to the block, executing it before all the other layers.

prepend_dropout(p[, name])

Prepend a dropout layer to the block.

remove(name[, allow_missing])

Remove a layer from the block.

remove_dropout([name, allow_missing])

Remove a dropout layer from the block.

set_dropout(p[, name, on_missing, after])

Set the dropout probability of a dropout layer.

Methods Documentation

append(layer: DeeplayModule, name: str | None = None)#

Append a layer to the block, executing it after all the other layers.

Parameters#

layerDeeplayLayer

The layer to append.

nameOptional[str], optional

The name of the layer, by default None. If None, the name of the layer will be the lowercase of its class name.

append_dropout(p: float, name: str | None = 'dropout')#

Append a dropout layer to the block.

Parameters#

pfloat

The dropout probability.

nameOptional[str], optional

The name of the dropout layer, by default “dropout”.

configure(*args, **kwargs)#

Configures the module with specified arguments.

This method allows dynamic configuration of the module’s properties and behaviors. It can be used to set or modify the attributes and parameters of the module and, if applicable, its child modules. The method intelligently handles both direct attribute configuration and delegation to child modules’ configure methods.

Parameters#

*argsAny

Positional arguments specifying the configuration settings. When the first argument is a string matching a configurable attribute, the method expects either one or two arguments: the attribute name and, optionally, its value. If the attribute is itself a DeeplayModule, subsequent arguments are passed to its configure method.

**kwargsAny

Keyword arguments for configuration settings. If provided, these are used to update the module’s configuration directly.

Raises#

ValueError

Raised if a configuration key is not recognized as a valid configurable for the module or if the provided arguments do not match the expected pattern for configuration.

Example Usage#

To configure a single attribute: ` module.configure('attribute_name', attribute_value) # or module.configure(attribute_name=attribute_value) `

To configure multiple attributes using keyword arguments: ` module.configure(attribute1=value1, attribute2=value2) `

To configure a child module’s attribute: ` module.configure('child_module_attribute', child_attribute=child_attribute_value) # or module.child_module.configure(child_attribute=child_attribute_value) `

forward(x)#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

insert(layer: DeeplayModule, after: str, name: str | None = None)#

Insert a layer to the block, executing it after a specific layer.

Parameters#

layerDeeplayLayer

The layer to insert.

afterstr

The name of the layer after which the new layer will be executed.

nameOptional[str], optional

The name of the layer, by default None.

Raises#

ValueError

If the layer after is not found in the block.

insert_dropout(p: float, after: str, name: str | None = 'dropout')#

Insert a dropout layer to the block.

Parameters#

pfloat

The dropout probability.

afterstr

The name of the layer after which the dropout layer will be executed.

nameOptional[str], optional

The name of the dropout layer, by default “dropout”.

Raises#

ValueError

If the layer after is not found in the block.

prepend(layer: DeeplayModule, name: str | None = None)#

Prepend a layer to the block, executing it before all the other layers.

Parameters#

layerDeeplayLayer

The layer to prepend.

nameOptional[str], optional

The name of the layer, by default None. If None, the name of the layer will be the lowercase of its class name.

prepend_dropout(p: float, name: str | None = 'dropout')#

Prepend a dropout layer to the block.

Parameters#

pfloat

The dropout probability.

nameOptional[str], optional

The name of the dropout layer, by default “dropout”.

remove(name: str, allow_missing: bool = False)#

Remove a layer from the block.

Parameters#

namestr

The name of the layer to remove.

allow_missingbool, optional

Whether to raise an error if the layer is not found in the block, by default False.

Raises#

ValueError

If the layer name is not found in the block and allow_missing is False.

remove_dropout(name: str = 'dropout', allow_missing: bool = False)#

Remove a dropout layer from the block.

Parameters#

namestr, optional

The name of the dropout layer to remove, by default “dropout”.

allow_missingbool, optional

Whether to raise an error if the dropout layer is not found in the block, by default False.

Raises#

ValueError

If the dropout layer name is not found in the block and allow_missing is False.

set_dropout(p: float, name: str = 'dropout', on_missing: Literal['append', 'prepend', 'insert'] = 'append', after: str | None = None)#

Set the dropout probability of a dropout layer.

Parameters#

pfloat

The dropout probability.

namestr, optional

The name of the dropout layer, by default “dropout”.

on_missingstr, optional

The action to take if the dropout layer is not found in the block. If “append”, a new dropout layer will be appended to the block. If “prepend”, a new dropout layer will be prepended to the block. If “insert”, a new dropout layer will be inserted after the layer specified in after. By default “append”.

afterstr, optional

The name of the layer after which the dropout layer will be executed if on_missing is “insert”, by default None.