chemprop.nn.agg#
Attributes#
Classes#
An |
|
Average the graph-level representation: |
|
Sum the graph-level representation: |
|
Sum the graph-level representation and divide by a normalization constant: |
|
An |
Module Contents#
- class chemprop.nn.agg.Aggregation(dim=0, *args, **kwargs)[source]#
Bases:
torch.nn.Module,chemprop.nn.hparams.HasHParamsAn
Aggregationaggregates the node-level representations of a batch of graphs into a batch of graph-level representationsNote
this class is abstract and cannot be instantiated.
See also
MeanAggregation,SumAggregation,NormAggregation- Parameters:
dim (int)
- dim = 0#
- hparams#
- abstractmethod forward(H, batch)[source]#
Aggregate the graph-level representations of a batch of graphs into their respective global representations
NOTE: it is possible for a graph to have 0 nodes. In this case, the representation will be a zero vector of length d in the final output.
- Parameters:
H (Tensor) – a tensor of shape
V x dcontaining the batched node-level representations ofbgraphsbatch (Tensor) – a tensor of shape
Vcontaining the index of the graph a given vertex corresponds to
- Returns:
a tensor of shape
b x dcontaining the graph-level representations- Return type:
Tensor
- chemprop.nn.agg.AggregationRegistry#
- class chemprop.nn.agg.MeanAggregation(dim=0, *args, **kwargs)[source]#
Bases:
AggregationAverage the graph-level representation:
\[\mathbf h = \frac{1}{|V|} \sum_{v \in V} \mathbf h_v\]- Parameters:
dim (int)
- forward(H, batch)[source]#
Aggregate the graph-level representations of a batch of graphs into their respective global representations
NOTE: it is possible for a graph to have 0 nodes. In this case, the representation will be a zero vector of length d in the final output.
- Parameters:
H (Tensor) – a tensor of shape
V x dcontaining the batched node-level representations ofbgraphsbatch (Tensor) – a tensor of shape
Vcontaining the index of the graph a given vertex corresponds to
- Returns:
a tensor of shape
b x dcontaining the graph-level representations- Return type:
Tensor
- class chemprop.nn.agg.SumAggregation(dim=0, *args, **kwargs)[source]#
Bases:
AggregationSum the graph-level representation:
\[\mathbf h = \sum_{v \in V} \mathbf h_v\]- Parameters:
dim (int)
- forward(H, batch)[source]#
Aggregate the graph-level representations of a batch of graphs into their respective global representations
NOTE: it is possible for a graph to have 0 nodes. In this case, the representation will be a zero vector of length d in the final output.
- Parameters:
H (Tensor) – a tensor of shape
V x dcontaining the batched node-level representations ofbgraphsbatch (Tensor) – a tensor of shape
Vcontaining the index of the graph a given vertex corresponds to
- Returns:
a tensor of shape
b x dcontaining the graph-level representations- Return type:
Tensor
- class chemprop.nn.agg.NormAggregation(dim=0, *args, norm=100.0, **kwargs)[source]#
Bases:
SumAggregationSum the graph-level representation and divide by a normalization constant:
\[\mathbf h = \frac{1}{c} \sum_{v \in V} \mathbf h_v\]- Parameters:
dim (int)
norm (float)
- norm = 100.0#
- forward(H, batch)[source]#
Aggregate the graph-level representations of a batch of graphs into their respective global representations
NOTE: it is possible for a graph to have 0 nodes. In this case, the representation will be a zero vector of length d in the final output.
- Parameters:
H (Tensor) – a tensor of shape
V x dcontaining the batched node-level representations ofbgraphsbatch (Tensor) – a tensor of shape
Vcontaining the index of the graph a given vertex corresponds to
- Returns:
a tensor of shape
b x dcontaining the graph-level representations- Return type:
Tensor
- class chemprop.nn.agg.AttentiveAggregation(dim=0, *args, output_size, **kwargs)[source]#
Bases:
AggregationAn
Aggregationaggregates the node-level representations of a batch of graphs into a batch of graph-level representationsNote
this class is abstract and cannot be instantiated.
See also
MeanAggregation,SumAggregation,NormAggregation- Parameters:
dim (int)
output_size (int)
- W#
- forward(H, batch)[source]#
Aggregate the graph-level representations of a batch of graphs into their respective global representations
NOTE: it is possible for a graph to have 0 nodes. In this case, the representation will be a zero vector of length d in the final output.
- Parameters:
H (Tensor) – a tensor of shape
V x dcontaining the batched node-level representations ofbgraphsbatch (Tensor) – a tensor of shape
Vcontaining the index of the graph a given vertex corresponds to
- Returns:
a tensor of shape
b x dcontaining the graph-level representations- Return type:
Tensor