neuralmonkey.experiment module

Provides a high-level API for training and using a model.

class neuralmonkey.experiment.Experiment(config_path: str, train_mode: bool = False, overwrite_output_dir: bool = False, config_changes: List[str] = None) → None

Bases: object

__init__(config_path: str, train_mode: bool = False, overwrite_output_dir: bool = False, config_changes: List[str] = None) → None

Initialize a Neural Monkey experiment.

Parameters:
  • config_path – The path to the experiment configuration file.
  • train_mode – Indicates whether the model should be prepared for training.
  • overwrite_output_dir – Indicates whether an existing experiment should be reused. If True, this overrides the setting in the configuration file.
  • config_changes – A list of modifications that will be made to the loaded configuration file before parsing.
build_model() → None

Build the configuration and the computational graph.

This function is invoked by all of the main entrypoints of the Experiment class (train, evaluate, run). It manages the building of the TensorFlow graph.

The bulding procedure is executed as follows: 1. Random seeds are set. 2. Configuration is built (instantiated) and normalized. 3. TODO(tf-data) tf.data.Dataset instance is created and registered

in the model parts. (This is not implemented yet!)
  1. Graph executors are “blessed”. This causes the rest of the TF Graph
    to be built.
  2. Sessions are initialized using the TF Manager object.
Raises:RuntimeError when the model is already built.
evaluate(dataset: neuralmonkey.dataset.Dataset, write_out: bool = False, batch_size: int = None, log_progress: int = 0, name: str = None) → Dict[str, Any]

Run the model on a given dataset and evaluate the outputs.

Parameters:
  • dataset – The dataset on which the model will be executed.
  • write_out – Flag whether the outputs should be printed to a file defined in the dataset object.
  • batch_size – size of the minibatch
  • log_progress – log progress every X seconds
  • name – The name of the evaluated dataset
Returns:

Dictionary of evaluation names and their values which includes the metrics applied on respective series loss and loss values from the run.

classmethod get_current() → neuralmonkey.experiment.Experiment

Return the experiment that is currently being built.

get_initializer(var_name: str, default: Callable = None) → Union[Callable, NoneType]

Return the initializer associated with the given variable name.

Calling the method marks the given initializer as used.

get_path(filename: str, cont_index: int = None) → str

Return the path to the most recent version of the given file.

load_variables(variable_files: List[str] = None) → None

Load variables from files.

Parameters:variable_files – A list of checkpoint file prefixes. A TF checkpoint is usually three files with a common prefix. This list should have the same number of files as there are sessions in the tf_manager object.
model

Get configuration namespace of the experiment.

The Experiment stores the configuration recipe in self.config. When the configuration is built (meaning the classes referenced from the config file are instantiated), it is saved in the model property of the experiment.

Returns:The built namespace config object.
Raises:RuntimeError when the configuration model has not been built.
register_inputs() → None
run_model(dataset: neuralmonkey.dataset.Dataset, write_out: bool = False, batch_size: int = None, log_progress: int = 0) → Tuple[List[neuralmonkey.runners.base_runner.ExecutionResult], Dict[str, List], Dict[str, List]]

Run the model on a given dataset.

Parameters:
  • dataset – The dataset on which the model will be executed.
  • write_out – Flag whether the outputs should be printed to a file defined in the dataset object.
  • batch_size – size of the minibatch
  • log_progress – log progress every X seconds
Returns:

A list of `ExecutionResult`s and a dictionary of the output series.

train() → None

Train model specified by this experiment.

This function is one of the main functions (entrypoints) called on the experiment. It builds the model (if needed) and runs the training procedure.

Raises:RuntimeError when the experiment is not intended for training.
update_initializers(initializers: Iterable[Tuple[str, Callable]]) → None

Update the dictionary mapping variable names to initializers.

neuralmonkey.experiment.create_config(train_mode: bool = True) → neuralmonkey.config.configuration.Configuration
neuralmonkey.experiment.save_git_info(git_commit_file: str, git_diff_file: str, branch: str = 'HEAD', repo_dir: str = None) → None
neuralmonkey.experiment.visualize_embeddings(sequences: List[neuralmonkey.model.sequence.EmbeddedFactorSequence], output_dir: str) → None