neuralmonkey.model.model_part module

Basic functionality of all model parts.

class neuralmonkey.model.model_part.GenericModelPart

Bases: object

Base class for Neural Monkey model parts.

Neural Monkey dynamically decides which model parts are in use when using a specific trainer or a runner. Each trainer/runner holds a reference to a top-level model part, which is then responsible for collecting references to all Parameterized and Feedable objects that contribute to the computation of its Tensors. This behavior is implemented using the get_dependencies method, which is called recursively on all instances of GenericModelPart class that are references from within a model part.

Apart from the get_dependencies method, this class also provides the dependencies property which store the names of the Python class attributes that are regarded as potential dependents of the GenericModelPart object. These dependents are automatically checked for type and when they are instances of the GenericModelPart class, results of their get_dependencies are united and returned as dependencies of the current object.

dependencies

Return a list of attribute names regarded as dependents.

get_dependencies() → Tuple[Set[neuralmonkey.model.feedable.Feedable], Set[neuralmonkey.model.parameterized.Parameterized]]

Collect all dependents of this object recursively.

The dependents are collected using the dependencies property. Each stores a potential dependent object. If the object exsits and is an instance of GenericModelPart, dependents are collected recursively by calling its get_dependencies method.

If the object itself is instance of Feedable or Parameterized class, it is added among the respective sets returned.

Returns:A Tuple of Set`s of `Feedable and Parameterized objects.
class neuralmonkey.model.model_part.ModelPart(name: str, reuse: Union[neuralmonkey.model.model_part.ModelPart, NoneType] = None, save_checkpoint: str = None, load_checkpoint: str = None, initializers: List[Tuple[str, Callable]] = None) → None

Bases: neuralmonkey.model.parameterized.Parameterized, neuralmonkey.model.model_part.GenericModelPart, neuralmonkey.model.feedable.Feedable

Base class of all parametric feedable model parts.

Serves as a syntactic sugar for labeling Feedable, Parameterized, and GenericModelPart objects.

__init__(name: str, reuse: Union[neuralmonkey.model.model_part.ModelPart, NoneType] = None, save_checkpoint: str = None, load_checkpoint: str = None, initializers: List[Tuple[str, Callable]] = None) → None

Construct a new parameterized object.

Parameters:
  • name – The name for the model part. Will be used in the variable and name scopes.
  • reuse – Optional parameterized part with which to share parameters.
  • save_checkpoint – Optional path to a checkpoint file which will store the parameters of this object.
  • load_checkpoint – Optional path to a checkpoint file from which to load initial variables for this object.
  • initializers – An InitializerSpecs instance with specification of the initializers.