autogl.module.train

class autogl.module.train.BaseGraphClassificationTrainer(encoder: Union[autogl.module.model.pyg.base.BaseAutoModel, autogl.module.model.encoders.base_encoder.BaseEncoderMaintainer, str, None] = None, decoder: Union[autogl.module.model.decoders.base_decoder.BaseDecoderMaintainer, str, None] = None, num_features: Optional[int] = None, num_classes: Optional[int] = None, num_graph_features: int = 0, last_dim: Union[int, str] = 'auto', device: Union[torch.device, str, None] = None, feval: Union[Sequence[str], Sequence[Type[autogl.module.train.evaluation.Evaluation]]] = (<class 'autogl.module.train.evaluation.Acc'>,), loss: str = 'nll_loss')[source]
class autogl.module.train.BaseNodeClassificationTrainer(encoder: Union[autogl.module.model.pyg.base.BaseAutoModel, autogl.module.model.encoders.base_encoder.BaseEncoderMaintainer, str, None], decoder: Union[autogl.module.model.decoders.base_decoder.BaseDecoderMaintainer, str, None], num_features: int, num_classes: int, device: Union[torch.device, str, None] = None, feval: Union[Sequence[str], Sequence[Type[autogl.module.train.evaluation.Evaluation]]] = (<class 'autogl.module.train.evaluation.Acc'>,), loss: str = 'nll_loss')[source]
class autogl.module.train.BaseNodeClassificationHetTrainer(model: Union[autogl.module.model.pyg.base.BaseAutoModel, str], dataset: None, num_features: int, num_classes: int, device: Union[torch.device, str, None] = 'auto', feval: Union[Sequence[str], Sequence[Type[autogl.module.train.evaluation.Evaluation]]] = (<class 'autogl.module.train.evaluation.Acc'>,), loss: str = 'nll_loss')[source]

Base class of trainer for classification tasks

class autogl.module.train.BaseLinkPredictionTrainer(encoder: Union[autogl.module.model.pyg.base.BaseAutoModel, autogl.module.model.encoders.base_encoder.BaseEncoderMaintainer, str, None] = None, decoder: Union[autogl.module.model.decoders.base_decoder.BaseDecoderMaintainer, str, None] = None, num_features: Optional[int] = None, last_dim: Union[int, str] = 'auto', device: Union[torch.device, str, None] = None, feval: Union[Sequence[str], Sequence[Type[autogl.module.train.evaluation.Evaluation]]] = (<class 'autogl.module.train.evaluation.Acc'>,), loss: str = 'nll_loss')[source]
class autogl.module.train.GraphClassificationFullTrainer(model: Union[Tuple[autogl.module.model.encoders.base_encoder.BaseEncoderMaintainer, autogl.module.model.decoders.base_decoder.BaseDecoderMaintainer], autogl.module.model.encoders.base_encoder.BaseEncoderMaintainer, autogl.module.model.pyg.base.BaseAutoModel, str] = None, num_features: int = None, num_classes: int = None, num_graph_features: int = 0, optimizer: Type[torch.optim.optimizer.Optimizer] = <class 'torch.optim.adam.Adam'>, lr: float = 0.0001, max_epoch: int = 100, batch_size: int = 64, num_workers: int = 0, early_stopping_round: int = 7, weight_decay: float = 0.0001, device: Union[str, torch.device] = 'auto', init: bool = False, feval=[<class 'autogl.module.train.evaluation.Logloss'>], loss='nll_loss', lr_scheduler_type=None, criterion=None, *args, **kwargs)[source]

The graph classification trainer.

Used to automatically train the graph classification problem.

