chemprop.nn.predictors#

Module Contents#

Classes#

Predictor

A Predictor is a protocol that defines a differentiable function

RegressionFFN

A _FFNPredictorBase is the base class for all Predictors that use an

MveFFN

A _FFNPredictorBase is the base class for all Predictors that use an

EvidentialFFN

A _FFNPredictorBase is the base class for all Predictors that use an

BinaryClassificationFFNBase

A _FFNPredictorBase is the base class for all Predictors that use an

BinaryClassificationFFN

A _FFNPredictorBase is the base class for all Predictors that use an

BinaryDirichletFFN

A _FFNPredictorBase is the base class for all Predictors that use an

MulticlassClassificationFFN

A _FFNPredictorBase is the base class for all Predictors that use an

MulticlassDirichletFFN

A _FFNPredictorBase is the base class for all Predictors that use an

SpectralFFN

A _FFNPredictorBase is the base class for all Predictors that use an

Attributes#

PredictorRegistry

class chemprop.nn.predictors.Predictor(*args, **kwargs)[source]#

Bases: torch.nn.Module, chemprop.nn.hparams.HasHParams

A Predictor is a protocol that defines a differentiable function \(f\) : mathbb R^d mapsto mathbb R^o

input_dim: int#

the input dimension

output_dim: int#

the output dimension

n_tasks: int#

the number of tasks t to predict for each input

n_targets: int#

the number of targets s to predict for each task t

criterion: chemprop.nn.loss.LossFunction#

the loss function to use for training

task_weights: torch.Tensor#

the weights to apply to each task when calculating the loss

output_transform: chemprop.nn.transforms.UnscaleTransform#

the transform to apply to the output of the predictor

abstract forward(Z)[source]#
Parameters:

Z (torch.Tensor)

Return type:

torch.Tensor

abstract train_step(Z)[source]#
Parameters:

Z (torch.Tensor)

Return type:

torch.Tensor

abstract encode(Z, i)[source]#

Calculate the i-th hidden representation

Parameters:
  • Z (Tensor) – a tensor of shape n x d containing the input data to encode, where d is the input dimensionality.

  • i (int) –

    The stop index of slice of the MLP used to encode the input. That is, use all layers in the MLP _up to_ i (i.e., MLP[:i]). This can be any integer value, and the behavior of this function is dependent on the underlying list slicing behavior. For example:

    • i=0: use a 0-layer MLP (i.e., a no-op)

    • i=1: use only the first block

    • i=-1: use _up to_ the final block

Returns:

a tensor of shape n x h containing the i-th hidden representation, where h is the number of neurons in the i-th hidden layer.

Return type:

Tensor

chemprop.nn.predictors.PredictorRegistry#
class chemprop.nn.predictors.RegressionFFN(n_tasks=1, input_dim=DEFAULT_HIDDEN_DIM, hidden_dim=300, n_layers=1, dropout=0.0, activation='relu', criterion=None, task_weights=None, threshold=None, output_transform=None)[source]#

Bases: _FFNPredictorBase

A _FFNPredictorBase is the base class for all Predictors that use an underlying SimpleFFN to map the learned fingerprint to the desired output.

Parameters:
n_targets = 1#
train_step(Z)[source]#
Parameters:

Z (torch.Tensor)

Return type:

torch.Tensor

class chemprop.nn.predictors.MveFFN(n_tasks=1, input_dim=DEFAULT_HIDDEN_DIM, hidden_dim=300, n_layers=1, dropout=0.0, activation='relu', criterion=None, task_weights=None, threshold=None, output_transform=None)[source]#

Bases: RegressionFFN

A _FFNPredictorBase is the base class for all Predictors that use an underlying SimpleFFN to map the learned fingerprint to the desired output.

Parameters:
n_targets = 2#
forward(Z)[source]#
Parameters:

Z (torch.Tensor)

Return type:

torch.Tensor

train_step(Z)[source]#
Parameters:

Z (torch.Tensor)

Return type:

torch.Tensor

class chemprop.nn.predictors.EvidentialFFN(n_tasks=1, input_dim=DEFAULT_HIDDEN_DIM, hidden_dim=300, n_layers=1, dropout=0.0, activation='relu', criterion=None, task_weights=None, threshold=None, output_transform=None)[source]#

