Bricks implemention#

Basic operations#

class Identity(input_shape=None, **args)[source]

Bases: Brick

forward(X)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

class MLP(input_shape, out_channels)[source]

Bases: Brick

forward(X)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

load_state_dict(state_dict, **kwargs)[source]

Copy parameters and buffers from state_dict into this module and its descendants.

If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.

Warning

If assign is True the optimizer must be created after the call to load_state_dict unless get_swap_module_params_on_conversion() is True.

Parameters:
  • state_dict (dict) – a dict containing parameters and persistent buffers.

  • strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True

  • assign (bool, optional) – When False, the properties of the tensors in the current module are preserved while when True, the properties of the Tensors in the state dict are preserved. The only exception is the requires_grad field of Default: ``False`

Returns:

  • missing_keys is a list of str containing any keys that are expected

    by this module but missing from the provided state_dict.

  • unexpected_keys is a list of str containing the keys that are not

    expected by this module but present in the provided state_dict.

Return type:

NamedTuple with missing_keys and unexpected_keys fields

Note

If a parameter or buffer is registered as None and its corresponding key exists in state_dict, load_state_dict() will raise a RuntimeError.

class Dropout(input_shape, rate)[source]

Bases: Brick

forward(X)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

One-dimensional Operations#

class Conv1d(input_shape, kernel_size, out_channels, padding='same', permute=False)[source]

Bases: Brick

forward(X)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

pad(X)[source]
class LayerNorm1d(input_shape, **args)[source]

Bases: Brick

forward(X)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

load_state_dict(state_dict, **kwargs)[source]

Copy parameters and buffers from state_dict into this module and its descendants.

If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.

Warning

If assign is True the optimizer must be created after the call to load_state_dict unless get_swap_module_params_on_conversion() is True.

Parameters:
  • state_dict (dict) – a dict containing parameters and persistent buffers.

  • strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True

  • assign (bool, optional) – When False, the properties of the tensors in the current module are preserved while when True, the properties of the Tensors in the state dict are preserved. The only exception is the requires_grad field of Default: ``False`

Returns:

  • missing_keys is a list of str containing any keys that are expected

    by this module but missing from the provided state_dict.

  • unexpected_keys is a list of str containing the keys that are not

    expected by this module but present in the provided state_dict.

Return type:

NamedTuple with missing_keys and unexpected_keys fields

Note

If a parameter or buffer is registered as None and its corresponding key exists in state_dict, load_state_dict() will raise a RuntimeError.

class BatchNorm1d(input_shape, **args)[source]

Bases: Brick

forward(X)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

load_state_dict(state_dict, **kwargs)[source]

Copy parameters and buffers from state_dict into this module and its descendants.

If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.

Warning

If assign is True the optimizer must be created after the call to load_state_dict unless get_swap_module_params_on_conversion() is True.

Parameters:
  • state_dict (dict) – a dict containing parameters and persistent buffers.

  • strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True

  • assign (bool, optional) – When False, the properties of the tensors in the current module are preserved while when True, the properties of the Tensors in the state dict are preserved. The only exception is the requires_grad field of Default: ``False`

Returns:

  • missing_keys is a list of str containing any keys that are expected

    by this module but missing from the provided state_dict.

  • unexpected_keys is a list of str containing the keys that are not

    expected by this module but present in the provided state_dict.

Return type:

NamedTuple with missing_keys and unexpected_keys fields

Note

If a parameter or buffer is registered as None and its corresponding key exists in state_dict, load_state_dict() will raise a RuntimeError.

class MaxPooling1D(input_shape, pool_size)[source]

Bases: Brick

forward(X)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

pad(X)[source]
class AVGPooling1D(input_shape, pool_size)[source]

Bases: Brick

forward(X)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

pad(X)[source]
class Attention1D(input_shape, Nh, d_out=None, gaussian_init_delta_std=2.0, alpha=46, init='random')[source]

Bases: Brick

get_attention_probs(X)[source]
forward(X)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

load_state_dict(state_dict, **kwargs)[source]

Copy parameters and buffers from state_dict into this module and its descendants.

If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.

Warning

If assign is True the optimizer must be created after the call to load_state_dict unless get_swap_module_params_on_conversion() is True.

Parameters:
  • state_dict (dict) – a dict containing parameters and persistent buffers.

  • strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True

  • assign (bool, optional) – When False, the properties of the tensors in the current module are preserved while when True, the properties of the Tensors in the state dict are preserved. The only exception is the requires_grad field of Default: ``False`

