What are Graph Neural Networks, and how do they work?

Prashant Last Updated : 25 Jun, 2024
7 min read

Introduction

Neural Networks have gained immense popularity recently due to their usefulness and ease in Pattern Recognition and Data Mining. Deep Learning techniques like CNN, RNN, and autoencoders have significantly advanced object identification and voice recognition. These methods excel at analyzing images, text, and videos based on Euclidean data sets. However, for applications involving non-Euclidean data represented in graphs with complex item interactions, graphical neural network (GNN) are crucial. This article will cover the concepts and principles of Graphs and GNNs, along with recent applications of Graph Neural Networks.

Learning Objectives:

  • Understand the concept of Graph Neural Networks and their applications
  • Differentiate between types of Graph Neural Networks
  • Recognize the advantages of GNNs over CNNs for non-Euclidean data
  • Identify the main functions and real time applications of GNNs

This article was published as a part of the Data Science Blogathon.

What is a Graph?

As implied by the term – Graph Neural Networks – the most essential component of GNN is a graph.

Similarly, in computer science, a graph is a data structure characterized by two main components: vertices (V) and edges (E). Vertices represent the entities within the graph, and edges denote the relationships or connections between these entities. While vertices and nodes are often used interchangeably, they refer to distinct concepts. Directed graphs feature edges with arrows indicating the direction of relationships between vertices, while undirected graphs lack such directional distinctions.

Graph Neural Networks
Source: researchgate

A graph can represent diverse entities such as social media networks, city networks, and molecules. Take for instance, the following example of a city network where cities are nodes and the highways connecting them are edges.

We can utilize graph networks to address a range of issues concerning these cities, such as identifying well-connected cities or calculating the shortest distance between two cities.

What are Graph Neural Networks (GNN)?

Due to their extraordinarily powerful expressive capabilities, graphs are getting significant interest in the field of Machine Learning. Each node is paired with an embedding. This embedding establishes the node’s location in the data space. Graph Neural Networks are topologies of neural networks that operate on graphs.

A GNN architecture’s primary goal is to learn an embedding that contains information about its neighborhood. We may use this embedding to tackle a variety of issues, including node labeling, node and edge prediction, and so on.

Similarly, Graph Neural Networks are a specialized category within Deep Learning methodologies designed specifically for making inferences on data structured as graphs. They excel in tasks involving predictions at the levels of nodes, edges, and entire graphs.

Why not CNN?

The primary benefit of GNN is its capability to perform tasks that Convolutional Neural Networks (CNN) cannot. In contrast, CNN excels in tasks such as object identification, image categorization, and recognition, achieved through hidden convolutional layers and pooling layers.

CNN is computationally challenging to perform on graph data because the topology is very arbitrary and complicated, implying that there is no spatial locality. Additionally, there is an unfixed node ordering, which complicates the use of CNN.

Types of Graph Neural Networks

Similarly, as implied by its name, a GNN directly applies neural network principles to graphs, offering a convenient approach for conducting edge, node, and graph-level prediction tasks. This method leverages the inherent structure of graphs to achieve accurate and efficient predictions across various domains. Graph Neural Networks are classified into three types:

Fundamentally, GNNs intuitively define nodes based on their neighbors and connections. For instance, removing all neighbors from a node results in the loss of all its information. Thus, the idea of a node’s neighbors and the connections between them describe a node.

With this in mind, let us assign a state (x) to each node to describe its notion. We may utilize the node state (x) to generate an output (o), which represents the concept’s choice. The node’s ultimate state (x_n) is referred to as the “node embedding.” The primary purpose of all Graph Neural Networks is to discover the “node embedding” of each node by examining its neighboring nodes’ information.

Let’s begin with the most powerful GNN variant, the Recurrent graphical neural network, or RecGNN.

Recurrent Graph Neural Network

RecGNN is based on the Banach Fixed-Point Theorem, which asserts that: Let (X,d) be a full metric space and (T:X→X) be a contraction mapping. Then T has a unique fixed point (x∗), and for each x∈X, the sequence T n(x) for n→∞ converges to (x∗). This suggests that if I apply the mapping T to x for k times, x^k should be close to x^(k-1).

Graph Neural Network

Architecture of RGNN-

Graph Neural Networks
Source: ResearchGate

Spatial Convolutional Network

Spatial Convolutional Networks operate similarly to CNNs. In CNNs, convolution aggregates neighboring pixels using a filter with learnable weights, a widely recognized technique. Similarly, Spatial Convolutional Networks aggregate properties of neighboring nodes toward the center node, adhering to the same principle.

Graph NNs
Source: ResearchGate

Spectral Convolutional Network

Like other graphical neural network, this GNN uses a strong mathematical basis in Graph Signal Processing. It uses Chebyshev polynomial approximation to simplify and process graph-structured data efficiently.

What Functions Can A GNN Perform?

The challenges that a GNN can solve are divided into three categories:

Node Classification

Predicting the node embedding for each node in a network entails this task. In such scenarios, where only a portion of the graph is labeled, a semi-supervised graph emerges. Examples include YouTube videos, Facebook friend recommendations, and various other applications.

The main goal is to analyze the relationship between entities in a graph and predict their connectivity. For instance, consider a recommender system that analyzes user reviews of various items. Consequently, the objective is to accurately predict user preferences and optimize the system to recommend products closely aligned with user interests.

