Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Hands-On Graph Neural Networks Using Python

You're reading from  Hands-On Graph Neural Networks Using Python

Product type Book
Published in Apr 2023
Publisher Packt
ISBN-13 9781804617526
Pages 354 pages
Edition 1st Edition
Languages
Author (1):
Maxime Labonne Maxime Labonne
Profile icon Maxime Labonne

Table of Contents (25) Chapters

Preface Part 1: Introduction to Graph Learning
Chapter 1: Getting Started with Graph Learning Chapter 2: Graph Theory for Graph Neural Networks Chapter 3: Creating Node Representations with DeepWalk Part 2: Fundamentals
Chapter 4: Improving Embeddings with Biased Random Walks in Node2Vec Chapter 5: Including Node Features with Vanilla Neural Networks Chapter 6: Introducing Graph Convolutional Networks Chapter 7: Graph Attention Networks Part 3: Advanced Techniques
Chapter 8: Scaling Up Graph Neural Networks with GraphSAGE Chapter 9: Defining Expressiveness for Graph Classification Chapter 10: Predicting Links with Graph Neural Networks Chapter 11: Generating Graphs Using Graph Neural Networks Chapter 12: Learning from Heterogeneous Graphs Chapter 13: Temporal Graph Neural Networks Chapter 14: Explaining Graph Neural Networks Part 4: Applications
Chapter 15: Forecasting Traffic Using A3T-GCN Chapter 16: Detecting Anomalies Using Heterogeneous GNNs Chapter 17: Building a Recommender System Using LightGCN Chapter 18: Unlocking the Potential of Graph Neural Networks for Real-World Applications
Index Other Books You May Enjoy

Building a Recommender System Using LightGCN

Recommender systems have become an integral part of modern online platforms, with the goal of providing personalized recommendations to users based on their interests and past interactions. These systems can be found in a variety of applications, including suggesting products to purchase on e-commerce websites, recommending content to watch on streaming services, and suggesting connections to make on social media platforms.

Recommendation systems are one of the main applications of GNNs. Indeed, they can effectively incorporate the complex relationships between users, items, and their interactions into a unified model. In addition, the graph structure allows for the incorporation of side information, such as user and item metadata, into the recommendation process.

In this chapter, we will introduce a new GNN architecture called LightGCN, specifically designed for recommender systems. We will also introduce a new dataset, the Book-Crossing...

Technical requirements

All the code examples from this chapter can be found on GitHub at https://github.com/PacktPublishing/Hands-On-Graph-Neural-Networks-Using-Python/tree/main/Chapter17. The installation steps required to run the code on your local machine can be found in the Preface of this book.

This chapter requires a large amount of GPU. You can lower it by decreasing the size of the training set in the code.

Exploring the Book-Crossing dataset

In this section, we will perform exploratory data analysis on a new dataset and visualize its main characteristics.

The Book-Crossing dataset [1] is a collection of book ratings provided by 278,858 users in the BookCrossing community (www.bookcrossing.com). The ratings, which are both explicit (rating between 1 and 10) and implicit (users interacted with the book), total 1,149,780 and pertain to 271,379 books. The dataset was collected by Cai-Nicolas Ziegler during a four-week crawl in August and September 2004. We will use the Book-Crossing dataset to build a book recommender system in this chapter.

Let’s download the dataset and unzip it with the following commands:

from io import BytesIO
from urllib.request import urlopen
from zipfile import ZipFile
url = 'http://www2.informatik.uni-freiburg.de/~cziegler/BX/BX-CSV-Dump.zip'
with urlopen(url) as zurl:
    with ZipFile(BytesIO(zurl.read())) as zfile...

Preprocessing the Book-Crossing dataset

We want to process the dataset for a particular task: recommending items, and more specifically using a collaborative filtering approach. Collaborative filtering is a technique used to make personalized recommendations to users. It is based on the idea that users who have similar preferences or behaviors are more likely to have similar interests. Collaborative filtering algorithms use this information to identify patterns and make recommendations to users based on the preferences of similar users.

This is different from content-based filtering, which is a recommendation approach that relies on the features of the items being recommended. It generates recommendations by identifying the characteristics of an item and matching them to the characteristics of other items that have been liked by the user in the past. Content-based filtering approaches are typically based on the idea that if a user likes an item with certain characteristics, they...

Implementing the LightGCN architecture

The LightGCN [4] architecture aims to learn representations for nodes by smoothing features over the graph. It iteratively performs graph convolution, where neighboring nodes’ features are aggregated as the new representation of a target node. The entire architecture is summarized in Figure 17.6.

Figure 17.6 – LightGCN model architecture with convolution and layer combination

Figure 17.6 – LightGCN model architecture with convolution and layer combination

However, LightGCN adopts a simple weighted sum aggregator rather than using feature transformation or nonlinear activation as seen in other models such as the GCN or GAT. The light graph convolution operation calculates the -th user and item embedding and as follows:

The symmetric normalization term ensures that the scale of embeddings does not increase with graph convolution operations. In contrast to other models, LightGCN only aggregates the connected neighbors and does not...

Summary

This chapter presented a detailed exploration of using LightGCN for book recommendation tasks. We used the Book-Crossing dataset, preprocessed it to form a bipartite graph, and implemented a LightGCN model with BPR loss. We trained the model and evaluated it using the recall@20 and ndcg@20 metrics. We demonstrated the effectiveness of the model by generating recommendations for a given user.

Overall, this chapter has provided valuable insight into the usage of LightGCN models in recommendation tasks. It is a state-of-the-art architecture that performs better than more complex models. You can expand this project by trying other techniques we discussed in previous chapters, such as matrix factorization and node2vec.

Further reading

lock icon The rest of the chapter is locked
You have been reading a chapter from
Hands-On Graph Neural Networks Using Python
Published in: Apr 2023 Publisher: Packt ISBN-13: 9781804617526
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}