chemprop.nn.ffn#
Classes#
A |
|
An |
|
A |
Module Contents#
- class chemprop.nn.ffn.FFN(*args, **kwargs)[source]#
Bases:
torch.nn.ModuleA
FFNis a differentiable function \(f_\theta : \mathbb R^i \mapsto \mathbb R^o\)- Parameters:
args (Any)
kwargs (Any)
- input_dim: int#
- output_dim: int#
- class chemprop.nn.ffn.MLP(*args: torch.nn.modules.module.Module)[source]#
- class chemprop.nn.ffn.MLP(arg)
Bases:
torch.nn.Sequential,FFNAn
MLPis an FFN that implements the following function:\[\begin{split}\mathbf h_0 &= \mathbf W_0 \mathbf x \,+ \mathbf b_{0} \\ \mathbf h_l &= \mathbf W_l \left( \mathtt{dropout} \left( \sigma ( \,\mathbf h_{l-1}\, ) \right) \right) + \mathbf b_l\\\end{split}\]where \(\mathbf x\) is the input tensor, \(\mathbf W_l\) and \(\mathbf b_l\) are the learned weight matrix and bias, respectively, of the \(l\)-th layer, \(\mathbf h_l\) is the hidden representation after layer \(l\), and \(\sigma\) is the activation function.
- classmethod build(input_dim, output_dim, hidden_dim=300, n_layers=1, dropout=0.0, activation='relu')[source]#
- Parameters:
input_dim (int)
output_dim (int)
hidden_dim (int | Sequence[int])
n_layers (int)
dropout (float)
activation (str | torch.nn.Module)
- property input_dim: int#
- Return type:
int
- property output_dim: int#
- Return type:
int
- class chemprop.nn.ffn.ConstrainerFFN(n_constraints=1, fp_dim=DEFAULT_HIDDEN_DIM, hidden_dim=300, n_layers=1, dropout=0.0, activation='relu')[source]#
Bases:
torch.nn.Module,chemprop.nn.hparams.HasHParams,lightning.pytorch.core.mixins.HyperparametersMixinA
ConstrainerFFNadjusts atom or bond property predictions to satisfy molecular constraints by using anMLPto map learned atom or bond embeddings to weights that determine how much of the total adjustment needed is added to each atom or bond prediction.- Parameters:
n_constraints (int)
fp_dim (int)
hidden_dim (int | Sequence[int])
n_layers (int)
dropout (float)
activation (str)
- ffn#
- forward(fp, preds, batch, constraints)[source]#
Performs a weighted adjustment to the predictions to satisfy the constraints, with the weights being determined from the learned atom or bond fingerprints via an
MLP.- Parameters:
fp (Tensor) – a tensor of shape
b x hcontaining the atom or bond-level fingerprints, wherebis the number of atoms or bonds andhis the length of each fingerprint.preds (Tensor) – a tensor of shape
b x tcontaining the atom or bond-level predictions, wheretis the number of predictions per atom or bond.batch (Tensor) – a tensor of shape
bcontaining indices of which molecule each atom or bond belongs toconstraints (Tensor) – a tensor of shape
m x tcontaining the values to which the atom or bond-level predictions should sum to for each molecule, wheremis the number of molecules in the batch.
- Returns:
a tensor of shape
b x tcontaining the atom or bond-level predictions adjusted to satisfy the molecule-level constraints- Return type:
Tensor