Graph Classification

It entails sorting the entire graph into a variety of groups. Similar to an image classification problem, the goal here is to identify graphs. For instance, Graph Classification involves categorizing a chemical structure into specific categories in chemistry.

GNN Applications in Real-Time

Many real time GNN applications have emerged since they were first introduced in 2018. A few of the most notable are outlined below.

Natural Language Processing

GNNs help with many NLP tasks like sentiment analysis, text classification, and labeling sequences. They also simplify NLP tasks and enable Social Network Analysis by analysing similar posts and suggesting relevant content.

Computer Vision

Computer Vision is a large discipline that has seen fast growth in recent years due to the use of Deep Learning in areas such as image classification and object detection. Convolutional Neural Networks are the most often used application. Recently, GNNs have been employed in this sector as well. Though GNN applications in Computer Vision are in their infancy, they demonstrate enormous potential in the next years.

Science

GNNs predict pharmacological adverse effects and categorize diseases, while also studying chemical and molecular graph structures.

Other Domains

In addition to the functions described above, GNN has a wide variety of functions. Recommender systems and social network research are only two areas where GNN has been tried out.

Application
Deep Learning
Description
Text classificationGraph convolutional network/ graph attention networkGNNs in NLP excel in Text Classification by deriving document labels from document or word relationships. GCN and GAT models use graph convolution to capture non-consecutive semantics efficiently.

Neural machine translation

Graph convolutional network/ gated graph neural networkIn sequence-to-sequence tasks such as NMT, GNNs integrate semantic information. Syntactic GCNs improve syntax-aware NMT, while GGNNs embed edge labels as nodes in syntactic dependency graphs.
Relation extractionGraph LSTM/ graph convolutional networkTraditionally, Relation Extraction identifies semantic relationships between text entities, now integrating entity recognition for enhanced performance and recognizing their interconnected nature.
Image classificationGraph convolutional network/ gated graph neural networkImage classification relies on large labeled datasets for training. Improving zero-shot and few-shot learning is critical, with GNNs showing promise in leveraging knowledge graphs for ZSL tasks.
Object detection

 

Interaction detection

Region classification

Semantic segmentation

Graph attention network

 

Graph neural network

Graph CNN

Graph LSTM/ gated graph neural network/ graph CNN/ graph neural network

GNNs are essential in computer vision for tasks such as object detection, interaction analysis, and region classification, extracting ROI features and reasoning about graph connections.
PhysicsGraph neural network/ graph networksUnderstanding human intelligence involves modeling physical systems. GNNs model objects as nodes and relationships as edges, enabling effective reasoning and prediction in complex systems like collision dynamics.
Molecular fingerprintsGraph convolutional networkMolecular fingerprints are vector representations enabling machine learning to predict molecule properties. GNNs replace traditional methods with customizable, task-specific, differentiable fingerprints.
Graph generationGraph convolutional network/ graph neural network/ LSTM /RNN/ relational-GCNGenerative models for real-world graphs, like simulating social interactions or generating knowledge graphs, are vital. GNN-based models excel by learning and matching node embeddings, surpassing traditional relaxation-based methods.

Conclusion

Since its introduction a few years ago, GNNs have proven effective in solving problems represented as graphs. Due to their adaptability, huge capability, and ease of visualization, they offer an understandable solution for handling unstructured data in various real world setting. Consequently, GNNs provide a straight forward approach to addressing complex issues through their versatile application.

Key Takeaways:

  • GNNs are designed to process graph structured data, making them ideal for complex relational tasks
  • There are three main types of GNNs: Recurrent, Spatial Convolutional, and Spectral Convolutional Networks
  • GNNs can perform node classification, link prediction, and graph classification tasks
  • GNNs have diverse applications in NLP, computer vision, scientific research, and social network analysis

Frequently Asked Questions:

Q1. What is a graph neural network?

A. A graph neural network (GNN) actively infers on data structured as graphs. It captures relationships between nodes through their edges, thereby improving the networks ability to understand complex structures.

Q2. What is the difference between graph neural networks and neural networks?

A. In this process graph structured data, capturing relationships and interactions between nodes, whereas traditional neural networks handle structured data like images or sequences without explicitly modeling interconnections.

Q3. Is ChatGPT a graph neural network?

A. ChatGPT differs from graph neural networks; instead, it operates as a transformer-based language model tailored for natural language processing tasks, distinct from applications involving graph-structured data.tasks, not for graph-structured data.

Q4. Are graph neural networks still relevant?

A. Yes, graph neural networks remain relevant due to their effectiveness in applications involving the relational data, such as social networks, recommendation systems, and biological networks.

The media shown in this article is not owned by Analytics Vidhya and are used at the Author’s discretion.

Hello, my name is Prashant, and I'm currently pursuing my Bachelor of Technology (B.Tech) degree. I'm in my 3rd year of study, specializing in machine learning, and attending VIT University.

In addition to my academic pursuits, I enjoy traveling, blogging, and sports. I'm also a member of the sports club. I'm constantly looking for opportunities to learn and grow both inside and outside the classroom, and I'm excited about the possibilities that my B.Tech degree can offer me in terms of future career prospects.

Thank you for taking the time to get to know me, and I look forward to engaging with you further!

Responses From Readers

Clear

Congratulations, You Did It!
Well Done on Completing Your Learning Journey. Stay curious and keep exploring!

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details