What are Graph Neural Networks (GNN) & How Do They Work?: A Comprehensive Guide

Read Time:
minutes

What is graph?

Imagine you have a bunch of data that can be represented as a network where each data or entity have a relationship with another data or entity and this relationship can be of multiple types (one-to-one, one-to-many, many-to-many etc..). Some examples of this type of data are transportation data or social media network where every entity or user have a relation with other entity or users and this is where graphs becomes easy to visualize this type of data.

There are 2 types of graphs:

  • Directed - In a directed graph, edges have a direction indicating the flow or relationship between nodes (e.g., following on social media).
  • Undirected - In an undirected graph, edges have no direction and represent symmetric relationships (e.g., connection on linkedin).

What is GNN?

Let’s say you want to analyze this data or make predictions for any node then this is where graph neural networks(GNN) come into play. GNNs are the class of deep learning methods which are used to analyze graph and to predict node-level, edge-level or graph-level tasks.

How GNN is different from Traditional Neural Networks?

Traditional neural networks are used to process grid structured data like images or sequences with fixed size and regular structure but in some real world datasets like social networks, biological networks or recommendation systems, GNNs are used to process this kind of data by incorporating this structure in neural network architecture, allowing them to learn and reason about relationships between entities or nodes in graph.

Image credits: ResearchGate

How does GNNs work?

In traditional neural network, each layer consists of neurons that are connected to neurons in the previous and next layers. These connections are represented by weights, which are learned during the training process. The output of each neuron is determined by applying an activation function to the weighted sum of its inputs but in case of graphs, we don’t have a structured data so we can’t apply this method directly here but instead we can take weighted sum of neighbors of a node and apply activation function on it to generate an output so that each node have information about every other node and this process is done using message passing.

What is message passing?

The core operation of GNN is message passing, where information is passed through neighboring nodes in graph. At each layer, each node gets information from its neighbors and updates its own information and this process is called message passing.

The message passing process typically involves the following steps:

Step 1: Each node aggregates information from its neighbors by combining their embeddings using an aggregation function (e.g., sum, mean, max, or a learned function).

Step 2: The aggregated information is then passed through a neural network layer to generate a new representation (embedding) for the node. More and more information gets passed in each round of message passing.

Step 3: All these embeddings gets stored in embedding space and the positions of these embeddings plays a big role here. If 2 nodes are close to each other then that means they are similar.

But how we will decide the positions of these nodes? 🤔

To put an element in embedding space, we need an measurable object to tell the neural network on which factors we need to find similarity between nodes. From that object and distance between current representation of nodes, we will find a loss function and check how accurate it is. In this process, we first forward propagate through the message passing layers to get the final state of each node and then we find the loss. After finding the loss, we then backpropagate it and then network will optimize it and give us new representation.

We will repeat this process until the loss is minimum and we have reached the final state or representation of embeddings.

Types of tasks which GNN can solve

GNNs are becoming very useful because of their ability to analyze complex relationships in graph-structured data. From social networks to biological networks or recommendation systems, GNNs have found applications across various applications and domains. Their capability to learn representations from graph data enables a wide range of tasks, including node classification, link prediction, graph classification, and node clustering.

Let’s see these tasks one by one.

Node classification

In node classification tasks, GNNs are used to predict the class for a node based on the graph architecture or attributes of a graph. GNNs achieve this by taking information from the local neighborhood of each node to make predictions. For example, finding fraudulent user in bank transaction network.

Here is the architecture for binary classification for fraudulent and genuine bank users

Link prediction

Link prediction is predicting the connection or relationship between 2 nodes in a graph. GNNs are well suited for this task because it will be easy for it to find the missing or future edges from the data which they have acquired from all the nodes in the graph during message passing. For example, in social networks GNNs can predict the friendship or match between 2 users based on similarities or interests.

Graph classification

Similar to node classification, you can also classify an entire graphs based on structure or attributes. GNNs can classify graphs in different categories or classes based on its structure or properties of its nodes. This is useful in categorizing social networks by their connection patterns.

Here is the graph classification for a social media platform based on user activity

Node clustering

Node clustering, also known as community detection or graph partitioning is a task in which some set of nodes or a part of graph is grouped together in a one single cluster based on their similarities and patterns. Nodes within the same cluster are more densely connected to each other than to nodes in other clusters. In social networks, node clustering can be useful to find communities of people with similar interests or behaviors.

Here is the node clustering example in a social media platform of users with different interests

Applications of GNN

Graph Neural Networks (GNNs) have a wide range of real-world applications across various domains due to their ability to model and analyze graph-structured data. here are some of the real world applications of GNN:

  • Social Network Analysis: GNNs can be used to analyze social networks, such as Facebook, Twitter, or LinkedIn, to identify communities, detect influential users, predict user behavior, and recommend connections or content.
  • Recommendation Systems: GNNs can enhance recommendation systems in e-commerce platforms, streaming services, and social media by modeling user-item interactions, capturing user preferences and item features, and generating personalized recommendations.
  • Drug Discovery: GNNs can accelerate the drug discovery process by predicting molecular properties, identifying potential drug candidates, and optimizing molecular structures.
  • Fraud Detection: GNNs can detect fraudulent activities in financial networks, social networks, and online platforms by analyzing transaction patterns, identifying anomalous behaviors, and predicting fraud risks.
  • Cybersecurity: GNNs can enhance cybersecurity by detecting and mitigating cyber threats, such as malware propagation, network intrusions, and phishing attacks, by analyzing network traffic, user behavior, and system logs.

Conclusion

GNNs have improved so much as powerful tools for modeling and analyzing graph-structured data, leveraging the inherent relationships and structures within graphs to address a wide range of real-world problems. In TNN (Traditional Neural Networks), you can only analyze structured data but GNNs allows us to analyze graph-structured data too.

As GNNs continue to evolve and advance, they hold great promise for shaping the future of machine learning and artificial intelligence, driving innovation, and solving complex problems in an increasingly interconnected world.

Need help with AI?

Are you looking for best AI Solutions for your model or have an idea to build any SaaS using AI then we at Ionio have done lot of work on LLMs and delivered multiple AI-Powered SaaS products. If you are interested then kindly book a call with us - https://calendly.com/rohansawant/intro-meeting-blog


Thanks for reading! 😄

Book an AI consultation

Looking to build AI solutions? Let's chat.

Schedule your consultation today - this not a sales call, feel free to come prepared with your technical queries.

You'll be meeting Rohan Sawant, the Founder.
 Company
Book a Call

Let us help you.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Behind the Blog 👀
Shivam Danawale
Writer

Shivam is an AI Researcher & Full Stack Engineer at Ionio.

Rohan Sawant
Editor

Rohan is the Founder & CEO of Ionio. I make everyone write all these nice articles... 🥵