pydgn.experiment

experiment.experiment

class pydgn.experiment.experiment.Experiment(model_configuration: dict, exp_path: str, exp_seed: int)

Bases: object

Class that handles a single experiment.

Parameters
  • model_configuration (dict) – the dictionary holding the experiment-specific configuration

  • exp_path (str) – path to the experiment folder

  • exp_seed (int) – the experiment’s seed to use

_create_engine(config: pydgn.evaluation.config.Config, model: pydgn.model.interface.ModelInterface, device: str, evaluate_every: int, reset_eval_model_hidden_state: bool) pydgn.training.engine.TrainingEngine

Utility that instantiates the training engine. It looks for pre-defined fields in the configuration file, i.e. loss, scorer, optimizer, scheduler, gradient_clipper, early_stopper and plotter, all of which should be classes implementing the EventHandler interface

Parameters
  • config (Config) – the configuration dictionary

  • model – the model that needs be trained

  • device (str) – the string with the CUDA device to be used, or cpu

  • evaluate_every (int) – number of epochs after which to log information

  • reset_eval_model_hidden_state (bool) – [temporal graph learning] Used when we want to reset the state after performing previous inference. It should be False when we are dealing with a single temporal graph sequence, because we don’t want to reset the hidden state after processing the previous [training/validation] time steps.

Returns

a TrainingEngine object

_create_model(dim_node_features: int, dim_edge_features: int, dim_target: int, readout_classname: str, config: pydgn.evaluation.config.Config) pydgn.model.interface.ModelInterface

Instantiates a model that implements the ModelInterface interface

Parameters
  • dim_node_features (int) – number of node features

  • dim_edge_features (int) – number of edge features

  • dim_target (int) – target dimension

  • readout_classname (str) – string containing the model’s class

  • config (Config) – the configuration dictionary

Returns

a model that implements the ModelInterface interface

_return_class_and_args(key: str) Tuple[Callable[[...], object], dict]

Returns the class and arguments associated to a specific key in the configuration file.

Parameters
  • config – the configuration dictionary

  • key – a string representing a particular class in the configuration dictionary

Returns

a tuple (class, dict of arguments), or (None, None) if the key is not present in the config dictionary

create_incremental_engine(model: pydgn.model.interface.ModelInterface) pydgn.training.engine.TrainingEngine

Instantiates the training engine by using the layer_config key in the config file

Parameters

model – the model that needs be trained

Returns

a TrainingEngine object

create_incremental_model(dim_node_features: int, dim_edge_features: int, dim_target: int, depth: int, prev_outputs_to_consider: List[int]) pydgn.model.interface.ModelInterface

Instantiates a layer of an incremental architecture. It assumes the config file has a field layer_config and another layer_config.arbitrary_function_config that holds any kind of information for the arbitrary function of an incremental architecture

Parameters
  • dim_node_features – input node features

  • dim_edge_features – input edge features

  • dim_target – target size

  • depth – current depth of the architecture

  • prev_outputs_to_consider – A list of previous layers to consider, e.g., [1,2] means the last two previous layers.

Returns

a layer of a model that implements the ModelInterface interface

create_supervised_engine(model: pydgn.model.interface.ModelInterface) pydgn.training.engine.TrainingEngine

Instantiates the training engine by using the supervised_config key in the config file

Parameters

model – the model that needs be trained

Returns

a TrainingEngine object

create_supervised_model(dim_node_features: int, dim_edge_features: int, dim_target: int) pydgn.model.interface.ModelInterface

Instantiates a supervised model that implements the ModelInterface interface, using the supervised_config field in the configuration file.

Parameters
  • dim_node_features (int) – number of node features

  • dim_edge_features (int) – number of edge features

  • dim_target (int) – target dimension

Returns

a model that implements the ModelInterface interface

create_supervised_readout(dim_node_features: int, dim_edge_features: int, dim_target: int) pydgn.model.interface.ReadoutInterface

Instantiates an supervised readout that implements the ReadoutInterface interface, using the supervised_config field in the configuration file.

Parameters
  • dim_node_features (int) – number of node features

  • dim_edge_features (int) – number of edge features

  • dim_target (int) – target dimension

Returns

a model that implements the ReadoutInterface interface

create_unsupervised_engine(model: pydgn.model.interface.ModelInterface) pydgn.training.engine.TrainingEngine

Instantiates the training engine by using the unsupervised_config key in the config file

Parameters

model – the model that needs be trained

Returns

a TrainingEngine object

create_unsupervised_model(dim_node_features: int, dim_edge_features: int, dim_target: int) pydgn.model.interface.ModelInterface