Bases: RegressionFFN

A _FFNPredictorBase is the base class for all Predictors that use an underlying SimpleFFN to map the learned fingerprint to the desired output.

Parameters:
n_targets = 4#
forward(Z)[source]#
Parameters:

Z (torch.Tensor)

Return type:

torch.Tensor

train_step(Z)[source]#
Parameters:

Z (torch.Tensor)

Return type:

torch.Tensor

class chemprop.nn.predictors.BinaryClassificationFFNBase(n_tasks=1, input_dim=DEFAULT_HIDDEN_DIM, hidden_dim=300, n_layers=1, dropout=0.0, activation='relu', criterion=None, task_weights=None, threshold=None, output_transform=None)[source]#

Bases: _FFNPredictorBase

A _FFNPredictorBase is the base class for all Predictors that use an underlying SimpleFFN to map the learned fingerprint to the desired output.

Parameters:
class chemprop.nn.predictors.BinaryClassificationFFN(n_tasks=1, input_dim=DEFAULT_HIDDEN_DIM, hidden_dim=300, n_layers=1, dropout=0.0, activation='relu', criterion=None, task_weights=None, threshold=None, output_transform=None)[source]#

Bases: BinaryClassificationFFNBase

A _FFNPredictorBase is the base class for all Predictors that use an underlying SimpleFFN to map the learned fingerprint to the desired output.

Parameters:
n_targets = 1#
forward(Z)[source]#
Parameters:

Z (torch.Tensor)

Return type:

torch.Tensor

train_step(Z)[source]#
Parameters:

Z (torch.Tensor)

Return type:

torch.Tensor

class chemprop.nn.predictors.BinaryDirichletFFN(n_tasks=1, input_dim=DEFAULT_HIDDEN_DIM, hidden_dim=300, n_layers=1, dropout=0.0, activation='relu', criterion=None, task_weights=None, threshold=None, output_transform=None)[source]#

Bases: BinaryClassificationFFNBase

A _FFNPredictorBase is the base class for all Predictors that use an underlying SimpleFFN to map the learned fingerprint to the desired output.

Parameters:
n_targets = 2#
forward(Z)[source]#
Parameters:

Z (torch.Tensor)

Return type:

torch.Tensor

train_step(Z)[source]#
Parameters:

Z (torch.Tensor)

Return type:

torch.Tensor

class chemprop.nn.predictors.MulticlassClassificationFFN(n_classes, n_tasks=1, input_dim=DEFAULT_HIDDEN_DIM, hidden_dim=300, n_layers=1, dropout=0.0, activation='relu', criterion=None, task_weights=None, threshold=None, output_transform=None)[source]#

Bases: _FFNPredictorBase

A _FFNPredictorBase is the base class for all Predictors that use an underlying SimpleFFN to map the learned fingerprint to the desired output.

Parameters:
n_targets = 1#
forward(Z)[source]#
Parameters:

Z (torch.Tensor)

Return type:

torch.Tensor

train_step(Z)[source]#
Parameters:

Z (torch.Tensor)

Return type:

torch.Tensor

class chemprop.nn.predictors.MulticlassDirichletFFN(n_classes, n_tasks=1, input_dim=DEFAULT_HIDDEN_DIM, hidden_dim=300, n_layers=1, dropout=0.0, activation='relu', criterion=None, task_weights=None, threshold=None, output_transform=None)[source]#

Bases: MulticlassClassificationFFN

A _FFNPredictorBase is the base class for all Predictors that use an underlying SimpleFFN to map the learned fingerprint to the desired output.

Parameters:
forward(Z)[source]#
Parameters:

Z (torch.Tensor)

Return type:

torch.Tensor

train_step(Z)[source]#
Parameters:

Z (torch.Tensor)

Return type:

torch.Tensor

class chemprop.nn.predictors.SpectralFFN(*args, spectral_activation='softplus', **kwargs)[source]#

Bases: _FFNPredictorBase

A _FFNPredictorBase is the base class for all Predictors that use an underlying SimpleFFN to map the learned fingerprint to the desired output.

Parameters:

spectral_activation (str | None)

n_targets = 1#
train_step#
forward(Z)[source]#
Parameters:

Z (torch.Tensor)

Return type:

torch.Tensor