Chapter 1: What Are Graph Neural Networks, and Why Do They Matter?
Imagine you’re scrolling through your favorite social media app, and the “People You May Know” suggestion pops up with a name you’ve never heard of—but as soon as you see the profile, you realize you both went to the same small high school, share 17 mutual friends, and have both posted photos of hiking in the Rocky Mountains last summer. That uncanny, hyper-relevant recommendation isn’t just luck. It’s the work of a graph neural network, or GNN, a type of artificial intelligence built specifically to understand the hidden connections between people, objects, and ideas that traditional machine learning tools completely miss.
To understand why GNNs are such a big deal, let’s first look at the data they’re built to handle. Every day, we generate billions of data points that are not just standalone numbers or text, but are explicitly connected to each other: your Facebook friends are connected to you, the atoms in a new drug molecule are connected by chemical bonds, the intersections in a city’s road network are connected by streets, and the concepts in a Wikipedia article are connected by hyperlinks. This type of data, where entities (called nodes) have explicit relationships (called edges) to other entities, is called graph-structured data. For decades, traditional machine learning models were terrible at working with this data, because they were designed to treat every data point as independent. If you wanted to predict whether a user would like a new movie, a traditional model would only look at that user’s past viewing history, ignoring the fact that 3 of their closest friends just watched and loved the same movie. GNNs fix this by explicitly modeling those connections, letting AI “see” the relationships that humans take for granted.
Let’s take a more concrete example from drug discovery. For years, pharmaceutical companies have struggled to find new treatments for diseases like Alzheimer’s, because the process of testing new molecular compounds is incredibly slow and expensive: it takes an average of 10 years and $2.6 billion to bring a new drug to market, with most candidates failing in clinical trials. The problem is that a molecule’s effectiveness is not just determined by the properties of its individual atoms, but by how those atoms are connected to each other—their spatial structure, their chemical bonds, their interaction with proteins in the human body. Traditional machine learning models treat each molecule as a flat list of atom properties, missing all that structural context. GNNs, by contrast, represent each atom as a node, each chemical bond as an edge, and pass messages between connected atoms to learn the full structural representation of the molecule. In 2023, Insilico Medicine, a biotechnology company, announced that a drug for idiopathic pulmonary fibrosis discovered using GNNs had entered Phase 2 clinical trials—cutting the usual drug discovery timeline by 4 years and reducing costs by 60%. That’s not a lab experiment: that’s a life-saving treatment reaching patients years faster than would have been possible with old methods.
Or take search engines. When you type “best laptop for college students” into Google, the search engine doesn’t just match keywords on web pages. It uses a knowledge graph—a massive graph where entities like “laptop,” “college student,” “battery life,” and “lightweight” are nodes, and relationships like “has feature,” “is suitable for,” and “is cheaper than” are edges. Traditional keyword-based search can’t understand that “long battery life” is a feature that matters more to college students than “high-end graphics card” for most use cases. GNNs process the entire knowledge graph to understand the context of your query, so it can return results that actually answer your question, not just pages that contain the words you typed. Google has reported that integrating GNNs into its search ranking algorithm improved user satisfaction scores by 12% in 2022, as users found relevant results faster.
These examples are not outliers. GNNs are now used in almost every industry to solve problems that were previously impossible for AI to tackle. To make the value of GNNs even clearer, let’s compare them directly to the traditional machine learning and deep learning models you may already be familiar with, like logistic regression, random forests, convolutional neural networks (CNNs), and recurrent neural networks (RNNs).
If you’ve ever studied basic machine learning, you know that most traditional models assume that every data point is independent of every other. This is called the “independent and identically distributed (IID)” assumption, and it works great for data like tabular customer data, where each row is a separate customer with no explicit connection to other rows. But for graph data, this assumption is completely wrong. Your behavior as a social media user is directly influenced by your friends’ behavior, the atoms in a molecule are directly connected to each other, and the traffic at one intersection is directly affected by the traffic at the intersection upstream. Traditional models throw away all that relational information, leading to much worse performance.
What about CNNs and RNNs, the workhorses of modern deep learning? CNNs are great for grid-structured data like images (which are 2D grids of pixels) or text (which can be treated as 1D sequences of words), because they use fixed-size convolution kernels that slide over the regular grid to extract local features. But graphs are irregular: a social media influencer might have 10 million friends, while a new user might only have 5. There’s no fixed grid structure, so CNNs’ fixed convolution kernels don’t work. RNNs, meanwhile, are designed for sequential data with a fixed order, like time series or sentences. But graphs have no inherent order: if you reorder the nodes in a social network graph, it’s still the exact same graph. RNNs can’t handle that lack of order.
GNNs solve both of these problems with a simple but powerful mechanism called message passing. Let’s use the potluck dinner analogy to make this concrete: imagine every node in a graph is a person at a potluck dinner. At the start of the dinner, each person only knows their own basic information: their name, their favorite food, their hobbies. That’s the initial feature representation of each node. Then, the first round of message passing begins: each person talks to all their friends (their immediate neighbors) at the dinner, and exchanges information. After that round, each person updates their own self-understanding based on what they learned from their friends. If you originally only knew that you like hiking, and you learn that 3 of your friends like camping, you might update your self-description to “I like hiking and I’m interested in camping gear.” Then a second round of message passing begins: now you share your updated self-description with your friends, and they share their updated descriptions with you. After a few rounds, every person at the dinner has a rich, context-aware understanding of themselves, based not just on their own traits, but on the traits of everyone they’re connected to, directly or indirectly.
That’s exactly how GNNs work. Each node starts with its own initial feature (like a user’s age, location, and past purchase history, or an atom’s atomic number and bond type). Then, for each “layer” of the GNN, every node aggregates the feature information from all its immediate neighbors, combines it with its own existing feature, and updates its own representation. After multiple layers, each node’s final representation captures not just its own traits, but the traits of all nodes that are within a certain number of hops away. For example, a 3-layer GNN’s representation of a user will capture information about the user’s friends, their friends’ friends, and their friends’ friends’ friends—capturing the entire local network context around the user.
We ca