Instantiates an unsupervised model that implements the ModelInterface interface, using the unsupervised_config field in the configuration file.

Parameters
  • dim_node_features (int) – number of node features

  • dim_edge_features (int) – number of edge features

  • dim_target (int) – target dimension

Returns

a model that implements the ModelInterface interface

run_test(dataset_getter: pydgn.data.provider.DataProvider, logger: pydgn.log.logger.Logger) Tuple[dict, dict, dict]

This function returns the training, validation and test results for a final run. Do not use the test to train the model nor for early stopping reasons! If possible, rely on already available subclasses of this class.

Parameters
Returns

a tuple of training,validation,test dictionaries. Each dictionary has two keys:

  • LOSS (as defined in pydgn.static)

  • SCORE (as defined in pydgn.static)

For instance, training_results[SCORE] is a dictionary itself with other fields to be used by the evaluator.

run_valid(dataset_getter, logger) Tuple[dict, dict]

This function returns the training and validation results for a model selection run. Do not attempt to load the test set inside this method! If possible, rely on already available subclasses of this class.

Parameters
Returns

a tuple of training and test dictionaries. Each dictionary has two keys:

  • LOSS (as defined in pydgn.static)

  • SCORE (as defined in pydgn.static)

For instance, training_results[SCORE] is a dictionary itself with other fields to be used by the evaluator.

experiment.semi_supervised_task

class pydgn.experiment.semi_supervised_task.SemiSupervisedTask(model_configuration, exp_path, exp_seed)

Bases: pydgn.experiment.experiment.Experiment

Class that implements a semi-supervised experiment. There is an unsupervised_config field in the configuration file that is used, together with the field model, to produce unsupervised embeddings. These are later used by a readout extracted from a supervised_config field in the configuration file to perform the supervised task.

run_test(dataset_getter, logger)

This function returns the training, validation and test results for a final run. Do not use the test to train the model nor for early stopping! If possible, rely on already available subclasses of this class.

It implements a semi-supervised training scheme where first a model is trained (possibly with unsupervised loss, hence the name semi-supervised) and a list of Data objects are produced according to the training engine used. Then a second training is carried out where the data list is used as new dataset. The result of this second training is used for the risk assessment procedure.

Parameters
Returns

a tuple of training,validation,test dictionaries. Each dictionary has two keys:

  • LOSS (as defined in pydgn.static)

  • SCORE (as defined in pydgn.static)

For instance, training_results[SCORE] is a dictionary itself with other fields to be used by the evaluator.

run_valid(dataset_getter, logger)

This function returns the training and validation results for a model selection run. Do not attempt to load the test set inside this method! If possible, rely on already available subclasses of this class.

It implements a semi-supervised training scheme where first a model is trained (possibly with unsupervised loss, hence the name semi-supervised) and a list of Data objects are produced according to the training engine used. Then a second training is carried out where the data list is used as new dataset. The result of this second training is used for the model selection procedure.

Parameters
Returns

a tuple of training and test dictionaries. Each dictionary has two keys:

  • LOSS (as defined in pydgn.static)

  • SCORE (as defined in pydgn.static)

For instance, training_results[SCORE] is a dictionary itself with other fields to be used by the evaluator.

experiment.supervised_task

class pydgn.experiment.supervised_task.SupervisedTask(model_configuration: dict, exp_path: str, exp_seed: int)

Bases: pydgn.experiment.experiment.Experiment

Class that implements a standard supervised experiment.

run_test(dataset_getter, logger)

This function returns the training, validation and test results for a final run. Do not use the test to train the model nor for early stopping reasons! If possible, rely on already available subclasses of this class.

It implements a simple supervised training scheme.

Parameters
Returns

a tuple of training,validation,test dictionaries. Each dictionary has two keys:

  • LOSS (as defined in pydgn.static)

  • SCORE (as defined in pydgn.static)

For instance, training_results[SCORE] is a dictionary itself with other fields to be used by the evaluator.

run_valid(dataset_getter, logger)

This function returns the training and validation results for a model selection run. Do not attempt to load the test set inside this method! If possible, rely on already available subclasses of this class.

It implements a simple supervised training scheme.

Parameters
Returns

a tuple of training and test dictionaries. Each dictionary has two keys:

  • LOSS (as defined in pydgn.static)

  • SCORE (as defined in pydgn.static)

For instance, training_results[SCORE] is a dictionary itself with other fields to be used by the evaluator.

experiment.util

pydgn.experiment.util.s2c(class_name: str) Callable[[...], object]

Converts a dotted path to the corresponding class

Parameters

class_name (str) – dotted path to class name

Returns

the class to be used