Parameters:
  • model – Models can be str, autogl.module.model.BaseAutoModel, autogl.module.model.encoders.BaseEncoderMaintainer or a tuple of (encoder, decoder) if need to specify both encoder and decoder. Encoder can be str or autogl.module.model.encoders.BaseEncoderMaintainer, and decoder can be str or autogl.module.model.decoders.BaseDecoderMaintainer. If only encoder is specified, decoder will be default to “logsoftmax”
  • num_features (int (Optional)) – The number of features in dataset. default None
  • num_classes (int (Optional)) – The number of classes. default None
  • num_graph_features (int (Optional)) – The number of graph level features. default 0.
  • optimizer (Optimizer of str) – The (name of) optimizer used to train and predict. default torch.optim.Adam
  • lr (float) – The learning rate of node classification task. default 1e-4
  • max_epoch (int) – The max number of epochs in training. default 100
  • early_stopping_round (int) – The round of early stop. default 100
  • weight_decay (float) – weight decay ratio, default 1e-4
  • device (torch.device or str) – The device where model will be running on.
  • init (bool) – If True(False), the model will (not) be initialized.
  • feval ((Sequence of) Evaluation or str) – The evaluation functions, default [LogLoss]
  • loss (str) – The loss used. Default nll_loss.
  • lr_scheduler_type (str (Optional)) – The lr scheduler type used. Default None.
duplicate_from_hyper_parameter(hp, encoder='same', decoder='same', restricted=True)[source]

The function of duplicating a new instance from the given hyperparameter.

Parameters:
  • hp (dict.) – The hyperparameter used in the new instance. Should contain 3 keys “trainer”, “encoder” “decoder”, with corresponding hyperparameters as values.
  • model (The new model) – Models can be str, autogl.module.model.BaseAutoModel, autogl.module.model.encoders.BaseEncoderMaintainer or a tuple of (encoder, decoder) if need to specify both encoder and decoder. Encoder can be str or autogl.module.model.encoders.BaseEncoderMaintainer, and decoder can be str or autogl.module.model.decoders.BaseDecoderMaintainer.
  • restricted (bool.) – If False(True), the hyperparameter should (not) be updated from origin hyperparameter.
Returns:

self – A new instance of trainer.

Return type:

autogl.train.GraphClassificationTrainer

evaluate(dataset, mask='val', feval=None)[source]

The function of training on the given dataset and keeping valid result.

Parameters:
  • dataset (The graph classification dataset used to be evaluated.) –
  • mask (train, val, or test.) – The dataset mask.
  • feval (str.) – The evaluation method used in this function.
Returns:

res

Return type:

The evaluation result on the given dataset.

get_valid_predict()[source]

Get the valid result.

get_valid_predict_proba()[source]

Get the valid result (prediction probability).

get_valid_score(return_major=True)[source]

The function of getting the valid score.

Parameters:return_major (bool.) – If True, the return only consists of the major result. If False, the return consists of the all results.
Returns:result
Return type:The valid score in training stage.
predict(dataset, mask='test')[source]

The function of predicting on the given dataset.

Parameters:
  • dataset (The graph classification dataset used to be predicted.) –
  • mask (train, val, or test.) – The dataset mask.
Returns:

Return type:

The prediction result of predict_proba.

predict_proba(dataset, mask='test', in_log_format=False)[source]

The function of predicting the probability on the given dataset.

Parameters:
  • dataset (The graph classification dataset used to be predicted.) –
  • mask (train, val, or test.) – The dataset mask.
  • in_log_format (bool.) – If True(False), the probability will (not) be log format.
Returns:

Return type:

The prediction result.

train(dataset, keep_valid_result=True)[source]

The function of training on the given dataset and keeping valid result.

Parameters:
  • dataset (The graph classification dataset used to be trained.) –
  • keep_valid_result (bool) – If True(False), save the validation result after training.
Returns:

self – A reference of current trainer.

Return type:

autogl.train.GraphClassificationTrainer

class autogl.module.train.NodeClassificationFullTrainer(model: Union[Tuple[autogl.module.model.encoders.base_encoder.BaseEncoderMaintainer, autogl.module.model.decoders.base_decoder.BaseDecoderMaintainer], autogl.module.model.encoders.base_encoder.BaseEncoderMaintainer, autogl.module.model.pyg.base.BaseAutoModel, str] = None, num_features: Optional[int] = None, num_classes: Optional[int] = None, optimizer: Union[str, Type[torch.optim.optimizer.Optimizer]] = <class 'torch.optim.adam.Adam'>, lr: float = 0.0001, max_epoch: int = 100, early_stopping_round: int = 100, weight_decay: float = 0.0001, device: Union[torch.device, str] = 'auto', init: bool = False, feval: Iterable[Type[autogl.module.train.evaluation.Evaluation]] = [<class 'autogl.module.train.evaluation.Logloss'>], loss: Union[Callable, str] = 'nll_loss', lr_scheduler_type: Optional[str] = None, **kwargs)[source]