Returns:

  • missing_keys is a list of str containing any keys that are expected

    by this module but missing from the provided state_dict.

  • unexpected_keys is a list of str containing the keys that are not

    expected by this module but present in the provided state_dict.

Return type:

NamedTuple with missing_keys and unexpected_keys fields

Note

If a parameter or buffer is registered as None and its corresponding key exists in state_dict, load_state_dict() will raise a RuntimeError.

class Simple_1DGRU(input_shape, num_layers, hidden_size)[source]

Bases: Brick

forward(X, h=None)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

load_state_dict(state_dict, **kwargs)[source]

Copy parameters and buffers from state_dict into this module and its descendants.

If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.

Warning

If assign is True the optimizer must be created after the call to load_state_dict unless get_swap_module_params_on_conversion() is True.

Parameters:
  • state_dict (dict) – a dict containing parameters and persistent buffers.

  • strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True

  • assign (bool, optional) – When False, the properties of the tensors in the current module are preserved while when True, the properties of the Tensors in the state dict are preserved. The only exception is the requires_grad field of Default: ``False`

Returns:

  • missing_keys is a list of str containing any keys that are expected

    by this module but missing from the provided state_dict.

  • unexpected_keys is a list of str containing the keys that are not

    expected by this module but present in the provided state_dict.

Return type:

NamedTuple with missing_keys and unexpected_keys fields

Note

If a parameter or buffer is registered as None and its corresponding key exists in state_dict, load_state_dict() will raise a RuntimeError.

class Simple_1DLSTM(input_shape, hidden_size, num_layers)[source]

Bases: Brick

forward(X, h=None)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

load_state_dict(state_dict, **kwargs)[source]

Copy parameters and buffers from state_dict into this module and its descendants.

If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.

Warning

If assign is True the optimizer must be created after the call to load_state_dict unless get_swap_module_params_on_conversion() is True.

Parameters:
  • state_dict (dict) – a dict containing parameters and persistent buffers.

  • strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True

  • assign (bool, optional) – When False, the properties of the tensors in the current module are preserved while when True, the properties of the Tensors in the state dict are preserved. The only exception is the requires_grad field of Default: ``False`

Returns:

  • missing_keys is a list of str containing any keys that are expected

    by this module but missing from the provided state_dict.

  • unexpected_keys is a list of str containing the keys that are not

    expected by this module but present in the provided state_dict.

Return type:

NamedTuple with missing_keys and unexpected_keys fields

Note

If a parameter or buffer is registered as None and its corresponding key exists in state_dict, load_state_dict() will raise a RuntimeError.

class Simple_1DRNN(input_shape, num_layers, hidden_size)[source]

Bases: Brick

forward(X, h=None)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

load_state_dict(state_dict, **kwargs)[source]

Copy parameters and buffers from state_dict into this module and its descendants.

If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.

Warning

If assign is True the optimizer must be created after the call to load_state_dict unless get_swap_module_params_on_conversion() is True.

