You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/pluto_output/gnn_intro_pluto.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@
33
33
<p>Recently, deep learning on graphs has emerged to one of the hottest research fields in the deep learning community. Here, <strong>Graph Neural Networks (GNNs)</strong> aim to generalize classical deep learning concepts to irregular structured data (in contrast to images or texts) and to enable neural networks to reason about objects and their relations.</p>
34
34
<p>This is done by following a simple <strong>neural message passing scheme</strong>, where node features <span class="tex">$\mathbf{x}_i^{(\ell)}$</span> of all nodes <span class="tex">$i \in \mathcal{V}$</span> in a graph <span class="tex">$\mathcal{G} = (\mathcal{V}, \mathcal{E})$</span> are iteratively updated by aggregating localized information from their neighbors <span class="tex">$\mathcal{N}(i)$</span>:</p>
<p>This tutorial will introduce you to some fundamental concepts regarding deep learning on graphs via Graph Neural Networks based on the <strong><a href="https://github.com/CarloLucibello/GraphNeuralNetworks.jl">GraphNeuralNetworks.jl library</a></strong>. GNN.jl is an extension library to the popular deep learning framework <a href="https://fluxml.ai/Flux.jl/stable/">Flux.jl</a>, and consists of various methods and utilities to ease the implementation of Graph Neural Networks.</p>
36
+
<p>This tutorial will introduce you to some fundamental concepts regarding deep learning on graphs via Graph Neural Networks based on the <strong><a href="https://github.com/CarloLucibello/GraphNeuralNetworks.jl">GraphNeuralNetworks.jl library</a></strong>. GraphNeuralNetworks.jl is an extension library to the popular deep learning framework <a href="https://fluxml.ai/Flux.jl/stable/">Flux.jl</a>, and consists of various methods and utilities to ease the implementation of Graph Neural Networks.</p>
37
37
<p>Let's first import the packages we need:</p>
38
38
</div>
39
39
@@ -70,7 +70,7 @@ end;</code></pre>
70
70
71
71
72
72
<div class="markdown"><p>Following <a href="https://arxiv.org/abs/1609.02907">Kipf et al. (2017)</a>, let's dive into the world of GNNs by looking at a simple graph-structured example, the well-known <a href="https://en.wikipedia.org/wiki/Zachary%27s_karate_club"><strong>Zachary's karate club network</strong></a>. This graph describes a social network of 34 members of a karate club and documents links between members who interacted outside the club. Here, we are interested in detecting communities that arise from the member's interaction.</p>
73
-
<p>GNN.jl provides utilities to convert <a href="https://github.com/JuliaML/MLDatasets.jl">MLDatasets.jl</a>'s datasets to its own type:</p>
73
+
<p>GraphNeuralNetworks.jl provides utilities to convert <a href="https://github.com/JuliaML/MLDatasets.jl">MLDatasets.jl</a>'s datasets to its own type:</p>
<div class="markdown"><p>Each graph in GNN.jl is represented by a <code>GNNGraph</code> object, which holds all the information to describe its graph representation. We can print the data object anytime via <code>print(g)</code> to receive a short summary about its attributes and their shapes.</p>
166
+
<div class="markdown"><p>Each graph in GraphNeuralNetworks.jl is represented by a <code>GNNGraph</code> object, which holds all the information to describe its graph representation. We can print the data object anytime via <code>print(g)</code> to receive a short summary about its attributes and their shapes.</p>
<div class="markdown"><p>By printing <code>edge_index(g)</code>, we can understand how GNN.jl represents graph connectivity internally. We can see that for each edge, <code>edge_index</code> holds a tuple of two node indices, where the first value describes the node index of the source node and the second value describes the node index of the destination node of an edge.</p>
187
-
<p>This representation is known as the <strong>COO format (coordinate format)</strong> commonly used for representing sparse matrices. Instead of holding the adjacency information in a dense representation <span class="tex">$\mathbf{A} \in \{ 0, 1 \}^{|\mathcal{V}| \times |\mathcal{V}|}$</span>, GNN.jl represents graphs sparsely, which refers to only holding the coordinates/values for which entries in <span class="tex">$\mathbf{A}$</span> are non-zero.</p>
188
-
<p>Importantly, GNN.jl does not distinguish between directed and undirected graphs, and treats undirected graphs as a special case of directed graphs in which reverse edges exist for every entry in the edge_index.</p>
186
+
<div class="markdown"><p>By printing <code>edge_index(g)</code>, we can understand how GraphNeuralNetworks.jl represents graph connectivity internally. We can see that for each edge, <code>edge_index</code> holds a tuple of two node indices, where the first value describes the node index of the source node and the second value describes the node index of the destination node of an edge.</p>
187
+
<p>This representation is known as the <strong>COO format (coordinate format)</strong> commonly used for representing sparse matrices. Instead of holding the adjacency information in a dense representation <span class="tex">$\mathbf{A} \in \{ 0, 1 \}^{|\mathcal{V}| \times |\mathcal{V}|}$</span>, GraphNeuralNetworks.jl represents graphs sparsely, which refers to only holding the coordinates/values for which entries in <span class="tex">$\mathbf{A}$</span> are non-zero.</p>
188
+
<p>Importantly, GraphNeuralNetworks.jl does not distinguish between directed and undirected graphs, and treats undirected graphs as a special case of directed graphs in which reverse edges exist for every entry in the edge_index.</p>
189
189
<p>Since a <code>GNNGraph</code> is an <code>AbstractGraph</code> from the <code>Graphs.jl</code> library, it supports graph algorithms and visualization tools from the wider julia graph ecosystem:</p>
190
190
</div>
191
191
@@ -198,11 +198,11 @@ Is undirected: true
198
198
```@raw html
199
199
<div class="markdown">
200
200
201
-
<p>After learning about GNN.jl's data handling, it's time to implement our first Graph Neural Network!</p>
201
+
<p>After learning about GraphNeuralNetworks.jl's data handling, it's time to implement our first Graph Neural Network!</p>
202
202
<p>For this, we will use on of the most simple GNN operators, the <strong>GCN layer</strong> (<a href="https://arxiv.org/abs/1609.02907">Kipf et al. (2017)</a>), which is defined as</p>
<p>where <span class="tex">$\mathbf{W}^{(\ell + 1)}$</span> denotes a trainable weight matrix of shape <code>[num_output_features, num_input_features]</code> and <span class="tex">$c_{w,v}$</span> refers to a fixed normalization coefficient for each edge.</p>
205
-
<p>GNN.jl implements this layer via <code>GCNConv</code>, which can be executed by passing in the node feature representation <code>x</code> and the COO graph connectivity representation <code>edge_index</code>.</p>
205
+
<p>GraphNeuralNetworks.jl implements this layer via <code>GCNConv</code>, which can be executed by passing in the node feature representation <code>x</code> and the COO graph connectivity representation <code>edge_index</code>.</p>
206
206
<p>With this, we are ready to create our first Graph Neural Network by defining our network architecture:</p>
Copy file name to clipboardExpand all lines: docs/pluto_output/graph_classification_pluto.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -141,15 +141,15 @@ end</code></pre>
141
141
<div class="markdown">
142
142
143
143
<p>Since graphs in graph classification datasets are usually small, a good idea is to <strong>batch the graphs</strong> before inputting them into a Graph Neural Network to guarantee full GPU utilization. In the image or language domain, this procedure is typically achieved by <strong>rescaling</strong> or <strong>padding</strong> each example into a set of equally-sized shapes, and examples are then grouped in an additional dimension. The length of this dimension is then equal to the number of examples grouped in a mini-batch and is typically referred to as the <code>batchsize</code>.</p>
144
-
<p>However, for GNNs the two approaches described above are either not feasible or may result in a lot of unnecessary memory consumption. Therefore, GNN.jl opts for another approach to achieve parallelization across a number of examples. Here, adjacency matrices are stacked in a diagonal fashion (creating a giant graph that holds multiple isolated subgraphs), and node and target features are simply concatenated in the node dimension (the last dimension).</p>
144
+
<p>However, for GNNs the two approaches described above are either not feasible or may result in a lot of unnecessary memory consumption. Therefore, GraphNeuralNetworks.jl opts for another approach to achieve parallelization across a number of examples. Here, adjacency matrices are stacked in a diagonal fashion (creating a giant graph that holds multiple isolated subgraphs), and node and target features are simply concatenated in the node dimension (the last dimension).</p>
145
145
<p>This procedure has some crucial advantages over other batching procedures:</p>
146
146
<ol>
147
147
<li><p>GNN operators that rely on a message passing scheme do not need to be modified since messages are not exchanged between two nodes that belong to different graphs.</p>
148
148
</li>
149
149
<li><p>There is no computational or memory overhead since adjacency matrices are saved in a sparse fashion holding only non-zero entries, <em>i.e.</em>, the edges.</p>
150
150
</li>
151
151
</ol>
152
-
<p>GNN.jl can <strong>batch multiple graphs into a single giant graph</strong>:</p>
152
+
<p>GraphNeuralNetworks.jl can <strong>batch multiple graphs into a single giant graph</strong>:</p>
<p>GNN.jl provides this functionality via <code>GlobalPool(mean)</code>, which takes in the node embeddings of all nodes in the mini-batch and the assignment vector <code>graph_indicator</code> to compute a graph embedding of size <code>[hidden_channels, batchsize]</code>.</p>
188
+
<p>GraphNeuralNetworks.jl provides this functionality via <code>GlobalPool(mean)</code>, which takes in the node embeddings of all nodes in the mini-batch and the assignment vector <code>graph_indicator</code> to compute a graph embedding of size <code>[hidden_channels, batchsize]</code>.</p>
189
189
<p>The final architecture for applying GNNs to the task of graph classification then looks as follows and allows for complete end-to-end training:</p>
190
190
</div>
191
191
@@ -263,7 +263,7 @@ end</code></pre>
263
263
<h2>(Optional) Exercise</h2>
264
264
<p>Can we do better than this? As multiple papers pointed out (<a href="https://arxiv.org/abs/1810.00826">Xu et al. (2018)</a>, <a href="https://arxiv.org/abs/1810.02244">Morris et al. (2018)</a>), applying <strong>neighborhood normalization decreases the expressivity of GNNs in distinguishing certain graph structures</strong>. An alternative formulation (<a href="https://arxiv.org/abs/1810.02244">Morris et al. (2018)</a>) omits neighborhood normalization completely and adds a simple skip-connection to the GNN layer in order to preserve central node information:</p>
<p>This layer is implemented under the name <code>GraphConv</code> in GNN.jl.</p>
266
+
<p>This layer is implemented under the name <code>GraphConv</code> in GraphNeuralNetworks.jl.</p>
267
267
<p>As an exercise, you are invited to complete the following code to the extent that it makes use of <code>GraphConv</code> rather than <code>GCNConv</code>. This should bring you close to <strong>82% test accuracy</strong>.</p>
Copy file name to clipboardExpand all lines: docs/tutorials/introductory_tutorials/gnn_intro_pluto.jl
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,7 @@ This is done by following a simple **neural message passing scheme**, where node
57
57
```
58
58
59
59
This tutorial will introduce you to some fundamental concepts regarding deep learning on graphs via Graph Neural Networks based on the **[GraphNeuralNetworks.jl library](https://github.com/CarloLucibello/GraphNeuralNetworks.jl)**.
60
-
GNN.jl is an extension library to the popular deep learning framework [Flux.jl](https://fluxml.ai/Flux.jl/stable/), and consists of various methods and utilities to ease the implementation of Graph Neural Networks.
60
+
GraphNeuralNetworks.jl is an extension library to the popular deep learning framework [Flux.jl](https://fluxml.ai/Flux.jl/stable/), and consists of various methods and utilities to ease the implementation of Graph Neural Networks.
61
61
62
62
Let's first import the packages we need:
63
63
"""
@@ -66,7 +66,7 @@ Let's first import the packages we need:
66
66
md"""
67
67
Following [Kipf et al. (2017)](https://arxiv.org/abs/1609.02907), let's dive into the world of GNNs by looking at a simple graph-structured example, the well-known [**Zachary's karate club network**](https://en.wikipedia.org/wiki/Zachary%27s_karate_club). This graph describes a social network of 34 members of a karate club and documents links between members who interacted outside the club. Here, we are interested in detecting communities that arise from the member's interaction.
68
68
69
-
GNN.jl provides utilities to convert [MLDatasets.jl](https://github.com/JuliaML/MLDatasets.jl)'s datasets to its own type:
69
+
GraphNeuralNetworks.jl provides utilities to convert [MLDatasets.jl](https://github.com/JuliaML/MLDatasets.jl)'s datasets to its own type:
70
70
"""
71
71
72
72
# ╔═╡ 4ba372d4-7a6a-41e0-92a0-9547a78e2898
@@ -129,7 +129,7 @@ end
129
129
130
130
# ╔═╡ 1e362709-a0d0-45d5-b2fd-a91c45fa317a
131
131
md"""
132
-
Each graph in GNN.jl is represented by a `GNNGraph` object, which holds all the information to describe its graph representation.
132
+
Each graph in GraphNeuralNetworks.jl is represented by a `GNNGraph` object, which holds all the information to describe its graph representation.
133
133
We can print the data object anytime via `print(g)` to receive a short summary about its attributes and their shapes.
134
134
135
135
The `g` object holds 3 attributes:
@@ -154,13 +154,13 @@ edge_index(g)
154
154
155
155
# ╔═╡ 98bb86d2-a7b9-4110-8851-8829a9f9b4d0
156
156
md"""
157
-
By printing `edge_index(g)`, we can understand how GNN.jl represents graph connectivity internally.
157
+
By printing `edge_index(g)`, we can understand how GraphNeuralNetworks.jl represents graph connectivity internally.
158
158
We can see that for each edge, `edge_index` holds a tuple of two node indices, where the first value describes the node index of the source node and the second value describes the node index of the destination node of an edge.
159
159
160
160
This representation is known as the **COO format (coordinate format)** commonly used for representing sparse matrices.
161
-
Instead of holding the adjacency information in a dense representation ``\mathbf{A} \in \{ 0, 1 \}^{|\mathcal{V}| \times |\mathcal{V}|}``, GNN.jl represents graphs sparsely, which refers to only holding the coordinates/values for which entries in ``\mathbf{A}`` are non-zero.
161
+
Instead of holding the adjacency information in a dense representation ``\mathbf{A} \in \{ 0, 1 \}^{|\mathcal{V}| \times |\mathcal{V}|}``, GraphNeuralNetworks.jl represents graphs sparsely, which refers to only holding the coordinates/values for which entries in ``\mathbf{A}`` are non-zero.
162
162
163
-
Importantly, GNN.jl does not distinguish between directed and undirected graphs, and treats undirected graphs as a special case of directed graphs in which reverse edges exist for every entry in the edge_index.
163
+
Importantly, GraphNeuralNetworks.jl does not distinguish between directed and undirected graphs, and treats undirected graphs as a special case of directed graphs in which reverse edges exist for every entry in the edge_index.
164
164
165
165
Since a `GNNGraph` is an `AbstractGraph` from the `Graphs.jl` library, it supports graph algorithms and visualization tools from the wider julia graph ecosystem:
166
166
"""
@@ -173,7 +173,7 @@ md"""
173
173
174
174
## Implementing Graph Neural Networks
175
175
176
-
After learning about GNN.jl's data handling, it's time to implement our first Graph Neural Network!
176
+
After learning about GraphNeuralNetworks.jl's data handling, it's time to implement our first Graph Neural Network!
177
177
178
178
For this, we will use on of the most simple GNN operators, the **GCN layer** ([Kipf et al. (2017)](https://arxiv.org/abs/1609.02907)), which is defined as
179
179
@@ -183,7 +183,7 @@ For this, we will use on of the most simple GNN operators, the **GCN layer** ([K
183
183
184
184
where ``\mathbf{W}^{(\ell + 1)}`` denotes a trainable weight matrix of shape `[num_output_features, num_input_features]` and ``c_{w,v}`` refers to a fixed normalization coefficient for each edge.
185
185
186
-
GNN.jl implements this layer via `GCNConv`, which can be executed by passing in the node feature representation `x` and the COO graph connectivity representation `edge_index`.
186
+
GraphNeuralNetworks.jl implements this layer via `GCNConv`, which can be executed by passing in the node feature representation `x` and the COO graph connectivity representation `edge_index`.
187
187
188
188
With this, we are ready to create our first Graph Neural Network by defining our network architecture:
0 commit comments