The node classification trainer.

Used to automatically train the node classification problem.

Parameters:
  • model – Models can be str, autogl.module.model.BaseAutoModel, autogl.module.model.encoders.BaseEncoderMaintainer or a tuple of (encoder, decoder) if need to specify both encoder and decoder. Encoder can be str or autogl.module.model.encoders.BaseEncoderMaintainer, and decoder can be str or autogl.module.model.decoders.BaseDecoderMaintainer. If only encoder is specified, decoder will be default to “logsoftmax”
  • num_features (int (Optional)) – The number of features in dataset. default None
  • num_classes (int (Optional)) – The number of classes. default None
  • optimizer (Optimizer of str) – The (name of) optimizer used to train and predict. default torch.optim.Adam
  • lr (float) – The learning rate of node classification task. default 1e-4
  • max_epoch (int) – The max number of epochs in training. default 100
  • early_stopping_round (int) – The round of early stop. default 100
  • weight_decay (float) – weight decay ratio, default 1e-4
  • device (torch.device or str) – The device where model will be running on.
  • init (bool) – If True(False), the model will (not) be initialized.
  • feval ((Sequence of) Evaluation or str) – The evaluation functions, default [LogLoss]
  • loss (str) – The loss used. Default nll_loss.
  • lr_scheduler_type (str (Optional)) – The lr scheduler type used. Default None.
duplicate_from_hyper_parameter(hp: dict, model=None, restricted=True)[source]

The function of duplicating a new instance from the given hyperparameter.

Parameters:
  • hp (dict.) – The hyperparameter used in the new instance. Should contain 3 keys “trainer”, “encoder” “decoder”, with corresponding hyperparameters as values.
  • model – Models can be str, autogl.module.model.BaseAutoModel, autogl.module.model.encoders.BaseEncoderMaintainer or a tuple of (encoder, decoder) if need to specify both encoder and decoder. Encoder can be str or autogl.module.model.encoders.BaseEncoderMaintainer, and decoder can be str or autogl.module.model.decoders.BaseDecoderMaintainer.
  • restricted (bool.) – If False(True), the hyperparameter should (not) be updated from origin hyperparameter.
Returns:

self – A new instance of trainer.

Return type:

autogl.train.NodeClassificationTrainer

evaluate(dataset, mask=None, feval=None)[source]

Evaluate on the given dataset.

Parameters:
  • dataset (The node classification dataset used to be evaluated.) –
  • mask (train, val, or test.) – The dataset mask.
  • feval (str.) – The evaluation method used in this function.
Returns:

res

Return type:

The evaluation result on the given dataset.

classmethod get_task_name()[source]

Derive the task name. (NodeClassification)

get_valid_predict()[source]

Get the valid result.

get_valid_predict_proba()[source]

Get the valid result (prediction probability).

get_valid_score(return_major=True)[source]

The function of getting the valid score.

Parameters:return_major (bool.) – If True, the return only consists of the major result. If False, the return consists of the all results.
Returns:result
Return type:The valid score in training stage.
predict(dataset, mask=None)[source]

Predict on the given dataset using specified mask.

Parameters:
  • dataset (The node classification dataset used to be predicted.) –
  • mask (train, val, or test.) – The dataset mask.
Returns:

Return type:

The prediction result.

predict_proba(dataset, mask=None, in_log_format=False)[source]

Predict the probability on the given dataset using specified mask.

Parameters:
  • dataset (The node classification dataset used to be predicted.) –
  • mask (train, val, test, or Tensor.) – The dataset mask.
  • in_log_format (bool.) – If True(False), the probability will (not) be log format.
Returns:

Return type:

The prediction result.

train(dataset, keep_valid_result=True, train_mask=None)[source]

Train on the given dataset.

Parameters:
  • dataset (The node classification dataset used to be trained.) –
  • keep_valid_result (bool) – If True(False), save the validation result after training.
  • train_mask (The mask for training data) –
Returns:

self – A reference of current trainer.

Return type:

autogl.train.NodeClassificationTrainer