Parameters:
  • state_dict (dict) – a dict containing parameters and persistent buffers.

  • strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True

  • assign (bool, optional) – When False, the properties of the tensors in the current module are preserved while when True, the properties of the Tensors in the state dict are preserved. The only exception is the requires_grad field of Default: ``False`

Returns:

  • missing_keys is a list of str containing any keys that are expected

    by this module but missing from the provided state_dict.

  • unexpected_keys is a list of str containing the keys that are not

    expected by this module but present in the provided state_dict.

Return type:

NamedTuple with missing_keys and unexpected_keys fields

Note

If a parameter or buffer is registered as None and its corresponding key exists in state_dict, load_state_dict() will raise a RuntimeError.

Two-dimensional Operations#

class Conv2d(input_shape, out_channels, kernel_size, stride=None, padding=None, permute=False)[source]

Bases: Brick

forward(X)[source]

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.

pad(X)[source]
modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

load_state_dict(state_dict, **kwargs)[source]

Copy parameters and buffers from state_dict into this module and its descendants.

If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.

Warning

If assign is True the optimizer must be created after the call to load_state_dict unless get_swap_module_params_on_conversion() is True.

Parameters:
  • state_dict (dict) – a dict containing parameters and persistent buffers.

  • strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True

  • assign (bool, optional) – When False, the properties of the tensors in the current module are preserved while when True, the properties of the Tensors in the state dict are preserved. The only exception is the requires_grad field of Default: ``False`

Returns:

  • missing_keys is a list of str containing any keys that are expected

    by this module but missing from the provided state_dict.

  • unexpected_keys is a list of str containing the keys that are not

    expected by this module but present in the provided state_dict.

Return type:

NamedTuple with missing_keys and unexpected_keys fields

Note

If a parameter or buffer is registered as None and its corresponding key exists in state_dict, load_state_dict() will raise a RuntimeError.

class LayerNorm2d(input_shape, **args)[source]

Bases: Brick

forward(X)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

load_state_dict(state_dict, **kwargs)[source]

Copy parameters and buffers from state_dict into this module and its descendants.

If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.

Warning

If assign is True the optimizer must be created after the call to load_state_dict unless get_swap_module_params_on_conversion() is True.

Parameters:
  • state_dict (dict) – a dict containing parameters and persistent buffers.

  • strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True

  • assign (bool, optional) – When False, the properties of the tensors in the current module are preserved while when True, the properties of the Tensors in the state dict are preserved. The only exception is the requires_grad field of Default: ``False`

Returns:

  • missing_keys is a list of str containing any keys that are expected

    by this module but missing from the provided state_dict.

  • unexpected_keys is a list of str containing the keys that are not

    expected by this module but present in the provided state_dict.

Return type:

NamedTuple with missing_keys and unexpected_keys fields

Note

If a parameter or buffer is registered as None and its corresponding key exists in state_dict, load_state_dict() will raise a RuntimeError.

class BatchNorm2d(input_shape, **args)[source]

Bases: Brick

forward(X)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

load_state_dict(state_dict, **kwargs)[source]

Copy parameters and buffers from state_dict into this module and its descendants.

If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.

Warning

If assign is True the optimizer must be created after the call to load_state_dict unless get_swap_module_params_on_conversion() is True.

Parameters:
  • state_dict (dict) – a dict containing parameters and persistent buffers.

  • strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True

  • assign (bool, optional) – When False, the properties of the tensors in the current module are preserved while when True, the properties of the Tensors in the state dict are preserved. The only exception is the requires_grad field of Default: ``False`

Returns:

  • missing_keys is a list of str containing any keys that are expected

    by this module but missing from the provided state_dict.

  • unexpected_keys is a list of str containing the keys that are not

    expected by this module but present in the provided state_dict.

Return type:

NamedTuple with missing_keys and unexpected_keys fields

Note

If a parameter or buffer is registered as None and its corresponding key exists in state_dict, load_state_dict() will raise a RuntimeError.

class MaxPooling2D(input_shape, pool, stride=None)[source]

Bases: Brick

forward(X)[source]

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.

pad(X)[source]
modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

class AVGPooling2D(input_shape, pool, stride=None)[source]

Bases: Brick

forward(X)[source]

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.

pad(X)[source]
modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

class SpatialAttention(input_shape, Nh, d_out, gaussian_init_delta_std=2.0, alpha=46, init='random')[source]

Bases: Brick

get_attention_probs(X)[source]
forward(X)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

load_state_dict(state_dict, **kwargs)[source]

