ssgc

Implementation for Simple Spectral Graph Convolution in ICLR 2021

https://github.com/allenhaozhu/ssgc

Science Score: 18.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (7.3%) to scientific vocabulary
Last synced: 10 months ago · JSON representation ·

Repository

Implementation for Simple Spectral Graph Convolution in ICLR 2021

Basic Info
  • Host: GitHub
  • Owner: allenhaozhu
  • License: other
  • Language: Python
  • Default Branch: main
  • Size: 15.4 MB
Statistics
  • Stars: 74
  • Watchers: 5
  • Forks: 17
  • Open Issues: 15
  • Releases: 0
Created over 5 years ago · Last pushed over 3 years ago
Metadata Files
Readme License Citation

README.md

Simple Spectral Graph Convolutional

Overview

This repo contains an example implementation of the Simple Spectral Graph Convolutional (S^2GC) model. This code is based on SGC. We will update the code in Text Classification and Node Clustering latter.

SGC removes the nonlinearities and collapes the weight matrices in Graph Convolutional Networks (GCNs) and is essentially a linear model. However, it also cannot beat GCNs in most benchmarks. S^2GC is a new baseline method for GCNs and downstream applications.

S^2GC achieves competitive performance while saving much training time, basically the computational cost is very close to SGC.

Dataset | Metric | :------:|:------:| Cora | Acc: 83.0 % Citeseer| Acc: 73.6 % Pubmed | Acc: 80.6 % Reddit | F1: 95.3 %

This home repo contains the implementation for citation networks (Cora, Citeseer, and Pubmed) and social network (Reddit).

Dependencies

Our implementation works with PyTorch>=1.0.0 Install other dependencies: $ pip install -r requirement.txt

Data

We provide the citation network datasets under data/, which corresponds to the public data splits.

Usage

$ python citation_cora.py $ python citation_citeseer.py $ python citation_pubmed.py

Owner

  • Name: allenhaozhu
  • Login: allenhaozhu
  • Kind: user
  • Location: Canberra
  • Company: Australian National University

PhD Student

Citation (citation.py)

import time
import argparse
import numpy as np
import torch
import torch.nn.functional as F
import torch.optim as optim
from utils import load_citation, sgc_precompute, set_seed
from models import get_model
from metrics import accuracy
import pickle as pkl
from args import get_citation_args
from time import perf_counter

# Arguments
args = get_citation_args()

if args.tuned:
    if args.model == "SGC":
        with open("{}-tuning/{}.txt".format(args.model, args.dataset), 'rb') as f:
            args.weight_decay = pkl.load(f)['weight_decay']
            print("using tuned weight decay: {}".format(args.weight_decay))
    else:
        raise NotImplemented

# setting random seeds
set_seed(args.seed, args.cuda)

adj, features, labels, idx_train, idx_val, idx_test, dRoot = load_citation(args.dataset, args.normalization, args.cuda)

model = get_model(args.model, features.size(1), labels.max().item()+1, args.hidden, args.dropout, args.cuda)

if args.model == "SGC": features, precompute_time = sgc_precompute(features, adj, args.degree)
print("{:.4f}s".format(precompute_time))

def train_regression(model,
                     train_features, train_labels,
                     val_features, val_labels,
                     epochs=args.epochs, weight_decay=args.weight_decay,
                     lr=args.lr, dropout=args.dropout):

    optimizer = optim.Adam(model.parameters(), lr=lr,
                           weight_decay=weight_decay)
    t = perf_counter()
    best_acc_val = torch.zeros((1))
    best_model = None
    for epoch in range(epochs):
        model.train()
        optimizer.zero_grad()
        output = model(train_features)
        loss_train = F.cross_entropy(output, train_labels)
        loss_train.backward()
        optimizer.step()
        with torch.no_grad():
            model.eval()
            output = model(val_features)
            acc_val = accuracy(output, val_labels)
            if best_acc_val < acc_val:
                best_acc_val = acc_val
                best_model = model

    train_time = perf_counter()-t

    # with torch.no_grad():
    #     model.eval()
    #     output = model(val_features)
    #     acc_val = accuracy(output, val_labels)

    return best_model, best_acc_val, train_time

def test_regression(model, test_features, test_labels):
    model.eval()
    return accuracy(model(test_features), test_labels)

if args.model == "SGC":
    model, acc_val, train_time = train_regression(model, features[idx_train], labels[idx_train], features[idx_val], labels[idx_val],
                     args.epochs, args.weight_decay, args.lr, args.dropout)
    acc_test = test_regression(model, features[idx_test], labels[idx_test])

print("Validation Accuracy: {:.4f} Test Accuracy: {:.4f}".format(acc_val, acc_test))
print("Pre-compute time: {:.4f}s, train time: {:.4f}s, total: {:.4f}s".format(precompute_time, train_time, precompute_time+train_time))

GitHub Events

Total
  • Watch event: 2
  • Fork event: 1
Last Year
  • Watch event: 2
  • Fork event: 1

Dependencies

requirements.txt pypi
  • hyperopt ==0.1.1
  • networkx ==1.11
  • numpy *
  • scikit-learn *
  • scipy *