class autogl.module.train.NodeClassificationHetTrainer(model: Union[autogl.module.model.pyg.base.BaseAutoModel, str] = None, dataset=None, num_features=None, num_classes=None, optimizer=<class 'torch.optim.adamw.AdamW'>, lr=0.0001, max_epoch=100, early_stopping_round=100, weight_decay=0.0001, device='auto', init=False, feval=[<class 'autogl.module.train.evaluation.Logloss'>], loss='nll_loss', lr_scheduler_type=None, *args, **kwargs)[source]

The heterogeneous node classification trainer.

Parameters:
  • model (autogl.module.model.BaseAutoModel) – Currently Heterogeneous trainer doesn’t support decoupled model setting.
  • num_features (int (Optional)) – The number of features in dataset. default None
  • num_classes (int (Optional)) – The number of classes. default None
  • optimizer (Optimizer of str) – The (name of) optimizer used to train and predict. default torch.optim.Adam
  • lr (float) – The learning rate of node classification task. default 1e-4
  • max_epoch (int) – The max number of epochs in training. default 100
  • early_stopping_round (int) – The round of early stop. default 100
  • weight_decay (float) – weight decay ratio, default 1e-4
  • device (torch.device or str) – The device where model will be running on.
  • init (bool) – If True(False), the model will (not) be initialized.
  • feval ((Sequence of) Evaluation or str) – The evaluation functions, default [LogLoss]
  • loss (str) – The loss used. Default nll_loss.
  • lr_scheduler_type (str (Optional)) – The lr scheduler type used. Default None.
duplicate_from_hyper_parameter(hp: dict, model=None, restricted=True)[source]

The function of duplicating a new instance from the given hyperparameter.

Parameters:
  • hp (dict.) – The hyperparameter used in the new instance. Should contain 2 keys “trainer”, “encoder” with corresponding hyperparameters as values.
  • model (autogl.module.model.BaseAutoModel) – Currently Heterogeneous trainer doesn’t support decoupled model setting. If only encoder is specified, decoder will be default to “logsoftmax”
  • restricted (bool.) – If False(True), the hyperparameter should (not) be updated from origin hyperparameter.
Returns:

self – A new instance of trainer.

Return type:

autogl.train.NodeClassificationTrainer

evaluate(dataset, mask='val', feval=None)[source]

The function of training on the given dataset and keeping valid result. :param dataset: :type dataset: The node classification dataset used to be evaluated. :param mask: The dataset mask. :type mask: train, val, or test. :param feval: The evaluation method used in this function. :type feval: str.

Returns:res
Return type:The evaluation result on the given dataset.
classmethod get_task_name()[source]

Get task name (“NodeClassificationHet”)

get_valid_predict()[source]

Get the valid result.

get_valid_predict_proba()[source]

Get the valid result (prediction probability).

get_valid_score(return_major=True)[source]

The function of getting the valid score.

Parameters:return_major (bool.) – If True, the return only consists of the major result. If False, the return consists of the all results.
Returns:result
Return type:The valid score in training stage.
predict(dataset, mask='test')[source]

The function of predicting on the given dataset. :param dataset: :type dataset: The node classification dataset used to be predicted. :param mask: The dataset mask. :type mask: train, val, or test.

Returns:
Return type:The prediction result of predict_proba.
predict_proba(dataset, mask='test', in_log_format=False)[source]

The function of predicting the probability on the given dataset. :param dataset: :type dataset: The node classification dataset used to be predicted. :param mask: The dataset mask. :type mask: train, val, test, or Tensor. :param in_log_format: If True(False), the probability will (not) be log format. :type in_log_format: bool.

Returns:
Return type:The prediction result.
to(new_device)[source]

Transfer the trainer to another device :param device: The device this trainer will use :type device: str or torch.device

train(dataset, keep_valid_result=True, train_mask='train')[source]

The function of training on the given dataset and keeping valid result. :param dataset: :type dataset: The node classification dataset used to be trained. :param keep_valid_result: If True(False), save the validation result after training. :type keep_valid_result: bool :param train_mask: :type train_mask: The mask for training data

Returns:self – A reference of current trainer.
Return type:autogl.train.NodeClassificationTrainer
class autogl.module.train.LinkPredictionTrainer(model: Union[Tuple[autogl.module.model.encoders.base_encoder.BaseEncoderMaintainer, autogl.module.model.decoders.base_decoder.BaseDecoderMaintainer], autogl.module.model.encoders.base_encoder.BaseEncoderMaintainer, autogl.module.model.pyg.base.BaseAutoModel, str] = None, num_features=None, optimizer=<class 'torch.optim.adam.Adam'>, lr=0.0001, max_epoch=100, early_stopping_round=101, weight_decay=0.0001, device='auto', init=False, feval=[<class 'autogl.module.train.evaluation.Auc'>], loss='binary_cross_entropy_with_logits', lr_scheduler_type=None, *args, **kwargs)[source]