Copy parameters and buffers from state_dict into this module and its descendants.

If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.

Warning

If assign is True the optimizer must be created after the call to load_state_dict unless get_swap_module_params_on_conversion() is True.

Parameters:
  • state_dict (dict) – a dict containing parameters and persistent buffers.

  • strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True

  • assign (bool, optional) – When False, the properties of the tensors in the current module are preserved while when True, the properties of the Tensors in the state dict are preserved. The only exception is the requires_grad field of Default: ``False`

Returns:

  • missing_keys is a list of str containing any keys that are expected

    by this module but missing from the provided state_dict.

  • unexpected_keys is a list of str containing the keys that are not

    expected by this module but present in the provided state_dict.

Return type:

NamedTuple with missing_keys and unexpected_keys fields

Note

If a parameter or buffer is registered as None and its corresponding key exists in state_dict, load_state_dict() will raise a RuntimeError.

class TemporalAttention(input_shape, Nh, d_out, gaussian_init_delta_std=2.0, alpha=46, init='random')[source]

Bases: Brick

get_attention_probs(X)[source]
forward(X)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

load_state_dict(state_dict, **kwargs)[source]

Copy parameters and buffers from state_dict into this module and its descendants.

If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.

Warning

If assign is True the optimizer must be created after the call to load_state_dict unless get_swap_module_params_on_conversion() is True.

Parameters:
  • state_dict (dict) – a dict containing parameters and persistent buffers.

  • strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True

  • assign (bool, optional) – When False, the properties of the tensors in the current module are preserved while when True, the properties of the Tensors in the state dict are preserved. The only exception is the requires_grad field of Default: ``False`

Returns:

  • missing_keys is a list of str containing any keys that are expected

    by this module but missing from the provided state_dict.

  • unexpected_keys is a list of str containing the keys that are not

    expected by this module but present in the provided state_dict.

Return type:

NamedTuple with missing_keys and unexpected_keys fields

Note

If a parameter or buffer is registered as None and its corresponding key exists in state_dict, load_state_dict() will raise a RuntimeError.

class Simple_2DGRU(input_shape, hidden_size, num_layers)[source]

Bases: Brick

forward(X)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

load_state_dict(state_dict, **kwargs)[source]

Copy parameters and buffers from state_dict into this module and its descendants.

If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.

Warning

If assign is True the optimizer must be created after the call to load_state_dict unless get_swap_module_params_on_conversion() is True.

Parameters:
  • state_dict (dict) – a dict containing parameters and persistent buffers.

  • strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True

  • assign (bool, optional) – When False, the properties of the tensors in the current module are preserved while when True, the properties of the Tensors in the state dict are preserved. The only exception is the requires_grad field of Default: ``False`

Returns:

  • missing_keys is a list of str containing any keys that are expected

    by this module but missing from the provided state_dict.

  • unexpected_keys is a list of str containing the keys that are not

    expected by this module but present in the provided state_dict.

Return type:

NamedTuple with missing_keys and unexpected_keys fields

Note

If a parameter or buffer is registered as None and its corresponding key exists in state_dict, load_state_dict() will raise a RuntimeError.

class Simple_2DLSTM(input_shape, hidden_size, num_layers)[source]

Bases: Brick

forward(X)[source]

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.

modify_operation(input_shape)[source]

Modify the operation so it can take a tensor of shape input_shape as input.

Parameters:

input_shape (tuple) – Shape of the input tensor.

load_state_dict(state_dict, **kwargs)[source]

Copy parameters and buffers from state_dict into this module and its descendants.

If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.

Warning

If assign is True the optimizer must be created after the call to load_state_dict unless get_swap_module_params_on_conversion() is True.

Parameters:
  • state_dict (dict) – a dict containing parameters and persistent buffers.

  • strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s state_dict() function. Default: True

  • assign (bool, optional) – When False, the properties of the tensors in the current module are preserved while when True, the properties of the Tensors in the state dict are preserved. The only exception is the requires_grad field of Default: ``False`

