sgmatch.modules

Attention

class sgmatch.modules.attention.GlobalContextAttention(input_dim: int, activation: str = 'tanh', activation_slope: Optional[float] = None)[source]

Attention Mechanism layer for the attention operator from the “SimGNN: A Neural Network Approach to Fast Graph Similarity Computation” paper

TODO: Include latex formula for attention computation and aggregation update

Parameters:
  • input_dim – Input Dimension of the Node Embeddings

  • activation – The Activation Function to be used for the Attention Layer

  • activation_slope – Slope of the -ve part if the activation is Leaky ReLU

class sgmatch.modules.attention.CrossGraphAttention(similarity_metric: str = 'euclidean')[source]

Attention mechanism layer for the cross-graph attention operator from the “Graph Matching Networks for Learning the Similarity of Graph Structured Objects” paper

TODO: Include latex formula for attention computation and aggregation update

Parameters:

similarity_metric – Similarity metric to be used to compute attention scoring

sgmatch.modules.scoring.similarity(h_i, h_j, mode: str = 'cosine')[source]

Encoding

class sgmatch.modules.encoder.MLPEncoder(node_feature_dim: int, node_hidden_sizes: List[int], edge_feature_dim: Optional[int] = None, edge_hidden_sizes: Optional[List[int]] = None)[source]

MLP node/edge feature encoding scheme following the “Graph Matching Networks for Learning the Similarity of Graph Structured Objects” paper.

NOTE: This is a generic MLP Encoder for graph encoding rather than something explicitly novel from the paper; it has been referenced for clarity. Both node and edge features have separately initialised MLP models.

Parameters:
  • node_feature_dim (int) – Input dimension of node feature embedding vectors

  • node_hidden_sizes ([int]) – Number of hidden neurons in each linear layer for transforming the node features.

  • edge_feature_dim ([int], Optional) – Input dimension of node feature embedding vectors(default: None)

  • edge_hidden_sizes ([int], Optional) – Number of hidden neurons in each linear layer for transforming the edge features. (default: None)

class sgmatch.modules.encoder.OrderEmbedder(margin, use_intersection: bool = False)[source]

Propagation

class sgmatch.modules.propagation.GraphProp(node_feature_dim: int, node_hidden_sizes: List[int], message_hidden_sizes: List[int], edge_feature_dim: Optional[int] = None, message_net_init_scale: float = 0.1, node_update_type: str = 'residual', use_reverse_direction: bool = False, reverse_dir_param_different: bool = True, layer_norm: bool = False, prop_type: str = 'embedding')[source]

Implementation of the message-propagation module from the “Graph Matching Networks for Learning the Similarity of Graph Structured Objects” <https://arxiv.org/pdf/1904.12787.pdf>_ paper.

\[\]

NOTE: This module only computes one propagation step at a time and needs to be called T times for T propagation steps (step-wise calls need to be defined by user in model training scripts).

Parameters:
  • node_feature_dim (int) – Input dimension of node feature embedding vectors

  • node_hidden_sizes ([int]) – Number of hidden neurons in each linear layer of node update MLP f_node. node_feature_dim is appended as the size of the final linear layer to maintain node embedding dimensionality

  • message_hidden_sizes ([int]) – Number of hidden neurons in each linear layer of message computation MLP f_node. Note that the message vector dimensionality (message_hidden_sizes[-1]) may not be equal to node_feature_dim.

  • edge_feature_dim ([int], Optional) – Input dimension of node feature embedding vectors. (default: None)

  • message_net_init_scale (float) – Initialisation scale for the message net output vectors. (default: 0.1)

  • node_update_type (str) – Type of update applied to node feature vectors ("GRU" or "MLP" or "residual) (default: "residual")

  • use_reverse_direction (bool) – Specifies whether or not to use the reverse message aggregation for propagation step. (default: False)

  • reverse_dir_param_different (bool) – Specifies whether or not message computation model parameters should be shared by forward and reverse messages. (default: True)

  • layer_norm (bool) – (default: False)

  • prop_type (str) – Propagation computation type ("embedding" or "matching") (default: "embedding")

Scoring

class sgmatch.modules.scoring.NeuralTensorNetwork(input_dim: int, slices: int = 16, activation: str = 'tanh')[source]

Neural Tensor Network layer from the “SimGNN: A Neural Network Approach to Fast Graph Similarity Computation” paper

TODO: Include latex formula for NTN interaction score computation

Parameters:
  • input_dim – Input dimension of the graph-level embeddings slices. That is, number of slices (K) the weight tensor possesses. Often interpreted as the number of entity-pair (in this use case - pairwise node) relations the data might possess.

  • activation – Non-linearity applied on the computed output of the layer