chemprop.nn.agg
#
Module Contents#
Classes#
An |
|
Average the graph-level representation: |
|
Sum the graph-level representation: |
|
Sum the graph-level representation and divide by a normalization constant: |
|
An |
Attributes#
- class chemprop.nn.agg.Aggregation(dim=0, *args, **kwargs)[source]#
Bases:
torch.nn.Module
,chemprop.nn.hparams.HasHParams
An
Aggregation
aggregates 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)
- abstract 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 d
containing the batched node-level representations ofb
graphsbatch (Tensor) – a tensor of shape
V
containing the index of the graph a given vertex corresponds to
- Returns:
a tensor of shape
b x d
containing the graph-level representations- Return type:
Tensor
- chemprop.nn.agg.AggregationRegistry#
- class chemprop.nn.agg.MeanAggregation(dim=0, *args, **kwargs)[source]#
Bases:
Aggregation
Average 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 d
containing the batched node-level representations ofb
graphsbatch (Tensor) – a tensor of shape
V
containing the index of the graph a given vertex corresponds to
- Returns:
a tensor of shape
b x d
containing the graph-level representations- Return type:
Tensor
- class chemprop.nn.agg.SumAggregation(dim=0, *args, **kwargs)[source]#
Bases:
Aggregation
Sum 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 d
containing the batched node-level representations ofb
graphsbatch (Tensor) – a tensor of shape
V
containing the index of the graph a given vertex corresponds to
- Returns:
a tensor of shape
b x d
containing the graph-level representations- Return type:
Tensor
- class chemprop.nn.agg.NormAggregation(dim=0, *args, norm=100.0, **kwargs)[source]#
Bases:
SumAggregation
Sum 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)
- 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 d
containing the batched node-level representations ofb
graphsbatch (Tensor) – a tensor of shape
V
containing the index of the graph a given vertex corresponds to
- Returns:
a tensor of shape
b x d
containing the graph-level representations- Return type:
Tensor
- class chemprop.nn.agg.AttentiveAggregation(dim=0, *args, output_size, **kwargs)[source]#
Bases:
Aggregation
An
Aggregation
aggregates 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)
- 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 d
containing the batched node-level representations ofb
graphsbatch (Tensor) – a tensor of shape
V
containing the index of the graph a given vertex corresponds to
- Returns:
a tensor of shape
b x d
containing the graph-level representations- Return type:
Tensor