Returns:

  • missing_keys is a list of str containing any keys that are expected

    by this module but missing from the provided state_dict.

  • unexpected_keys is a list of str containing the keys that are not

    expected by this module but present in the provided state_dict.

Return type:

NamedTuple with missing_keys and unexpected_keys fields

Note

If a parameter or buffer is registered as None and its corresponding key exists in state_dict, load_state_dict() will raise a RuntimeError.

Bricks variables#

Meta Variables#

dag_var(label, operations, complexity=None)[source]

Creates a DAG object, with some specified candidate operations.

Parameters:
  • label (str) – Name of the variable.

  • operations (DynamicBlock) – Candidate operations for the DAG.

  • complexity (int, default = None) – Maximum number of nodes for the randomly created DAGs.

Return type:

EvoDagVariable

node_var(label, operations, activation_function)[source]

Creates a node outside a DAG, with some specified candidate operation and activation function. This function is used when a node is needed outside any DAG. This situation often happens at the end of the network or between two DAGs. Usually, there will be only one input, therefore the combiner is useless and set to ‘add’.

Parameters:
  • label (str) – Name of the variable.

  • operations (HpVar) – Candidate operation for the node.

  • activation_function (nn.Module) – Activation function for the node.

Return type:

NodeVariable

activation_var(label, activations=None)[source]

Creates a CatVar with multiple possible activation functions. If the list of possible activation functions is not given (activations set to None), then the default list will be used.

Parameters:
  • label (str) – Name of the variable.

  • activations (list, default=None) – List of the possble activation functions.

Return type:

CatVar

operations_var(label, size, candidates)[source]

Creates a DynamicBlock repeating NodeVariable objects corresponding to the candidates operations for a given DAG. The combiners and the activation functions used are the ones by default. This function provides a way of using the package without having to dig too deeply into the various objects. The user is invited to directly manipulate the DynamicBlock class to customize the search space.

Parameters:
  • label (str) – Name of the variable.

  • size (int) – Maximum number of nodes that the DAG can have.

  • candidates (list or ['2d', '1d']) – List of the candidate operations for the DAG. The values ‘1d’ or ‘2d’ give the default operations for a 1d DAG or a 2d one.

Return type:

DynamicBlock

Basic Variables#

identity_var(label)[source]

Creates a HpVar corresponding to the identity operation.

Parameters:

label (str) – Name of the variable.

Return type:

HpVar

mlp_var(label, max_int=512)[source]

Creates a HpVar corresponding to the MLP (multi-layer perceptron) operation.

Parameters:
  • label (str) – Name of the variable.

  • max_int (int, default=512) – Maximum number of output channels.

Return type:

HpVar

mlp_const_var(label)[source]

Creates a HpVar corresponding to the MLP (multi-layers perceptron) operation, but with a fix number of output channels.

Parameters:
  • label (str) – Name of the variable.

  • out (int) – Number of output channels.

Return type:

HpVar

dropout(label)[source]

Creates a HpVar corresponding to the dropout operation. The dropout rate goes from 0 to 1.

Parameters:

label (str) – Name of the variable.

Return type:

HpVar

One-dimensional Variables#

conv_1d(label)[source]

Creates a HpVar corresponding to the one-dimensional convolution operation. By default the input is of shape (batch_size, L, C_in). Use permute=False if your input will be of size (batch_size, C_in, L). By default C_out will go from 1 to 512. By default the padding is set to same.

Parameters:
  • label (str) – Name of the variable.

  • max_out

Return type:

HpVar

const_conv_1d(label, kernel, max_out, permute=True)[source]
pooling_1d(label)[source]
attention_1d(label)[source]
norm_1d(label)[source]
recurrence_1d(label, max_h=20)[source]

Two-dimensional Variables#

conv_2d(label, max_out=10, permute=True)[source]
pooling_2d(label)[source]
pooling_2d_const_var(label, pool=None)[source]
norm_2d(label)[source]
recurrence_2d(label)[source]
attention_2d(label)[source]