How to use the spektral.datasets.citation function in spektral

To help you get started, we’ve selected a few spektral examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github danielegrattarola / spektral / tests / benchmarks / citation / citation.py View on Github external
'n_layers': neighbourhood,
        'kwargs': {
            'mlp_channels': 32
        },
        'fltr': lambda A: A,
        'sparse': True
    }
]

results = {}
weights = []
for c in CONFIG:
    acc = []
    times = []
    for i in range(runs):
        A, X, y, train_mask, val_mask, test_mask = citation.load_data(
            dataset, random_split=True
        )

        # Parameters
        N = X.shape[0]          # Number of nodes in the graph
        F = X.shape[1]          # Original feature dimensionality
        n_classes = y.shape[1]  # Number of classes

        # Preprocessing operations
        fltr = c['fltr'](A)

        # Model definition
        X_in = Input(shape=(F, ))
        fltr_in = Input((N, ), sparse=c['sparse'])

        gc_1 = Dropout(dropout_rate)(X_in)
github danielegrattarola / spektral / tests / benchmarks / node_classification / node_classification.py View on Github external
'sparse': True
    }
]

results = {}
weights = []
for c in CONFIG:
    acc = []
    times = []
    for i in range(runs):
        if dataset == 'ppi':
            A, X, y, train_mask, val_mask, test_mask = graphsage.load_data(
                dataset_name=dataset
            )
        else:
            A, X, y, train_mask, val_mask, test_mask = citation.load_data(
                dataset, random_split=True
            )

        # Parameters
        N = X.shape[0]          # Number of nodes in the graph
        F = X.shape[1]          # Original feature dimensionality
        n_classes = y.shape[1]  # Number of classes

        # Preprocessing operations
        fltr = c['fltr'](A)

        # Model definition
        X_in = Input(shape=(F, ))
        fltr_in = Input((N, ), sparse=c['sparse'])

        gc_1 = Dropout(dropout_rate)(X_in)
github danielegrattarola / spektral / tests / test_datasets.py View on Github external
def test_citation():
    for dataset_name in ['cora', 'citeseer', 'pubmed']:
        citation.load_data(dataset_name)
        citation.load_data(dataset_name, random_split=True)
github danielegrattarola / spektral / tests / test_datasets.py View on Github external
def test_citation():
    for dataset_name in ['cora', 'citeseer', 'pubmed']:
        citation.load_data(dataset_name)
        citation.load_data(dataset_name, random_split=True)