The link prediction trainer.

Used to automatically train the link prediction problem.

Parameters:
  • model – Models can be str, autogl.module.model.BaseAutoModel, autogl.module.model.encoders.BaseEncoderMaintainer or a tuple of (encoder, decoder) if need to specify both encoder and decoder. Encoder can be str or autogl.module.model.encoders.BaseEncoderMaintainer, and decoder can be str or autogl.module.model.decoders.BaseDecoderMaintainer. If only encoder is specified, decoder will be default to “logsoftmax”
  • num_features (int (Optional)) – The number of features in dataset. default None
  • optimizer (Optimizer of str) – The (name of) optimizer used to train and predict. default torch.optim.Adam
  • lr (float) – The learning rate of node classification task. default 1e-4
  • max_epoch (int) – The max number of epochs in training. default 100
  • early_stopping_round (int) – The round of early stop. default 100
  • weight_decay (float) – weight decay ratio, default 1e-4
  • device (torch.device or str) – The device where model will be running on.
  • init (bool) – If True(False), the model will (not) be initialized.
  • feval ((Sequence of) Evaluation or str) – The evaluation functions, default [LogLoss]
  • loss (str) – The loss used. Default nll_loss.
  • lr_scheduler_type (str (Optional)) – The lr scheduler type used. Default None.
duplicate_from_hyper_parameter(hp: dict, model=None, restricted=True)[source]

The function of duplicating a new instance from the given hyperparameter.

Parameters:
  • hp (dict.) – The hyperparameter used in the new instance. Should contain 3 keys “trainer”, “encoder” “decoder”, with corresponding hyperparameters as values.
  • model (The new model) – Models can be str, autogl.module.model.BaseAutoModel, autogl.module.model.encoders.BaseEncoderMaintainer or a tuple of (encoder, decoder) if need to specify both encoder and decoder. Encoder can be str or autogl.module.model.encoders.BaseEncoderMaintainer, and decoder can be str or autogl.module.model.decoders.BaseDecoderMaintainer.
  • restricted (bool.) – If False(True), the hyperparameter should (not) be updated from origin hyperparameter.
Returns:

self – A new instance of trainer.

Return type:

autogl.train.LinkPredictionTrainer

evaluate(dataset, mask=None, feval=None)[source]

The function of training on the given dataset and keeping valid result.

Parameters:
  • dataset (The link prediction dataset used to be evaluated.) –
  • mask (train, val, or test.) – The dataset mask.
  • feval (str.) – The evaluation method used in this function.
Returns:

res

Return type:

The evaluation result on the given dataset.

get_valid_predict()[source]

Get the valid result.

get_valid_predict_proba()[source]

Get the valid result (prediction probability).

get_valid_score(return_major=True)[source]

The function of getting the valid score.

Parameters:return_major (bool.) – If True, the return only consists of the major result. If False, the return consists of the all results.
Returns:result
Return type:The valid score in training stage.
predict(dataset, mask=None)[source]

The function of predicting on the given dataset.

Parameters:
  • dataset (The link prediction dataset used to be predicted.) –
  • mask (train, val, or test.) – The dataset mask.

:param .. Note:: Deprecated, this function will be removed in the future.:

Returns:
Return type:The prediction result of predict_proba.
predict_proba(dataset, mask=None, in_log_format=False)[source]

Predict the probability on the given dataset. :param dataset: :type dataset: The dataset used in predicting. :param mask: The dataset mask. :type mask: train, val, or test. :param in_log_format: If True(False), the probability will (not) be log format. :type in_log_format: bool.

Returns:
Return type:The prediction result.
train(dataset, keep_valid_result=True)[source]

train on the given dataset

Parameters:
  • dataset (The link prediction dataset used to be trained.) –
  • keep_valid_result (bool) – If True(False), save the validation result after training.
Returns:

self – A reference of current trainer.

Return type:

autogl.train.LinkPredictionTrainer

class autogl.module.train.NodeClassificationGraphSAINTTrainer(model: Union[autogl.module.model.pyg.base.BaseAutoModel, str], num_features: int, num_classes: int, optimizer: Union[Type[torch.optim.optimizer.Optimizer], str, None] = Ellipsis, lr: float = 0.0001, max_epoch: int = 100, early_stopping_round: int = 100, weight_decay: float = 0.0001, device: Optional[torch.device] = None, init: bool = True, feval: Union[Sequence[str], Sequence[Type[autogl.module.train.evaluation.Evaluation]]] = (<class 'autogl.module.train.evaluation.MicroF1'>,), loss: str = 'nll_loss', lr_scheduler_type: Optional[str] = None, **kwargs)[source]

The node classification trainer utilizing GraphSAINT technique.

Parameters:
  • model (BaseModel or str) – The name or class of model adopted
  • num_features (int) – number of features for each node provided by dataset
  • num_classes (int) – number of classes to classify
  • optimizer (Optimizer of str) – The (name of) optimizer used to train and predict.
  • lr (float) – The learning rate of link prediction task.
  • max_epoch (int) – The max number of epochs in training.
  • early_stopping_round (int) – The round of early stop.
  • weight_decay (float) – The weight decay argument for optimizer
  • device (torch.device or str) – The device where model will be running on.
  • init (bool) – If True(False), the model will (not) be initialized.
  • feval (str.) – The evaluation method adopted in this function.
duplicate_from_hyper_parameter(hp: Dict[str, Any], model: Optional[autogl.module.model.pyg.base.BaseAutoModel] = None) → autogl.module.train.node_classification_trainer.node_classification_sampled_trainer.NodeClassificationGraphSAINTTrainer[source]

The function of duplicating a new instance from the given hyper-parameter.

Parameters:
  • hp (dict.) – The hyper-parameter settings for the new instance.
  • model (BaseModel) – The name or class of model adopted
Returns:

instance – A new instance of trainer.

Return type:

NodeClassificationGraphSAINTTrainer

evaluate(dataset, mask: Optional[str] = None, feval: Union[None, Sequence[str], Sequence[Type[autogl.module.train.evaluation.Evaluation]]] = None) → Sequence[float][source]

The function of training on the given dataset and keeping valid result.

Parameters:
  • dataset – The dataset containing conventional data of integral graph adopted to train for node classification.
  • mask – The str of train, val, or test, representing the identifier for specific dataset mask.
  • feval (str.) – The evaluation method adopted in this function.
Returns:

result

Return type:

The evaluation result on the given dataset.

get_valid_predict() → torch.Tensor[source]

Get the valid result.

get_valid_predict_proba() → torch.Tensor[source]

Get the valid result (prediction probability).

get_valid_score(return_major: bool = True) → Union[Tuple[float, bool], Tuple[Sequence[float], Sequence[bool]]][source]

The function of getting the valid score.

Parameters:return_major (bool.) – If True, the return only consists of the major result. If False, the return consists of the all results.
Returns:result
Return type:The valid score.
predict(dataset, mask: Optional[str] = None) → torch.Tensor[source]

The function of predicting on the given dataset.

Parameters:
  • dataset – The dataset containing conventional data of integral graph adopted to train for node classification.
  • mask – The str of train, val, or test, representing the identifier for specific dataset mask.
Returns:

Return type:

The prediction result of predict_proba.

predict_proba(dataset, mask: Optional[str] = None, in_log_format: bool = False)[source]

The function of predicting the probability on the given dataset.

Parameters:
  • dataset – The dataset containing conventional data of integral graph adopted to train for node classification.
  • mask – The str of train, val, or test, representing the identifier for specific dataset mask.
  • in_log_format (bool.) – If True(False), the probability will (not) be log format.
Returns:

Return type:

The prediction result.

to(device: torch.device)[source]

Transfer the trainer to another device :param device: The device this trainer will use :type device: str or torch.device

train(dataset, keep_valid_result: bool = True)[source]

The function of training on the given dataset and keeping valid result.

Parameters:
  • dataset – The dataset containing conventional data of integral graph adopted to train for node classification.
  • keep_valid_result (bool) – If True(False), save the validation result after training.
Returns:

Return type:

None

