<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Carlo H on Medium]]></title>
        <description><![CDATA[Stories by Carlo H on Medium]]></description>
        <link>https://medium.com/@carlo-harprecht?source=rss-52c87f77c5a1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wMGecwnLKbshmcVrU09lnA.png</url>
            <title>Stories by Carlo H on Medium</title>
            <link>https://medium.com/@carlo-harprecht?source=rss-52c87f77c5a1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 06:09:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@carlo-harprecht/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to boost your GNN]]></title>
            <link>https://medium.com/data-science/how-to-boost-your-gnn-356f70086991?source=rss-52c87f77c5a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/356f70086991</guid>
            <category><![CDATA[editors-pick]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[graph-neural-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Carlo H]]></dc:creator>
            <pubDate>Thu, 14 Apr 2022 17:27:47 GMT</pubDate>
            <atom:updated>2022-04-14T17:27:47.756Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>Tips and Tricks to improve your Graph Neural Network</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f9OcJeBadVnLXlG6" /><figcaption>Photo by <a href="https://unsplash.com/@pietrozj?utm_source=medium&amp;utm_medium=referral">Pietro Jeng</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The Graph Neural Network (GNN) is the new cool kid on the block. Its name sounds fancy, the math is advanced, and GNNs show state-of-the-art performance on a variety of tasks¹ ².</p><p>GNNs offer a way to use deep learning techniques on graph-structured data. And graph-structured data is everywhere: from chemistry (e.g., molecular graphs), to social media (e.g., social networks) and also financial investments (e.g., VC investment networks).</p><p>During my master’s thesis, I predicted future funding rounds of startups using GNNs on an investment network composed of investors, startups, and individuals. The baseline random forest models were already fairly strong (AUC = 0.69) when I implemented the GNN models (R-GCN¹ and HGT²).</p><p>I was excited to see how the advanced GNN would improve my results. To my surprise, the GNN models constantly lagged behind the baseline models’ performances. Increasing the number of layers and hidden dimensions did not help. So I started researching and found that I am not alone in my GNN relationship problems.</p><p>If this sounds familiar to you (it probably does, otherwise why would you bother reading this dry blog post), I might have some tips to boost the performance of your GNN model.</p><h3>What are GNNs again?</h3><p>Before we discuss how to improve GNNs, let&#39;s have a quick refresher on how they work. For a great and in-depth introduction to graph neural networks, check out the Youtube channel from <a href="https://www.youtube.com/channel/UCScjF2g0_ZNy0Yv3KbsbR7Q">DeepFindr</a>³ (or some literature⁴)</p><p>Let&#39;s assume we have a simple graph as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*d41ghszApj_zPIHYLZcMzg.png" /><figcaption>A graph including node features (image by the author, adapted from DeepFindr³)</figcaption></figure><p><strong>The Graph</strong> <br>A graph contains nodes (i, j, and k) and edges (e) connecting these nodes. In addition, the graph also includes node features for each node (X1,…) and possibly each edge (in black). The target node is colored in yellow, its 1-hop neighbors are blue and 2-hop neighbors are represented in green. A graph including different types of nodes is called a “heterogeneous” graph, as in our case.</p><p><strong>Message Passing</strong><br>The embedding of a node at step 0 is simply its feature vector (consisting of features X1, X2…). To obtain the new (l + 1) node embedding, h, for our target node, i, (in yellow), we extract all embeddings from its neighboring nodes, j, (in blue), its own representation, as well as potential edge features e (in black) and aggregate this information. This is shown in the formula below. However, keep in mind that most prominent GNN architectures currently do not make use of edge features⁵. Afterward, we can use these new node embeddings for various tasks, such as node classification, link prediction, or graph classification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j-6fFXpMa9s-xWNVKNPALg.png" /><figcaption>General GNN Layer Formula²</figcaption></figure><h3>Problems with GNNs</h3><p><strong>In Practice<br></strong>Many recent studies across various fields found GNN models not delivering the anticipated performance⁵ ⁶ ⁷. When researchers compared them to much simpler tree-based baseline models, the GNNs could not outperform or even match the baselines.</p><p><strong>In Theory</strong><br>Other researchers provided theoretical explanations of the sometimes poor performance of GNNs⁸. According to their experiments, GNNs only perform feature de-noising and are unable to learn non-linear manifolds. Therefore, they advocate for viewing GNNs as one mechanism (e.g. for feature denoising) of a graph learning model and not a full end-to-end model by themselves.</p><h3>Fixes</h3><p>To fix these shortcomings and boost your GNN, I found 3 main tricks/ideas:</p><ol><li><em>Utilize Edge Features in your GNN</em></li><li><em>Self-supervised pre-training for GNNs</em></li><li><em>Separate Pretext &amp; Downstream tasks</em></li></ol><p>Let&#39;s have a look at them in detail.</p><h3>Utilize Edge Features</h3><p>The idea of utilizing edge features is very much dependent on the kind of data you are working with. In case your data contains(multidimensional) edge features, leveraging edge features can make a difference in your model&#39;s performance.</p><p>However, few established GNN model architectures support multidimensional edge features⁵. An easy workaround that I used and that worked quite well is creating artificial nodes:</p><p><strong>Artificial Nodes<br></strong>By using artificial nodes, you can keep using the same model you did before. The only thing we will change is the graph itself, which will become a bit more complex. Instead of edges holding edge features, each edge will become a node of itself (light blue) connected to the original, dark blue nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GDy8Ube34nWGuVYL5TpzQA.png" /><figcaption>Meta graph of an investment network before and after adding artificial nodes (image by the author)</figcaption></figure><p>This way, you can leverage edge features indirectly by passing them to the model as node features from the artificial nodes. This can improve the model&#39;s performance if edge features are relevant for the task but also create more complexity. You might want to consider adding more GNN layers to the model (to allow for more neighbor-hops). Artificial Nodes led to an increase in AUC of about 2%.</p><p><strong>Your own Edge Feature architecture<br></strong>You can also create your own GNN layer implementation. This sounds pretty tough; however, if you use a graph learning library such as <a href="https://www.dgl.ai/">DGL</a>, it is definitely doable. I suggest you use an existing GNN implementation (see <a href="https://docs.dgl.ai/en/0.6.x/api/python/nn.pytorch.html">here</a>) and adapt it to your needs.</p><p>As an example, I formulated my own implementation based on existing ideas from the GAT¹⁰ and the R-GCN¹, which I call Edge-GCN¹¹:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*5KdmwugFR_xLPdDAkSp3VQ.png" /><figcaption>My own Edge-GCN Formula (v represents nodes, e stands for edges, sigma is a non-linear activation function [RELU in this case], alpha is the learned attention score per relation type, c is a normalization constant)</figcaption></figure><p>The Edge-GCN uses the attention mechanism to learn the importance of edge versus node features for all different relation types¹¹. Reach out to me in case you are interested in the DGL implementation. The E-GCN architecture improved the results of the GNN Model by around 2% in AUC (as did the artificial nodes).</p><h3>Self-supervised Pre-training</h3><p>This is probably the most important trick to improve your GNN’s performance. Even though pre-training GNNs has already been explored in theory¹², the applications in practice are still rare⁶ ⁷ ⁸.</p><p><strong>The Idea</strong><br>The general idea is very similar to concepts from the areas of computer vision and natural language processing. Take, for example, the language model BERT¹³ that is trained to predict masked words in a sentence (this is self-supervised as it does not rely on labeled data). We usually do not care much about the specific task of predicting masked words. However, the resulting word embeddings are highly useful for many different tasks as the model learns about how specific words are related to each other.</p><p><strong>Self-Supervision</strong><br>We want to pre-train the GNN models node embeddings using a self-supervised task. This can be especially rewarding in the case of noisy labels, as the self-supervision process provides more “labeled” examples (because we do not need to provide labels for the pre-training) and could potentially also be less prone to noise¹¹ ¹².</p><p>If our final goal is to classify nodes, we could use link prediction on the entire graph as a self-supervised pre-training task. In link prediction, we attempt to predict if an edge (= link) exists between two nodes. Therefore, we train a GNN to differentiate between real edges and artificially introduced fake edges in the graph (“negative sampling for link prediction”). As we simply add fake and remove real edges between existing nodes in a graph, we do not rely on any labeled data. Following, we can use the resulting node embeddings from the link prediction GNN model as input for another node classification model.</p><p>Adding a self-supervised pre-training pipeline to the model increased its AUC scores by an astonishing additional 14%, making this the most impactful trick.</p><h3>Separate Pretext &amp; Downstream Tasks</h3><p>So far, we have only talked about pre-training a GNN on a self-supervised task (“pretext”) and using the same GNN architecture for the final (“downstream”) task. However, we do not have to use the same model architecture for both tasks. You can also combine different GNN architectures. Or even more promising:</p><p><strong>Best of both worlds<br></strong>As previously discussed, GNN layers might not be able to learn efficiently in all kinds of situations. Therefore, we can use a GNN model to create node embeddings using self-supervised pre-training and pass these embeddings to either a classical machine learning algorithm or fully connected neural network layers for the final downstream task. This architecture could be used for many different downstream tasks, from graph classification to node classification and regression.</p><p>The model will profit from combining the ability to access all information contained in the graph with non-linear manifold learning properties. Additionally, the model inherits some benefits from simpler machine learning algorithms, such as reduced training time and better explainability. In our experiments, tree-based models (e.g. Random Forest) showed particularly strong performance for the downstream task¹¹ of node classification, so maybe start from there.</p><p>Following you can find a graphical overview of the final pipeline incorporating all three presented ideas:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vU7Gzt_paof5oZ1zKjLr3Q.png" /><figcaption>Final pipeline using edge features, self-supervised pre-training, and a downstream Random Forest model to classify nodes in a graph (X represents features, E stands for learned embeddings and h is the hidden node representation) (image by the author)</figcaption></figure><p>This architecture represented our final model, with an AUC score of 78.1 (another + 1.5%), or a total increase in performance measured by AUC of 17% (base R-GCN model: AUC = 66.6)¹¹.</p><h3>Conclusion</h3><p>In this blog post, we discussed the shortcomings of graph neural network models and three main tips to boost your model&#39;s performance. Combining these tips, I was able to boost my final GNN models by 17% in AUC¹¹ (even more for other metrics).</p><p>First, you can try to leverage edge features if your data contains such and you consider them insightful for the final prediction task. Second, pre-training the GNN model using a self-supervised objective is often beneficial for the final model’s performance. It can increase the number of training examples and sometimes reduce inherent noise. Third, testing different architectures for the pre-text and the final prediction task can improve the model&#39;s predictive capabilities.</p><p>Did these tricks work for you? Let me know in the comment section if you have additions or feedback! Happy GNN tuning!</p><h3>References</h3><p>[1] Michael Schlichtkrull, Thomas N. Kipf, Peter Bloem, Rianne van den Berg, Ivan Titov, and Max Welling. Modeling relational data with graph convolutional networks, 2017.</p><p>[2] Ziniu Hu, Yuxiao Dong, Kuansan Wang, and Yizhou Sun. Heterogeneous graph transformer, 2020.</p><p>[3] <a href="https://deepfindr.com/understanding-graph-neural-networks-part-2-3/">https://deepfindr.com</a>, 2020.</p><p>[4] Davide Bacciu, Federico Errica, Alessio Michelia, Marco Podda. A Gentle Introduction to Deep Learning for Graphs, 2020</p><p>[5] Yulei Yang Dongsheng Li. NENN: Incorporate Node and Edge Features in Graph Neural Networks, 2020</p><p>[6] Federico Errica, Marco Podda, Davide Bacciu, and Alessio Micheli. A fair comparison of graph neural networks for graph classification, 2020.</p><p>[7] Clement Gastaud, Theophile Carniel, and Jean-Michel Dalle. The varying importance of extrinsic factors in the success of startup fundraising: competition at early-stage and networks at growth-stage, 2019.</p><p>[8] Dejun Jiang, Zhenxing Wu, Chang-Yu Hsieh, Guangyong Chen, Ben Liao, Zhe Wang, Chao Shen, Dongsheng Cao, Jian Wu, and Tingjun Hou. Could graph neural networks learn better molecular representation for drug discovery? 2021.</p><p>[9] Hoang NT and Takanori Maehara. Revisiting graph neural networks: All we have is low-pass filters, 2019.</p><p>[10] Petar Veličković, Guillem Cucurull, Arantxa Casanova, Adriana Romero, Pietro Liò, and Yoshua Bengio. Graph attention networks, 2018.</p><p>[11] Carlo Harprecht. Predicting Future Funding Rounds using Graph Neural Networks, 2021</p><p>[12] Weihua Hu, Bowen Liu, Joseph Gomes, Marinka Zitnik, Percy Liang, Vijay Pande, and Jure Leskovec. Strategies for Pre-training Graph Neural Networks, 2019.</p><p>[13] Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding, 2018.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=356f70086991" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/how-to-boost-your-gnn-356f70086991">How to boost your GNN</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>