Package: hybrid-graph
This is a benchmark dataset for evaluatinghybrid-graph(hypergraph and hierarchical graph) learning algorithms. It contains:23 real-world higer-order graphs from the domains of biology, social media, and wikipediaBuilt-in functionalities for preprocessing hybrid-graphsA framework to easily train and evaluate Graph Neural NetworksInstallationRequirementsFirst, install the required PyTorch packages. You will need to know the version of CUDA you have installed, as well as the version of PyTorch you want to use. Replace${TORCH}and${CUDA}with these versions in the following commands:# TORCH=2.0.1 if use newest stable torch version# CUDA=cpu if cuda is not availablepython-mpipinstalltorch-scatter-fhttps://data.pyg.org/whl/torch-${TORCH}+${CUDA}.html
python-mpipinstalltorch-sparse-fhttps://data.pyg.org/whl/torch-${TORCH}+${CUDA}.html
python-mpipinstalltorch-geometric==2.2.0Once these dependencies are installed, you can install this package with one of the following:Pip installpipinstallhybrid-graph# or pip install git+https://github.com/Zehui127/hybrid-graph-benchmark.gitFrom sourcegitclonehttps://github.com/Zehui127/hybrid-graph-benchmark.gitcdhybrid-graph-benchmark
pipinstall-e.UsageHybrid-graph provide both datasets and flash training/evaluation capabilities.(1) Access the Datasetwe use thetorch_geometric.data.Datato wrap the graphs with additional adjacency matrix for hyperedge representation.fromhg.datasetsimportFacebook,HypergraphSAINTNodeSampler# download data to the path 'data/facebook'data=Facebook('data/facebook')print(data[0])# e.g. Data(x=[22470, 128], edge_index=[2, 342004], y=[22470], hyperedge_index=[2, 2344151], num_hyperedges=236663)# create a sampler which sample 1000 nodes from the graph for 5 timessampler=HypergraphSAINTNodeSampler(data[0],batch_size=1000,num_steps=5)batch=next(iter(sampler))print(batch)# e.g. Data(num_nodes=918, edge_index=[2, 7964], hyperedge_index=[2, 957528], num_hyperedges=210718, x=[918, 128], y=[918])Data Loaders can also be obtained usinghg.hybrid_graph.io.get_datasetfromhg.hybrid_graph.ioimportget_datasetname='musae_Facebook'train_loader,valid_loader,test_loader,data_info=get_dataset(name)(2) Train/Evaluate withhybrid-graphAssuming that you havePip install.Training can be triggered with the following, it takes only a few minutes to train GCN even on CPU device.#-a=gpu,cpu,tpuhybrid-graphtraingrand_Lunggcn-a=cpuEvaluation can be triggered with# load the saved checkpoint from the path 'lightning_logs/version_0/checkpoints/best.ckpt'hybrid-graphevalgrand_lunggcn-load='lightning_logs/version_0/checkpoints/best.ckpt'-a=cpuAdd New ModelsIn order to add new models, you shouldInstall from source.cdhybrid-graph-benchmark/hg/hybrid_graph/models/gnn
touchcustomize_model.pyWithincustomize_model.py, it should correctly handle the input feature size, prediction size and task type.
Below is the definition of vanila Graph Convolutional Networks (GCN)fromtorch_geometric.nnimportGCNConvclassCustomizeGNN(torch.nn.Module):def__init__(self,info,*args,**kwargs):super().__init__()dim=32self.conv1=GCNConv(info["num_node_features"],dim)self.is_regression=info["is_regression"]ifinfo["is_regression"]:self.conv2=GCNConv(dim,dim)self.head=nn.Linear(dim,1)else:self.conv2=GCNConv(dim,info["num_classes"])defforward(self,data,*args,**kargs):x,edge_index=data.x,data.edge_indexx=F.relu(self.conv1(x,edge_index))x=F.dropout(x,training=self.training)x=self.conv2(x,edge_index)ifself.is_regression:x=self.head(x).squeeze()else:x=F.log_softmax(x,dim=1)returnxFinally, you should register you model inhybrid-graph-benchmark/hg/hybrid_graph/models/__init__.pyfrom.gnn.customize_modelimportCustomizeGNNfactory={'sage':SAGENet,'gcn':CustomizeGNN,# abbreviation: ClassName,}