class autogl.module.train.NodeClassificationLayerDependentImportanceSamplingTrainer(model: Union[autogl.module.model.pyg.base.BaseAutoModel, str], num_features: int, num_classes: int, optimizer: Union[Type[torch.optim.optimizer.Optimizer], str, None] = Ellipsis, lr: float = 0.0001, max_epoch: int = 100, early_stopping_round: int = 100, weight_decay: float = 0.0001, device: Optional[torch.device] = None, init: bool = True, feval: Union[Sequence[str], Sequence[Type[autogl.module.train.evaluation.Evaluation]]] = (<class 'autogl.module.train.evaluation.MicroF1'>,), loss: str = 'nll_loss', lr_scheduler_type: Optional[str] = None, **kwargs)[source]

The node classification trainer utilizing Layer dependent importance sampling technique.

Parameters:
  • model (BaseModel or str) – The name or class of model adopted
  • num_features (int) – number of features for each node provided by dataset
  • num_classes (int) – number of classes to classify
  • optimizer (Optimizer of str) – The (name of) optimizer used to train and predict.
  • lr (float) – The learning rate of link prediction task.
  • max_epoch (int) – The max number of epochs in training.
  • early_stopping_round (int) – The round of early stop.
  • weight_decay (float) – The weight decay argument for optimizer
  • device (torch.device or str) – The device where model will be running on.
  • init (bool) – If True(False), the model will (not) be initialized.
  • feval (str.) – The evaluation method adopted in this function.
duplicate_from_hyper_parameter(hp: Dict[str, Any], model: Optional[autogl.module.model.pyg.base.BaseAutoModel] = None) → autogl.module.train.node_classification_trainer.node_classification_sampled_trainer.NodeClassificationLayerDependentImportanceSamplingTrainer[source]

The function of duplicating a new instance from the given hyper-parameter.

Parameters:
  • hp (dict.) – The hyper-parameter settings for the new instance.
  • model (BaseModel) – The name or class of model adopted
Returns:

instance – A new instance of trainer.

Return type:

NodeClassificationLayerDependentImportanceSamplingTrainer

evaluate(dataset, mask: Optional[str] = None, feval: Union[None, Sequence[str], Sequence[Type[autogl.module.train.evaluation.Evaluation]]] = None) → Sequence[float][source]

The function of training on the given dataset and keeping valid result.

Parameters:
  • dataset – The dataset containing conventional data of integral graph adopted to train for node classification.
  • mask – The str of train, val, or test, representing the identifier for specific dataset mask.
  • feval (str.) – The evaluation method adopted in this function.
Returns:

result

Return type:

The evaluation result on the given dataset.

get_valid_predict() → torch.Tensor[source]

Get the valid result.

get_valid_predict_proba() → torch.Tensor[source]

Get the valid result (prediction probability).

get_valid_score(return_major: bool = True) → Union[Tuple[float, bool], Tuple[Sequence[float], Sequence[bool]]][source]

The function of getting the valid score.

Parameters:return_major (bool.) – If True, the return only consists of the major result. If False, the return consists of the all results.
Returns:result
Return type:The valid score.
predict(dataset, mask: Optional[str] = None) → torch.Tensor[source]

The function of predicting on the given dataset.

Parameters:
  • dataset – The dataset containing conventional data of integral graph adopted to train for node classification.
  • mask – The str of train, val, or test, representing the identifier for specific dataset mask.
Returns:

Return type:

The prediction result of predict_proba.

predict_proba(dataset, mask: Optional[str] = None, in_log_format: bool = False)[source]

The function of predicting the probability on the given dataset.

Parameters:
  • dataset – The dataset containing conventional data of integral graph adopted to train for node classification.
  • mask – The str of train, val, or test, representing the identifier for specific dataset mask.
  • in_log_format (bool.) – If True(False), the probability will (not) be log format.
Returns:

Return type:

The prediction result.

to(device: torch.device)[source]

Transfer the trainer to another device :param device: The device this trainer will use :type device: str or torch.device

train(dataset, keep_valid_result: bool = True)[source]

The function of training on the given dataset and keeping valid result.

Parameters:
  • dataset – The dataset containing conventional data of integral graph adopted to train for node classification.
  • keep_valid_result (bool) – If True(False), save the validation result after training.
Returns:

