Model¶
A model is a thin layer of abstraction between the user-defined computation graph, bricks, parameters and main loop extensions. This module provides the basic AbstractModel interface as well as its implementations (currently only Model).
- class blocks.model.AbstractModel¶
Bases: object
A parameterized entity trained in the main loop.
A model is a parameterized entity the user trains a in a main loop. The following are traits of every model:
- It has parameters and supports a way to access them. In addition to returning handles to parameter objects it can return their values as numpy arrays and set their values to given numpy arrays.
- It has an optimality objective.
- It can be serialized and deserialized by mean of pickling.
- It might have bricks as its components.
This class provides an interface for models. For experiments use a subclass, e.g. the Model.
- get_objective()¶
Return the optimization objective.
- get_parameter_dict()¶
Return the model parameters.
Returns: parameters – Dictionary of (name, parameter) pairs. Return type: OrderedDict
- get_parameter_values()¶
Return the values of model parameters.
The default implementation assumes that parameters are Theano shared variables.
Returns: parameter_values – Dictionary of (parameter name, ndarray) pairs. Return type: OrderedDict
- get_top_bricks()¶
Return the top-level bricks that are used in the model.
Returns: bricks – List of bricks. Return type: list
- class blocks.model.Model(outputs)¶
Bases: blocks.model.AbstractModel, blocks.graph.ComputationGraph
Wraps a computation graph to support model interface.
This model covers the most common case when all information about the model is contained in an annotated computation graph: parameters are identified by the roles, bricks found by annotations. Due to frequency of this case this class is called simply ‘Model’ and not ‘ComputationGraphModel’.
Todo
Overriding the automatically found parameters and bricks might be needed.
If there are top bricks in scan inner graphs, those will not be found.
Parameters: outputs ((list of) Variable) – The output variables of the computation graph. - get_objective()¶
Return the output variable, if there is a single one.
If there is only one output variable, it is a reasonable default setting to assume that it is the optimization objective.
- get_parameter_dict()¶
Get model parameters.
The parameter names are formed from positions of their owner bricks in the bricks hierarchy. The variable names are used for the parameters that do not belong to any brick.
- get_top_bricks()¶