4 min total

Graph Neural Networks

Graph Neural Networks

Graph Neural Networks

…

  1. node regression and edge regression: predicting a continuous value for each node/edge in a graph.

    each sensor on a road tracks things like speed, volumme and model predicts future values at each sensor. can be used to predict house pricings at locations on a grid.

    for edge regression, we can predict values for road segments themselves, travel time, segment speed etc.
  2. graph classification and regression: predicting a continous values for whole graph. molecules can be represented as graphs. molecular property prediction = graph classification/regression problem. graph classification would be to predict categorical properties of a graph (toxic/non-toxic). graph regression would be to predict continuous properties of a graph(boiling point, solubility score)

Encoder-Decoder models

Attributed graphs: each graph has a node, edges. Each graph is represented by a weighted symmetric adjacency matrix. Aij is a non-zero if there is an edge between node i and j. each node i has an attribute vector xi

how to obtain embeddings (Pre-NN Era)?

we cant take a node level vector as the embedding, but they do not capture any structural information on how nodes are connected.

graph tasks require knowing “what is happening in the neighborhood”, graph level tasks need neighborhood aggregation.

  1. use rows of the adjacency matrix as embeddings. but they are poor features becuase they do not provide any structural information beyond each nodes 1-hop neighborhood.
  2. use graph metrics (centrality, clustering coefficient) to define embeddings. but they are hand-crafted features, and not a part of algorithms training process.


researchers use encoder-decoder approaches to generate embeddings

  1. encoder: learns to map nodes to embeddings
  2. decoder: uses these embeddings to reconstruct graph structure, predict node/edge/graph labels.


shallow embeddings methods: compute node embeddings for nodes seen during training(no generalization) these shallow embeddings are not related to NNs, they date back to pre NN eraNN

  1. laplacian eignemaps: construct a adjacency matrix that captures similaity between nodes if they are connnected. high w = less similar, low w = more similar. if wij is large, penalize embeddings being far apart.
  2. matrix factorization methods: uses a similarity matrix, uses random walks to compute co occurrence probabilities.

shallow embeddings downsides:

  1. ignore node attributes, primarily rely on graph structure.
  2. transductive only: can only embed nodes seen during training, cannot handle unseen nodes
  3. parameters grow with nodes, memory issues for large graphs
  4. No parameter sharing, cannot generalize embeddings to other graphs


after computing these shallow embeddings, we can use them as inputs to our traditional ML models.


since the node was not part of the training in shallow embeddings case, it wasnt a part of the original adjacency matrix or random walks, it doesnt has a precomputed row in the embedding matrix, therefore there is no way to compute its embedding without retraining on the expanded graph.

GNNs

Why GNNs

  1. jointly use node attributes + edge structure
  2. can handle seen/unseen graphs/nodes
  3. parameter count doesnt sccales with number od nodes
  4. works well for directed + undirected graphs


Encoder layers

GNN encoder can have three classes of layers:

  1. input node features
  2. pre-processing layers: FNNs that input node features, projects raw input features into new feature space.
  3. message-passing layers: step 2 ke representation mein neighboring edges ko aggregate kardiya. stacking K layers will now contain information from its K-hop neighborhood
  4. post-processing layers: step 3 ke representation ki projection, does dimensionality reduction
  5. output

GNN Types

  1. Convolutional GNNs: GraphSAGE (Graph Sample and Aggregate) is one of the first inducive GNN, meaning we can generate embeddings for unseen nodes which allows for scalability.
  2. Message passing GNN: can model complex relationships, costs memory and harder to scale
  3. Attentional GNNs: learnable attention mechanism, slightly outperforms convolutional GNNs, but can be less scalable that convolutional GNNs

Aggregation functions

  1. vector sum
  2. concatenation
  3. laplacian eigenvectors for aggregation


GNN decoder and loss functions

GNN encoder produces node embeddings and decoder maps those embeddings to task specific outputs.

softmax function can be used to convert a probability distribution over K classes


different tasks at the end of decoder:

  1. Node classification: predict class label for each node.

ground truth yi(c) = 1 if node i is in class c else 0

decoder = softmax(z)

loss: categorical cross entropy: -y^t log(y)

  1. Link prediction task: predict whether edge exists between node i and node j

sigmoid predicts the probability of edge existence

decoder = sigmoid(z)

loss: binary cross entropy: ylog(y) + (1-y) log(1-y)

  1. graph classification: combines all node embeddings into one feature vector using sum mean or max pooling.

decoder: softmax(agg all z)

loss: -y^t log(y)

  1. community detection: cluster nodes into k communities by maximising modularity function Q. a modularity function outputs a score whicch tells how modular the nodes are, helps finding relations between nodes.

the model input a graph data structure, the model outputs a assignment matrix
assignment matrix (number of nodes x number of communities). each row represents a node and a distribution over the number of communities.

  1. Node regression: predict continuous values for each ndoe.

decoder: activation function(wz + b)

loss: mean squared error (y-yhat)^2


Learning paradigms

  1. inductive learning: test data is not available during training. train one graph on completely unseen graphs and test on new unseen graph
  2. transducive learning: all nodes are present during training (test+train). during training you use whole graph without knowing the test labels.