Graph Neural Network Introduction
Graph Neural Network Introduction
material useful for giving your own lectures. Feel free to use these slides verbatim, or to modify
them to fit your own needs. If you make use of a significant portion of these slides in your own
lecture, please include this message, or a link to our web site: http://cs224w.Stanford.edu
Text/Speech
vs.
Text
Networks Images
No fixed node ordering or reference point
Often dynamic and have multimodal features
2/16/2023 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs 14
How can we develop neural networks
that are much more broadly
applicable?
Graphs are the new frontier
of deep learning
2/16/2023 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs 15
…
z
Thu, 2/2 8. Knowledge Graph Embeddings Thu, 3/9 17. Guest lecture: TBD
9. Reasoning over
Tue, 2/7 Tue, 3/14 18. GNNs for Science
KnowledgeGraphs
10. Frequent Subgraph Mining with
Thu, 2/9 Thu, 3/16 19. Special topics in GNNs
GNNs
Graph-level
Community
prediction,
(subgraph)
Graph
level
generation
Edge-level
Spatial graph
2/16/2023 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs 32
Users interacts with items
▪ Watch movies, buy merchandise, listen to music
▪ Nodes: Users and items
▪ Edges: User-item interactions
Goal: Recommend items users might like
Users
Interactions
2/16/2023 Jure Les kovec, Stanford CS224W: Ma chine Learning with Graphs 8
Prescribed
Many patients take multiple drugsDrug
to treat
drugs side effect
complex or co-existing diseases:
46% of people ages 70-79 take more than 5 drugs
Many patients take more than 20 drugs to treat
heart disease, depression, insomnia, etc.
Task: Given a pair of drugs predict
adverse side effects
30%
, 65%
2/16/2023 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs
prob. prob. 36
Zitnik et al., Modeling Polypharmacy Side Effects with Graph Convolutional Networks, Bioinformatics 2018
Stokes, Jonathan M., et al. "A deep learning approach to antibiotic discovery."
Cell 180.4 (2020): 688-702.
Use case 1: Generate novel molecules Use case 2: Optimize existing molecules to
with high Drug likeness value have desirable properties
Drug likeness
2/16/2023 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs 46
Sanchez-Gonzalez et al., Learning to simulate complex physics with graph networks, ICML 2020
Actor 3 Albert
Protein 1 Protein 2
Protein 5
Protein 9 |N|=4
|E|=4
2/16/2023 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs 52
If you connect individuals that work
with each other, you will explore a
professional network Image credit: Euro Scientists
Examples: Examples:
▪ Collaborations ▪ Phone calls
▪ Friendship on Facebook ▪ Following on Twitter
2/16/2023 Jure Les kovec, Stanford CS224W: Ma chine Learning with Graphs 55
A heterogeneous graph is defined as
𝑮 = 𝑽, 𝑬, 𝑹, 𝑻
▪ Nodes with node types 𝑣𝑖 ∈ 𝑉
▪ Edges with relation types 𝑣𝑖 , 𝑟, 𝑣𝑗 ∈ 𝐸
▪ Node type 𝑇 𝑣𝑖
▪ Relation type 𝑟 ∈ 𝑅
2/16/2023 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 56
Biomedical Knowledge Graphs Academic Graphs
Example node: Migraine Example node: ICML
Example edge: (fulvestrant, Treats, Breast Neoplasms) Example edge: (GraphSAGE, NeurIPS)
Example node type: Protein Example node type: Author
Example edge type (relation): Causes Example edge type (relation): pubYear
2/16/2023 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 57
Node degree, ki: the number
Undirected
C
The (total) degree of a node is the
G
E sum of in- and out-degrees.
kCin = 2 kCout = 1 kC = 3
A
E
Source: Node with kin = 0 k= k in = k out
Sink: Node with kout = 0 N
2/16/2023 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs 58
A
Bipartite graph is a graph whose nodes can
be divided into two disjoint sets U and V such that
B
every link connects a node in U to one in V; that is,
U and V are independent sets
C
Examples: D
▪ Authors-to-Papers (they authored)
E
▪ Actors-to-Movies (they appeared in)
U V
▪ Users-to-Movies (they rated)
▪ Recipes-to-Ingredients (they contain)
“Folded” networks:
▪ Author collaboration networks
▪ Movie co-rating networks
2/16/2023 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs 59
4
4
3
3
2
2 1
1
0 1 0 1 0 0 0 1
1 0 0 1 1 0 0 0
A= A=
0 0 0 1 0 0 0 0
1 0 0 0
1 1 1 1
Note that for a directed graph (right) the matrix is not symmetric.
2/16/2023 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs 60
2/16/2023 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs 61
Most real-world networks are sparse
E << Emax (or k << N-1)
2 2
3 3
0 1 1 0 0 2 0.5 0
1 0 1 1 2 0 1 4
Aij = Aij =
1 1 0 0 0.5 1 0 0
0 1 0 0 0 4 0 0
Aii = 0 Aij = A ji Aii = 0 Aij = A ji
1 N 1 N 2E
E = å Aij k=
2E
E = nonzero( Aij ) k=
2 i, j=1 N 2 i , j =1 N
Examples: Friendship, Hyperlink Examples: Collaboration, Internet, Roads
2/16/2023 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs 64
Self-edges (self-loops) Multigraph
(undirected) (undirected)
4 4
1 1
2 2
3 3
1 1 1 0 0 2 1 0
1 0 1 1 2 0 1 3
Aij = Aij =
1 1 0 0 1 1 0 0
0 1 0 1 0 3 0 0
H H
G G
D E C
D C G
F
G SCC
SCC
2/16/2023 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 86
Colabs 0 and 1 will be released on our course
website at 3pm Thursday (1/12)
Colab 0:
▪ Does not need to be handed-in
Colab 1:
▪ Due on Thursday 10/07 (2 weeks from today)
▪ Submit written answers and code on Gradescope
▪ Will cover material from Lectures 1-4, but you
can get started right away!
2/16/2023 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 87