compositional_graph_models/models.py
def forward(self, graph: dgl.DGLGraph) -> torch.Tensor:
        """
        Compute the logits of equality holding for each equation in the (batched) graph.

        NOTE: modifies the graph in place.

        Parameters
        ----------
        graph
            The graph (possibly batched) containing equalities to classify.

        Returns
        -------
        Tensor
            For each equality in the input graph, the logit of positive classification.
        """
        self._prepare_graph(graph)
        graph.ndata["features"] = self._embed_nodes(graph)

        for layer in self.layers:
            reduce_udf = self._reduce_layer(layer)
            graph.update_all(
                message_func=dgl.function.copy_src("features", "features"),
                reduce_func=reduce_udf,
            )

        pad_node_id = graph.num_nodes() - 1
        graph.remove_nodes(pad_node_id)
        left_subgraph, right_subgraph = self._left_right_subgraphs(graph)

        # TODO: try other readouts
        encoding_left = dgl.readout_nodes(left_subgraph, "features", op="mean")
        encoding_right = dgl.readout_nodes(right_subgraph, "features", op="mean")

        # TODO: try other metrics like cosine similarity
        logits = (encoding_left * encoding_right).sum(-1) + self.output_bias
        return logits

        Compute the logits of equality holding for each equation in the (batched) graph.

        NOTE: modifies the graph in place.

        Parameters
        ----------
        graph
            The graph (possibly batched) containing equalities to classify.

        Returns
        -------
        Tensor
            For each equality in the input graph, the logit of positive classification.
        
Compute the logits of equality holding for each equation in the (batched) graph.
NOTE: modifies the graph in place.

Parameters

graph
The graph (possibly batched) containing equalities to classify.

Returns

Tensor
For each equality in the input graph, the logit of positive classification.
Compute the logits of equality holding for each equation in the ( batched ) graph . NOTE : modifies the graph in place . Parameters graph The graph ( possibly batched ) containing equalities to classify . Returns Tensor For each equality in the input graph the logit of positive classification .
def forward(self, graph: dgl.DGLGraph) -> torch.Tensor:
        self._prepare_graph(graph)
        graph.ndata["features"] = self._embed_nodes(graph)
        for layer in self.layers:
            reduce_udf = self._reduce_layer(layer)
            graph.update_all(
                message_func=dgl.function.copy_src("features", "features"),
                reduce_func=reduce_udf,
            )
        pad_node_id = graph.num_nodes() - 1
        graph.remove_nodes(pad_node_id)
        left_subgraph, right_subgraph = self._left_right_subgraphs(graph)
        encoding_left = dgl.readout_nodes(left_subgraph, "features", op="mean")
        encoding_right = dgl.readout_nodes(right_subgraph, "features", op="mean")
        logits = (encoding_left * encoding_right).sum(-1) + self.output_bias
        return logits
def forward ( self , graph : dgl . DGLGraph ) -> torch . Tensor : self . _prepare_graph ( graph ) graph . ndata [ "features" ] = self . _embed_nodes ( graph ) for layer in self . layers : reduce_udf = self . _reduce_layer ( layer ) graph . update_all ( message_func = dgl . function . copy_src ( "features" , "features" ) , reduce_func = reduce_udf , ) pad_node_id = graph . num_nodes ( ) - 1 graph . remove_nodes ( pad_node_id ) left_subgraph , right_subgraph = self . _left_right_subgraphs ( graph ) encoding_left = dgl . readout_nodes ( left_subgraph , "features" , op = "mean" ) encoding_right = dgl . readout_nodes ( right_subgraph , "features" , op = "mean" ) logits = ( encoding_left * encoding_right ) . sum ( - 1 ) + self . output_bias return logits
Compute the logits of equality holding for each equation in the (batched) graph.
Compute the logits of equality holding for each equation in the ( batched ) graph .
"""
        Compute the logits of equality holding for each equation in the (batched) graph.

        NOTE: modifies the graph in place.

        Parameters
        ----------
        graph
            The graph (possibly batched) containing equalities to classify.

        Returns
        -------
        Tensor
            For each equality in the input graph, the logit of positive classification.
        """ # TODO: try other readouts # TODO: try other metrics like cosine similarity
self
graph
dgl.DGLGraph