Return type:

None

class autogl.module.train.NodeClassificationNeighborSamplingTrainer(model: Union[autogl.module.model.pyg.base.BaseAutoModel, str], num_features: int, num_classes: int, optimizer: Union[Type[torch.optim.optimizer.Optimizer], str, None] = Ellipsis, lr: float = 0.0001, max_epoch: int = 100, early_stopping_round: int = 100, weight_decay: float = 0.0001, device: Optional[torch.device] = None, init: bool = True, feval: Union[Sequence[str], Sequence[Type[autogl.module.train.evaluation.Evaluation]]] = (<class 'autogl.module.train.evaluation.Logloss'>,), loss: str = 'nll_loss', lr_scheduler_type: Optional[str] = None, **kwargs)[source]

The node classification trainer utilizing Layer dependent importance sampling technique.

Parameters:
  • model (BaseModel or str) – The name or class of model adopted
  • num_features (int) – number of features for each node provided by dataset
  • num_classes (int) – number of classes to classify
  • optimizer (Optimizer of str) – The (name of) optimizer used to train and predict.
  • lr (float) – The learning rate of link prediction task.
  • max_epoch (int) – The max number of epochs in training.
  • early_stopping_round (int) – The round of early stop.
  • weight_decay (float) – The weight decay argument for optimizer
  • device (torch.device or str) – The device where model will be running on.
  • init (bool) – If True(False), the model will (not) be initialized.
  • feval (str.) – The evaluation method adopted in this function.
duplicate_from_hyper_parameter(hp: Dict[str, Any], model: Optional[autogl.module.model.pyg.base.BaseAutoModel] = None) → autogl.module.train.node_classification_trainer.node_classification_sampled_trainer.NodeClassificationNeighborSamplingTrainer[source]

The function of duplicating a new instance from the given hyper-parameter.

Parameters:
  • hp (dict.) – The hyper-parameter settings for the new instance.
  • model (BaseModel) – The name or class of model adopted
Returns:

instance – A new instance of trainer.

Return type:

NodeClassificationLayerDependentImportanceSamplingTrainer

evaluate(dataset, mask: Optional[str] = None, feval: Union[None, Sequence[str], Sequence[Type[autogl.module.train.evaluation.Evaluation]]] = None) → Sequence[float][source]

The function of training on the given dataset and keeping valid result.

Parameters:
  • dataset – The dataset containing conventional data of integral graph adopted to train for node classification.
  • mask – The str of train, val, or test, representing the identifier for specific dataset mask.
  • feval (str.) – The evaluation method adopted in this function.
Returns:

result

Return type:

The evaluation result on the given dataset.

get_valid_predict() → torch.Tensor[source]

Get the valid result.

get_valid_predict_proba() → torch.Tensor[source]

Get the valid result (prediction probability).

get_valid_score(return_major: bool = True) → Union[Tuple[float, bool], Tuple[Sequence[float], Sequence[bool]]][source]

The function of getting the valid score.

Parameters:return_major (bool.) – If True, the return only consists of the major result. If False, the return consists of the all results.
Returns:result
Return type:The valid score.
predict(dataset, mask: Optional[str] = None) → torch.Tensor[source]

The function of predicting on the given dataset.

Parameters:
  • dataset – The dataset containing conventional data of integral graph adopted to train for node classification.
  • mask – The str of train, val, or test, representing the identifier for specific dataset mask.
Returns:

Return type:

The prediction result of predict_proba.

predict_proba(dataset, mask: Optional[str] = None, in_log_format: bool = False)[source]

The function of predicting the probability on the given dataset.

Parameters:
  • dataset – The dataset containing conventional data of integral graph adopted to train for node classification.
  • mask – The str of train, val, or test, representing the identifier for specific dataset mask.
  • in_log_format (bool.) – If True(False), the probability will (not) be log format.
Returns:

Return type:

The prediction result.

to(device: torch.device)[source]

Transfer the trainer to another device :param device: The device this trainer will use :type device: str or torch.device

train(dataset, keep_valid_result: bool = True)[source]

The function of training on the given dataset and keeping valid result.

Parameters:
  • dataset – The dataset containing conventional data of integral graph adopted to train for node classification.
  • keep_valid_result (bool) – If True(False), save the validation result after training.
Returns:

Return type:

None