code: def preprocess(G, node_label_index, method="louvain"):
      graphs = []
      labeled_nodes = set(node_label_index.tolist())
      if method == "louvain":
          community_mapping = community_louvain.best_partition(
              G, resolution=10
          )
          communities = {}
          for node in community_mapping:
              comm = community_mapping[node]
              if comm in communities:
                  communities[comm].add(node)
              else:
                  communities[comm] = set([node])
          communities = communities.values()
      elif method == "bisection":
          communities = nx.algorithms.community.kernighan_lin_bisection(
              G
          )
      elif method == "greedy":
          communities = (
              nx.algorithms.community.greedy_modularity_communities(G)
          )
  
      for community in communities:
          nodes = set(community)
          subgraph = G.subgraph(nodes)
          # Make sure each subgraph has more than 10 nodes
          if subgraph.number_of_nodes() > 10:
              node_mapping = {
                  node: i for i, node in enumerate(subgraph.nodes())
              }
              subgraph = nx.relabel_nodes(subgraph, node_mapping)
              # Get the id of the training set labeled node in the new graph
              train_label_index = []
              for node in labeled_nodes:
                  if node in node_mapping:
                      # Append relabeled labeled node index
                      train_label_index.append(node_mapping[node])
  
              # Make sure the subgraph contains at least one training set labeled node
              if len(train_label_index) > 0:
                  dg = Graph(subgraph)
                  # Update node_label_index
                  dg.node_label_index = torch.tensor(
                      train_label_index, dtype=torch.long
                  )
                  graphs.append(dg)
      return graphs
  
file_path: deepsnap/examples/sampling/cluster.py
imports: import copy
  import torch
  import random
  import argparse
  import numpy
  import networkx
  import torch.nn
  import torch.nn.functional
  import community
  from torch_geometric.nn import SAGEConv
  from torch.utils.data import DataLoader
  from torch_geometric.datasets import Planetoid
  from torch.nn import Sequential, Linear, ReLU
  from deepsnap.dataset import GraphDataset
  from deepsnap.graph import Graph
  from model import *
label_desc: Use image node_id 2 for calling a global function with example usage: preprocess(G, node_label_index, method) and returns: graphs