Combination layers

Perhaps unsurprisingly, combination layers are layers that combine other layers within one layer.

class dynn.layers.combination_layers.Parallel(*layers, dim=0, default_insert_dim=False)

Bases: dynn.layers.base_layers.BaseLayer

A helper class to run layers on the same input and concatenate their outputs

This can be used to create 2d conv layers with multiple kernel sizes by concatenating multiple dynn.layers.Conv2D .

Parameters:
  • layers (list) – A list of dynn.layers.BaseLayer objects. The first layer is the first one applied to the input. It is the programmer’s responsibility to make sure that the layers are compatible (eg. each layer takes the same input and the outputs have the same shape everywhere except along the concatenation dimension)
  • dim (int) – The concatenation dimension
  • default_insert_dim (bool, optional) – Instead of concatenating along an existing dimension, insert a a new dimension at dim and concatenate.
__call__(x, insert_dim=None, **kwargs)

Calls all the layers in succession.

Computes dy.concatenate([layers[0](x)...layers[n-1](x)], d=dim)

Parameters:
  • x (dynet.Expression) – Input expression
  • default_insert_dim (bool, optional) – Override the default
Returns:

Depending on

return_last_only, returns either the last expression or a list of all the layer’s outputs (first to last)

Return type:

dynet.Expression, list

__init__(*layers, dim=0, default_insert_dim=False)

Initialize self. See help(type(self)) for accurate signature.

class dynn.layers.combination_layers.Sequential(*layers, default_return_last_only=True)

Bases: dynn.layers.base_layers.BaseLayer

A helper class to stack layers into deep networks.

Parameters:
  • layers (list) – A list of dynn.layers.BaseLayer objects. The first layer is the first one applied to the input. It is the programmer’s responsibility to make sure that the layers are compatible (eg. the output of each layer can be fed into the next one)
  • default_return_last_only (bool, optional) – Return only the output of the last layer (as opposed to the output of all layers).
__call__(x, return_last_only=None)

Calls all the layers in succession.

Computes layers[n-1](layers[n-2](...layers[0](x)))

Parameters:
  • x (dynet.Expression) – Input expression
  • return_last_only (bool, optional) – Overrides the default
Returns:

Depending on

return_last_only, returns either the last expression or a list of all the layer’s outputs (first to last)

Return type:

dynet.Expression, list

__init__(*layers, default_return_last_only=True)

Initialize self. See help(type(self)) for accurate signature.