github danielegrattarola / spektral / docs / autogen.py View on Github external
'classes': [
            layers.TopKPool,
            layers.MinCutPool,
            layers.DiffPool,
            layers.SAGPool,
            layers.GlobalSumPool,
            layers.GlobalAvgPool,
            layers.GlobalMaxPool,
            layers.GlobalAttentionPool,
            layers.GlobalAttnSumPool
        ]
    },
    {
        'page': 'datasets/citation.md',
        'functions': [
            datasets.citation.load_data
        ],
        'methods': [],
        'classes': []
    },
    {
        'page': 'datasets/graphsage.md',
        'functions': [
            datasets.graphsage.load_data
        ],
        'methods': [],
        'classes': []
    },
    {
        'page': 'datasets/tud.md',
        'functions': [
            datasets.tud.load_data
github danielegrattarola / spektral / examples / node_classification_gcn.py View on Github external
Thomas N. Kipf, Max Welling
"""

from keras.callbacks import EarlyStopping
from keras.layers import Input, Dropout
from keras.models import Model
from keras.optimizers import Adam
from keras.regularizers import l2

from spektral.datasets import citation
from spektral.layers import GraphConv
from spektral.utils import localpooling_filter

# Load data
dataset = 'cora'
A, X, y, train_mask, val_mask, test_mask = citation.load_data(dataset)

# Parameters
channels = 16           # Number of channels in the first layer
N = X.shape[0]          # Number of nodes in the graph
F = X.shape[1]          # Original feature dimensionality
n_classes = y.shape[1]  # Number of classes
dropout = 0.5           # Dropout rate applied to the features
l2_reg = 5e-4           # Regularization rate for l2
learning_rate = 1e-2    # Learning rate for SGD
epochs = 20000          # Number of training epochs
es_patience = 200       # Patience for early stopping

# Preprocessing operations
fltr = localpooling_filter(A)

# Model definition
github danielegrattarola / spektral / examples / node_classification_cheb.py View on Github external
Michaël Defferrard, Xavier Bresson, Pierre Vandergheynst
"""

from keras.callbacks import EarlyStopping, ModelCheckpoint
from keras.layers import Input, Dropout
from keras.models import Model
from keras.optimizers import Adam
from keras.regularizers import l2

from spektral.datasets import citation
from spektral.layers import ChebConv
from spektral.utils.convolution import chebyshev_filter

# Load data
dataset = 'cora'
A, X, y, train_mask, val_mask, test_mask = citation.load_data(dataset)

# Parameters
channels = 16           # Number of channels in the first layer
cheb_k = 2              # Max degree of the Chebyshev approximation
support = cheb_k + 1    # Total number of filters (k + 1)
N = X.shape[0]          # Number of nodes in the graph
F = X.shape[1]          # Original feature dimensionality
n_classes = y.shape[1]  # Number of classes
dropout = 0.5           # Dropout rate applied to the features
l2_reg = 5e-4           # Regularization rate for l2
learning_rate = 1e-2    # Learning rate for SGD
epochs = 20000          # Number of training epochs
es_patience = 200       # Patience for early stopping

# Preprocessing operations
fltr = chebyshev_filter(A, cheb_k)
github danielegrattarola / spektral / examples / node_classification_arma.py View on Github external
Filippo Maria Bianchi, Daniele Grattarola, Cesare Alippi, Lorenzo Livi
"""

from keras.callbacks import EarlyStopping, ModelCheckpoint
from keras.layers import Input, Dropout
from keras.models import Model
from keras.optimizers import Adam
from keras.regularizers import l2

from spektral.datasets import citation
from spektral.layers import ARMAConv
from spektral.utils import normalized_laplacian, rescale_laplacian

# Load data
dataset = 'cora'
A, X, y, train_mask, val_mask, test_mask = citation.load_data(dataset)

# Parameters
ARMA_T = 1              # Depth of each ARMA_1 filter
ARMA_K = 2              # Number of parallel ARMA_1 filters
recurrent = True        # Share weights like a recurrent net in each head
N = X.shape[0]          # Number of nodes in the graph
F = X.shape[1]          # Original feature dimensionality
n_classes = y.shape[1]  # Number of classes
dropout_rate = 0.75     # Dropout rate applied to the input of GCN layers
l2_reg = 5e-4           # Regularization rate for l2
learning_rate = 1e-2    # Learning rate for SGD
epochs = 20000          # Number of training epochs
es_patience = 200       # Patience for early stopping

# Preprocessing operations
fltr = normalized_laplacian(A, symmetric=True)
github danielegrattarola / spektral / examples / node_classification_gat.py View on Github external
Petar Veličković, Guillem Cucurull, Arantxa Casanova, Adriana Romero, Pietro Liò, Yoshua Bengio
"""

from keras.callbacks import EarlyStopping, ModelCheckpoint
from keras.layers import Input, Dropout
from keras.models import Model
from keras.optimizers import Adam
from keras.regularizers import l2

from spektral.datasets import citation
from spektral.layers import GraphAttention
from spektral.utils.misc import add_eye

# Load data
dataset = 'cora'
A, X, y, train_mask, val_mask, test_mask = citation.load_data(dataset)

# Parameters
gat_channels = 8        # Output size of first GraphAttention layer
n_attn_heads = 8        # Number of attention heads in first GAT layer
N = X.shape[0]          # Number of nodes in the graph
F = X.shape[1]          # Original feature dimensionality
n_classes = y.shape[1]  # Number of classes
dropout_rate = 0.25     # Dropout rate applied to the input of GAT layers
l2_reg = 5e-4           # Regularization rate for l2
learning_rate = 1e-2    # Learning rate for SGD
epochs = 20000          # Number of training epochs
es_patience = 200       # Patience fot early stopping

# Preprocessing operations
A = add_eye(A).toarray()  # Add self-loops
github danielegrattarola / spektral / examples / node_classification_simple_gc.py View on Github external
Felix Wu, Tianyi Zhang, Amauri Holanda de Souza Jr., Christopher Fifty, Tao Yu, Kilian Q. Weinberger
"""

from keras.callbacks import EarlyStopping
from keras.layers import Input
from keras.models import Model
from keras.optimizers import Adam
from keras.regularizers import l2

from spektral.datasets import citation
from spektral.layers import GraphConv
from spektral.utils.convolution import localpooling_filter

# Load data
dataset = 'cora'
A, X, y, train_mask, val_mask, test_mask = citation.load_data(dataset)

# Parameters
K = 2                   # Degree of propagation
N = X.shape[0]          # Number of nodes in the graph
F = X.shape[1]          # Original feature dimensionality
n_classes = y.shape[1]  # Number of classes
l2_reg = 5e-6           # Regularization rate for l2
learning_rate = 0.2     # Learning rate for SGD
epochs = 20000          # Number of training epochs
es_patience = 200       # Patience for early stopping

# Preprocessing operations
fltr = localpooling_filter(A)

# Pre-compute propagation
for i in range(K - 1):