Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Cluster-GCN and GCN graph classification into GCN layer #1205

Merged
merged 8 commits into from
Apr 20, 2020

Conversation

huonw
Copy link
Member

@huonw huonw commented Apr 6, 2020

ClusterGraphConvolution and GraphConvolution were practically identical, with just some minor differences in the details of the code, and GraphClassificationConvolution only differed by:

  1. not using any output indices, which is moved out of GraphConvolution in Gather output nodes in full batch models, not the layers #1204
  2. supporting a batch of multiple graphs (i.e. multiple sets of node features and adjacency matrices); the core of this patch is thus expanding GraphConvolution to handle a batch size > 1 for dense matrices, not sparse ones (yet, since it's harder: Keras's .batch_dot doesn't seem to support sparse matrices).

That is, by building on #1204, this patch can merge all three of our implementations of the GCN layer.

This deprecates ClusterGraphConvolution because it has been released for a while, but removes GraphClassificationConvolution entirely, because it has only been released @experimental-y.

See: #1201

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

You'll be able to see Jupyter notebook diff and discuss changes. Powered by ReviewNB.

huonw added a commit that referenced this pull request Apr 7, 2020
The core layer in a full batch method (like `GraphConvolution` inside `GCN`)
natively computes information about a whole graph, but this doesn't directly
work with machine learning (and, in particular, how it works with `Keras`). In
particular, there's usually only a subset of labelled nodes, so training needs
to only compute candidate embeddings for those nodes to compare against the
ground-truth target array.

We currently handle this in full batch methods by having each layer know whether
it is the `final_layer` in the model, and do `tf.gather` using a tensor of
indices of relevant nodes. This means that the individual full-batch layers have
to:

- always accept the tensor of indices, even if they won't use it (and,
  potentially, even if they are being used as part of a model that doesn't ever
  use it)
- do the appropriate `tf.gather` invocation to select the relevant nodes

This patch adjusts this approach to make the output filtering a model level
concern: layers always compute all the information, and models that need to can
do a `tf.gather` call (via the new `layer.misc.GatherIndices`) to select out the
relevant output elements. This has a few benefits:

- it seems conceptually more "correct" to me, because it's the training/using of
  a overall model that needs to filter out elements, _not_ the operation of an
  individual layer
- it reduces the amount of code required noticeably, and will reduce if further
  when we remove the left-over-`final_layer` detection (that is designed to help
  us migrate).
- it makes #1201 easier (in #1205): graph classification doesn't have any output
  indices to feed into the graph convolution layers, and so this patch makes
  `GraphConvolution` closer to the behaviour required for that
- it may also ease implementing models that incorporate information from
  multiple convolution layers, because it's easy to make sure all the
  convolution layers compute embeddings for all nodes

See: #1201
@huonw huonw changed the base branch from feature/model-level-output-indices to develop April 7, 2020 01:55
@huonw huonw force-pushed the feature/1201-deduplicate-gcn branch from dd91833 to 62d18e2 Compare April 7, 2020 01:56
@huonw huonw marked this pull request as ready for review April 7, 2020 01:56
@codeclimate
Copy link

codeclimate bot commented Apr 7, 2020

Code Climate has analyzed commit bf54b3a and detected 0 issues on this pull request.

View more on Code Climate.

@huonw huonw requested review from PantelisElinas and kjun9 April 7, 2020 02:38
Copy link
Contributor

@kjun9 kjun9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍 Just some minor comments

stellargraph/layer/gcn.py Outdated Show resolved Hide resolved
stellargraph/layer/gcn.py Outdated Show resolved Hide resolved
stellargraph/layer/gcn.py Outdated Show resolved Hide resolved
stellargraph/layer/gcn.py Outdated Show resolved Hide resolved
stellargraph/layer/cluster_gcn.py Outdated Show resolved Hide resolved
Copy link
Contributor

@kjun9 kjun9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

stellargraph/layer/gcn.py Outdated Show resolved Hide resolved
@huonw huonw merged commit 56e6adb into develop Apr 20, 2020
@huonw huonw deleted the feature/1201-deduplicate-gcn branch April 20, 2020 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants