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 (
VariableRoleinstance) –
Notes
Some roles are subroles of others (e.g.
WEIGHTis a subrole ofPARAMETER). 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. replaceWEIGHTwithPARAMETER) 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
- var (
Roles¶
All roles are implemented as subclasses of VariableRole.
The actual roles are instances of the different subclasses of
VariableRole. They are:
-
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