Scalability and optimization
Handling large-scale graphs requires advanced techniques for efficient training and inference. We covered the challenge of scalability in Chapter 5; here, we’ll look at practical examples of techniques that can help us address this issue.
Mini-batch training with neighborhood sampling
Instead of processing the entire graph, we can use mini-batch training with neighborhood sampling:
- Sample a subset of user nodes:
def create_mini_batch(G, batch_size, n_pos=5, n_neg=5,                       n_neighbors=10, n_hops=2):     # Get all user nodes     all_user_nodes = [n for n in G.nodes() if                       n.startswith('user_')]     if not all_user_nodes...