Variable roles

blocks.roles.add_role(var, role)[source]

Add a role to a given Theano variable.

Parameters:
  • var (TensorVariable) – The variable to assign the new role to.
  • role (VariableRole instance) –

Notes

Some roles are subroles of others (e.g. WEIGHT is a subrole of PARAMETER). This function will not add a role if a more specific role has already been added. If you need to replace a role with a parent role (e.g. replace WEIGHT with PARAMETER) you must do so manually.

Examples

>>> from theano import tensor
>>> W = tensor.matrix()
>>> from blocks.roles import PARAMETER, WEIGHT
>>> add_role(W, PARAMETER)
>>> print(*W.tag.roles)
PARAMETER
>>> add_role(W, WEIGHT)
>>> print(*W.tag.roles)
WEIGHT
>>> add_role(W, PARAMETER)
>>> print(*W.tag.roles)
WEIGHT

Roles

All roles are implemented as subclasses of VariableRole.

class blocks.roles.VariableRole[source]

Base class for all variable roles.

The actual roles are instances of the different subclasses of VariableRole. They are:

blocks.roles.INPUT = INPUT

The input of a Brick

blocks.roles.OUTPUT = OUTPUT

The output of a Brick

blocks.roles.AUXILIARY = AUXILIARY

Variables added to the graph as annotations

blocks.roles.COST = COST

A scalar cost that can be used to train or regularize

blocks.roles.PARAMETER = PARAMETER

A parameter of the model

blocks.roles.WEIGHT = WEIGHT

The weight matrices of linear transformations

blocks.roles.BIAS = BIAS

Biases of linear transformations

blocks.roles.FILTER = FILTER

The filters (kernels) of a convolution operation