http://cs224w.stanford.edu 1. Introduction to Knowledge Graphs 2. - - PowerPoint PPT Presentation

http cs224w stanford edu 1 introduction to knowledge
SMART_READER_LITE
LIVE PREVIEW

http://cs224w.stanford.edu 1. Introduction to Knowledge Graphs 2. - - PowerPoint PPT Presentation

CS224W: Machine Learning with Graphs Jure Leskovec, Hongyu Ren, Stanford University http://cs224w.stanford.edu 1. Introduction to Knowledge Graphs 2. Knowledge Graph completion 3. Path Queries 4. Conjunctive Queries 5. Query2Box: Reasoning with Box


slide-1
SLIDE 1

CS224W: Machine Learning with Graphs Jure Leskovec, Hongyu Ren, Stanford University

http://cs224w.stanford.edu

slide-2
SLIDE 2
  • 1. Introduction to Knowledge Graphs
  • 2. Knowledge Graph completion
  • 3. Path Queries
  • 4. Conjunctive Queries
  • 5. Query2Box: Reasoning with Box Embeddings

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 2

slide-3
SLIDE 3

¡ Knowledge in graph form

§ Capture entities, types, and relationships

¡ Nodes are entities ¡ Nodes are labeled with

their types

¡ Edges between two nodes

capture relationships between entities

11/21/19 3 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu

slide-4
SLIDE 4

¡ Node types: paper, title, author, conference,

year

¡ Relation types: pubWhere, pubYear, hasTitle,

hasAuthor, cite

11/21/19 4 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu

slide-5
SLIDE 5

¡ Node types: account, song, post, food, channel ¡ Relation types: friend, like, cook, watch, listen

11/21/19 5 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu

slide-6
SLIDE 6

11/21/19 6 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu

paintedBy

slide-7
SLIDE 7

¡ Google Knowledge Graph ¡ Amazon Product Graph ¡ Facebook Graph API ¡ IBM Watson ¡ Microsoft Satori ¡ Project Hanover/Literome ¡ LinkedIn Knowledge Graph ¡ Yandex Object Answer

11/21/19 7 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu

slide-8
SLIDE 8

¡ Serving information

11/21/19 8 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu

slide-9
SLIDE 9

¡ Question answering and conversation agents

11/21/19 9 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu

slide-10
SLIDE 10
  • 1. Introduction to Knowledge Graphs
  • 2. Knowledge Graph completion
  • 3. Path Queries
  • 4. Conjunctive Queries
  • 5. Query2Box: Reasoning with Box Embeddings

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 10

slide-11
SLIDE 11

¡ Publicly available KGs:

§ FreeBase, Wikidata, Dbpedia, YAGO, NELL, etc.

¡ Common characteristics:

§ Massive: millions of nodes and edges § Incomplete: many true edges are missing

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 11

Given a massive KG, enumerating all the possible facts is intractable! Can we predict plausible BUT missing links?

slide-12
SLIDE 12

¡ Freebase

§ ~50 million entities § ~38K relation types § ~3 billion facts/triples

¡ FB15k/FB15k-237

§ A complete subset of Freebase, used by researchers to learn KG models

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 12

93.8% of persons from Freebase have no place of birth and 78.5% have no nationality!

[1] Paulheim, Heiko. "Knowledge graph refinement: A survey of approaches and evaluation methods." Semantic web 8.3 (2017): 489-508. [2] Min, Bonan, et al. "Distant supervision for relation extraction with an incomplete knowledge base." Proceedings of the 2013 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies. 2013.

slide-13
SLIDE 13

¡ Given an enormous KG, can we complete the

KG / predict missing relations?

§ links + type

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 13

missing relation: genre

slide-14
SLIDE 14

¡ Edges in KG are represented as triples (ℎ, 𝑠, 𝑢)

§ head (ℎ) has relation 𝑠 with tail (𝑢).

¡ Key Idea:

§ Model entities and relations in the embedding/vector space ℝ(. § Given a true triple (ℎ, 𝑠, 𝑢), the goal is that the embedding of (ℎ, 𝑠) should be close to the embedding of 𝑢.

§ How to embed ℎ, 𝑠 ? § How to define closeness?

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 14

slide-15
SLIDE 15

¡ Symmetric Relations:

𝑠 ℎ, 𝑢 ⇒ 𝑠 𝑢, ℎ ∀ℎ, 𝑢

§ Example: Family, Roommate

¡ Composition Relations:

𝑠

+ 𝑦, 𝑧 ∧ 𝑠 / 𝑧, 𝑨 ⇒ 𝑠 1 𝑦, 𝑨

∀𝑦, 𝑧, 𝑨

§ Example: My mother’s husband is my father.

¡ 1-to-N, N-to-1 relations:

𝑠 ℎ, 𝑢+ , 𝑠 ℎ, 𝑢/ , … , 𝑠(ℎ, 𝑢3) are all True.

§ Example: 𝑠 is “StudentsOf”

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 15

slide-16
SLIDE 16

¡ Translation Intuition:

For a triple (ℎ, 𝑠, 𝑢), 𝐢, 𝐬, 𝐮 ∈ ℝ(, 𝐢 + 𝐬 = 𝐮 Score function: 𝑔

; ℎ, 𝑢 = ||ℎ + 𝑠 − 𝑢||

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 16

𝐢 𝐮 𝐬

Obama Nationality American

Bordes, Antoine, et al. "Translating embeddings for modeling multi-relational data." Advances in neural information processing systems. 2013.

NOTATION: embedding vectors will appear in boldface

slide-17
SLIDE 17

¡ Translation Intuition: for a triple (ℎ, 𝑠, 𝑢),

𝐢 + 𝐬 = 𝐮 Max margin loss:

ℒ = ?

(@,;,A)∈B,(@,;,AC)∉B

𝛿 + 𝑔

;(ℎ, 𝑢) − 𝑔 ;(ℎ, 𝑢F) G

where 𝛿 is the margin, i.e., the smallest distance tolerated by the model between a valid triple and a corrupted one.

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 17

Valid triple Corrupted triple NOTE: check lecture 7 for a more in-depth discussion

  • f TransE!
slide-18
SLIDE 18

¡ Who has won the Turing award? ¡ Who is a Canadian citizen?

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 18

Win

Hinton Bengio Pearl Turing Award Canada Trudeau Bieber

𝐫

Answers!

Hinton Bengio Pearl Turing Award Canada

Citizen

Trudeau Bieber

Answers!

𝐫

slide-19
SLIDE 19

¡ Composition Relations:

𝑠

+ 𝑦, 𝑧 ∧ 𝑠 / 𝑧, 𝑨 ⇒ 𝑠 1 𝑦, 𝑨

∀𝑦, 𝑧, 𝑨

¡ Example: My mother’s husband is my father. ¡ In TransE:

𝑠

1 = 𝑠 + + 𝑠 / ü

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 19

𝐲 𝐬+ 𝐬/ 𝐬1 𝐳 𝐴

slide-20
SLIDE 20

¡ Symmetric Relations:

𝑠 ℎ, 𝑢 ⇒ 𝑠 𝑢, ℎ ∀ℎ, 𝑢

¡ Example: Family, Roommate ¡ In TransE:

𝑠 = 0, ℎ = 𝑢 û

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 20

𝐢 𝐮 𝐬

If we want TransE to handle symmetric relations 𝑠, for all ℎ, 𝑢 that satisfy 𝑠(ℎ, 𝑢), 𝑠(𝑢, ℎ) is also True, which means ‖ ‖ ℎ + 𝑠 − 𝑢 = 0 and 𝑢 + 𝑠 − ℎ = 0. Then 𝑠 = 0 and ℎ = 𝑢, however ℎ and 𝑢 are two different entities and should be mapped to different locations.

slide-21
SLIDE 21

¡ 1-to-N, N-to-1, N-to-N relations. ¡ Example: (ℎ, 𝑠, 𝑢+) and (ℎ, 𝑠, 𝑢/) both exist in

the knowledge graph, e.g., 𝑠 is “StudentsOf” With TransE, 𝑢+ and 𝑢/ will map to the same vector, although they are different entities.

¡ 𝐮+ = 𝐢 + 𝐬 = 𝐮/ ¡ 𝐮+ ≠ 𝐮/

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 21

𝐢 𝐮+ 𝐮/ 𝐬 𝐬

contradictory!

slide-22
SLIDE 22

¡ TransR: model entities as vectors in the entity

space ℝ( and model each relation as vector 𝒔 in relation space ℝP with 𝐍; ∈ ℝP×( as the projection matrix.

¡ ℎS = 𝑁;ℎ, 𝑢S = 𝑁;𝑢 ¡ 𝑔

; ℎ, 𝑢 = ||ℎS + 𝑠 − 𝑢S||

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 22

𝐢 𝐢S 𝐮S 𝐮 𝐬

Lin, Yankai, et al. "Learning entity and relation embeddings for knowledge graph completion." AAAI. 2015.

slide-23
SLIDE 23

¡ Symmetric Relations:

𝑠 ℎ, 𝑢 ⇒ 𝑠 𝑢, ℎ ∀ℎ, 𝑢

¡ Example: Family, Roommate

𝑠 = 0, ℎS = 𝑁;ℎ = 𝑁;𝑢 = 𝑢Sü

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 23

𝐢 𝐮S, ℎS 𝐮 𝑵;

For TransR, we can map ℎ and 𝑢 to the same location on the space of relation 𝑠.

slide-24
SLIDE 24

¡ 1-to-N, N-to-1, N-to-N relations ¡ Example: If (ℎ, 𝑠, 𝑢+) and (ℎ, 𝑠, 𝑢/) exist in the

knowledge graph. We can learn 𝑁; so that 𝑢S = 𝑁;𝑢+ = 𝑁;𝑢/, note

that 𝑢+ does not need to be equal to 𝑢/!

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 24

𝐢 𝐢S 𝐮S 𝐮+ 𝐮/ 𝐬

slide-25
SLIDE 25

¡ Composition Relations:

𝑠

+ 𝑦, 𝑧 ∧ 𝑠 / 𝑧, 𝑨 ⇒ 𝑠 1 𝑦, 𝑨

∀𝑦, 𝑧, 𝑨

¡ Example: My mother’s husband is my father.

Each relation has different space. It is not naturally compositional for multiple relations! û

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 25

slide-26
SLIDE 26

Embedding Entity Relation 𝒈𝒔(𝒊, 𝒖) TransE ℎ, 𝑢 ∈ ℝ( 𝑠 ∈ ℝ( ||ℎ + 𝑠 − 𝑢|| TransR ℎ, 𝑢 ∈ ℝ( 𝑠 ∈ ℝP, 𝑁; ∈ ℝP×( ||𝑁;ℎ + 𝑠 − 𝑁;𝑢||

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 26

Embedding Symmetry Composition One-to-many TransE û ü û TransR ü û ü

slide-27
SLIDE 27
  • 1. Introduction to Knowledge Graphs
  • 2. Knowledge Graph completion
  • 3. Path Queries
  • 4. Conjunctive Queries
  • 5. Query2Box: Reasoning with Box Embeddings

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 27

slide-28
SLIDE 28

¡ Can we do multi-hop reasoning, i.e., answer

complex queries efficiently on an incomplete, massive KG?

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 28

Query Types Examples One-hop Queries Where did Hinton graduate? Path Queries Where did Turing Award winners graduate? Conjunctive Queries Where did Canadians with Turing Award graduate? EPFO Queries Where did Canadians with Turing Award or Nobel graduate?

slide-29
SLIDE 29

¡ We can formulate link prediction problems as

answering one-hop queries.

¡ Link prediction: Is link (ℎ, 𝑠, 𝑢) True? ¡ One-hop query: Is 𝑢 an answer to query (ℎ, 𝑠)?

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 29

slide-30
SLIDE 30

¡ Generalize one-hop queries to path queries by

adding more relations on the path.

¡ Path queries can be represented by

𝑟 = 𝑤\, 𝑠

+, … , 𝑠 3

𝑤\ is a constant node, answers are denoted by 𝑟 . Computation graph of 𝑟: Computation graph of path queries is a chain.

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 30

𝑊

?

𝑤\ 𝑠

+

𝑠/ 𝑠

3

slide-31
SLIDE 31

“Where did Turing Award winners graduate?”

¡ 𝑤\ is “Turing Award”. ¡ 𝑠

+, 𝑠 / is (“win”, “graduate”).

Given a KG, how to answer the query?

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 31

Win Graduate

𝑊 𝑊

? Turing Award

slide-32
SLIDE 32

¡ Answer path queries by traversing the KG.

“Where did Turing Award winners graduate?”

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 32

Turing Award The anchor node is Turing Award.

slide-33
SLIDE 33

¡ Answer path queries by traversing the KG.

“Where did Turing Award winners graduate?”

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 33

Turing Award

Win

Pearl Hinton Bengio Start from the anchor node “Turing Award” and traverse the KG by the relation “Win”, we reach entities {“Pearl”, “Hinton”, “Bengio”}.

slide-34
SLIDE 34

¡ Answer path queries by traversing the KG.

“Where did Turing Award winners graduate?”

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 34

Turing Award

Win

Pearl

Graduate Edinburgh

Hinton McGill Bengio Cambridge NYU Answers! Start from nodes {“Pearl”, “Hinton”, “Bengio”} and traverse the KG by the relation “Graduate”, we reach entities {“NYU”, “Edinburgh”, “Cambridge”, “McGill”}. These are the answers to the query!

slide-35
SLIDE 35

¡ Answer path queries by traversing the KG.

“Where did Turing Award winners graduate?” What if KG is incomplete?

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 35

Turing Award

Win

Pearl

Graduate Edinburgh

Hinton McGill Bengio Cambridge NYU Answers!

slide-36
SLIDE 36

¡ Can we first do link prediction and then

traverse the completed (probabilistic) KG?

¡ No! The completed KG is a dense graph! ¡ Time complexity of traversing a dense KG with

𝑊 entities to answer (𝑤\, 𝑠

+, … , 𝑠 3) of length

𝑜 is 𝒫 𝑊 3 .

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 36

𝑠/ 𝑤\ 𝑠

+

𝑤+ 𝑤/ 𝑤|b| … 𝑤/ 𝑤|b| … 𝑤+ … …

slide-37
SLIDE 37

¡ Key idea: embed queries!

§ Generalize TransE to multi-hop reasoning.

Given a path query 𝑟 = 𝑤\, 𝑠

+, … , 𝑠 3 ,

𝐫 = 𝐰\ + 𝐬+ + ⋯ + 𝐬3

¡ Is 𝑤 an answer to 𝑟?

§ Do a nearest neighbor search for all 𝑤 based on 𝑔

e 𝑤 = ||𝐫 − 𝐰||, time complexity is 𝒫(𝑊).

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 37

𝐰𝒃 𝐫 𝐬+ 𝐬/ 𝐬3

Guu, Kelvin, John Miller, and Percy Liang. "Traversing knowledge graphs in vector space." arXiv preprint arXiv:1506.01094 (2015).

slide-38
SLIDE 38

¡ Embed path queries in vector space.

“Where did Turing Award winners graduate?” Follow the computation graph:

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 38

Turing Award

Computation Graph

Turing Award

Embedding Space

slide-39
SLIDE 39

¡ Embed path queries in vector space.

“Where did Turing Award winners graduate?” Follow the computation graph:

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 39

Turing Award

Projection

Computation Graph

Win

Bengio Pearl Turing Award

Embedding Space

Hinton

slide-40
SLIDE 40

¡ Embed path queries in vector space.

“Where did Turing Award winners graduate?” Follow the computation graph:

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 40

Turing Award

Projection Projection

Computation Graph

Win

NYU Hinton Bengio Pearl

Graduate

McGill Edinburgh Cambridge Turing Award

Embedding Process

𝐫

Answers!

slide-41
SLIDE 41
  • 1. Introduction to Knowledge Graphs
  • 2. Link Prediction
  • 3. Path Queries
  • 4. Conjunctive Queries
  • 5. Query2Box: Reasoning with Box Embeddings

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 41

slide-42
SLIDE 42

¡ Can we answer more complex queries? ¡ What if we start from multiple anchor nodes?

“Where did Canadian citizens with Turing Award graduate?”

Computation graph of 𝑟:

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 42

Turing Award Canada Projection Projection Projection Intersection Intersection

slide-43
SLIDE 43

¡ Can we answer even more complex queries?

“Where did Canadian citizens with Turing Award graduate?” Two anchor nodes: Canada and Turing Award.

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 43

Turing Award

Win

Pearl Hinton Bengio

Start from the first anchor node “Turing Award”, and traverse by relation “Win”, we reach {“Pearl”, “Hinton”, “Bengio”} .

slide-44
SLIDE 44

¡ Can we answer even more complex queries?

“Where did Canadian citizens with Turing Award graduate?” Two anchor nodes: Canada and Turing Award.

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 44

Turing Award

Win

Canada

Citizen

Pearl Hinton Bieber Bengio Trudeau

Start from the second anchor node “Canada”, and traverse by relation “citizen”, we reach { “Hinton”, “Bengio”, “Bieber”, “Trudeau”}

slide-45
SLIDE 45

¡ Can we answer even more complex queries?

“Where did Canadian citizens with Turing Award graduate?” Two anchor nodes: Canada and Turing Award.

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 45

Turing Award

Win

Canada

Citizen

Pearl Hinton Bieber Bengio Trudeau

Then, we take intersection of the two sets and achieve {‘Hinton’, ‘Bengio’}

slide-46
SLIDE 46

¡ Can we answer even more complex queries?

“Where did Canadian citizens with Turing Award graduate?” Two anchor nodes: Canada and Turing Award.

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 46

Turing Award

Win

Canada

Citizen

Pearl

Graduate

Edinburgh Hinton McGill Bieber Bengio Trudeau Cambridge

We do another traverse and arrive at the answers!

slide-47
SLIDE 47

¡ Key Idea: embed queries in vector space

“Where did Canadian citizens with Turing Award graduate?”

Follow the computation graph:

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 47

Computation Graph Embedding Space

Turing Award Canada

Projection Projection Win

Hinton Bengio Pearl Turing Award Canada

Citizen

Trudeau Bieber

𝐫+ 𝐫/

slide-48
SLIDE 48

¡ Key Idea: embed queries in vector space

“Where did Canadian citizens with Turing Award graduate?”

Follow the computation graph:

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 48

Computation Graph Embedding Process

Win

Hinton Bengio Pearl Turing Award Canada

Citizen

Trudeau Bieber Turing Award Canada

Projection Projection Intersection Intersection

?

𝐫+ 𝐫/

slide-49
SLIDE 49

¡ How do we take intersection of several

vectors in the embedding space?

¡ Design a neural intersection operator ℐ

§ Input: current query embeddings 𝐫+, … , 𝐫h § Output: intersection query embedding 𝐫 § ℐ should be permutation invariant: ℐ 𝐫+, … , 𝐫h = ℐ(𝐫i + , … , 𝐫i(h)) [𝑞 1 , … , 𝑞 𝑛 ] is any permutation of [1, … , 𝑛]

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 49

slide-50
SLIDE 50

¡ DeepSets architecture

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 50

𝐫+ 𝐫/ …𝐫h

𝜚

mean

𝛾

𝐫 Permutation Invariant Vector embeddings

  • f the input queries

Features of the input queries 𝜚(𝐫+) 𝜚(𝐫h) Vector embedding of the intersection query

slide-51
SLIDE 51

¡ Key Idea: embed queries in vector space

“Where did Canadian citizens with Turing Award graduate?”

Follow the computation graph:

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 51

Computation Graph Embedding Space

Win

Hinton Bengio Pearl Turing Award Canada

Citizen

NYU

Graduate

McGill Edinburgh Cambridge

𝐫 𝐫 = ℐ(𝐫+, 𝐫/)

Turing Award Canada

Projection Projection Projection Intersection Intersection

Trudeau Bieber

𝐫/ 𝐫+

Answers!

slide-52
SLIDE 52

¡ Given an entity embedding 𝐰 and a query

embedding 𝐫, the distance is 𝑔

e 𝑤 = ||𝐫 − 𝐰||.

¡ Trainable parameters:

§ entity embeddings: 𝑒 𝑊 § relation embeddings: 𝑒 𝑆 § intersection operator 𝜚, 𝛾: number of parameters does not depend on graph size

¡ Same training strategy as TransE

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 52

slide-53
SLIDE 53

¡ Training:

  • 1. Sample a query 𝑟, answer 𝑤, negative sample 𝑤′.
  • 2. Embed the query 𝐫.
  • 3. Calculate the distance 𝑔

e(𝑤) and 𝑔 e(𝑤F).

  • 4. Optimize the loss ℒ.

¡ Query evaluation:

  • 1. Given a test query 𝑟, embed the query 𝐫.
  • 2. For all 𝑤 in KG, calculate 𝑔

e(𝑤).

  • 3. Sort the distance and rank all 𝑤.

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 53

slide-54
SLIDE 54

¡ Taking the intersection between two vectors

is an operation that does not follow intuition.

¡ When we traverse the KG to achieve the

answers, each step produces a set of reachable entities. How can we better model these sets?

¡ Can we define a more expressive geometry to

embed the queries?

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 54

slide-55
SLIDE 55
  • 1. Introduction to Knowledge Graphs
  • 2. Knowledge Graph completion
  • 3. Path Queries
  • 4. Conjunctive Queries
  • 5. Query2Box: Reasoning with Box Embeddings

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 55

slide-56
SLIDE 56

¡ Embed queries with hyper-rectangles (boxes)

𝐫 = (𝐷𝑓𝑜𝑢𝑓𝑠 𝑟 , 𝑃𝑔𝑔𝑡𝑓𝑢(𝑟))

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 56

Edinburgh

𝑟

McGill Cambridge Stanford

Embedding Space

slide-57
SLIDE 57

¡ Taking intersection between two vectors is an

  • peration that does not follow intuition.

§ Intersection of boxes is well-defined!

¡ When we traverse the KG to achieve the

answers, each step produces a set of reachable entities. How can we better model these sets?

§ Boxes are a powerful abstraction, as we can project the center and control the offset to model the set of entities enclosed in the box.

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 57

slide-58
SLIDE 58

¡ Parameters: § entity embeddings: 𝑒 𝑊

§ entities are seen as zero-volume boxes

§ relation embeddings: 2𝑒 𝑆

§ augment each relation with an offset

§ intersection operator 𝜚, 𝛾: number of parameters does not depend on graph size

§ New operator, inputs are boxes and output is a box

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 58

slide-59
SLIDE 59

¡ Embed queries in vector space

“Where did Canadian citizens with Turing Award graduate?” Note that computation graph stays the same!

Follow the computation graph:

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 59

Computation Graph

Turing Award Canada Canada Turing Award

Embedding Space

slide-60
SLIDE 60

¡ Embed queries in vector space

“Where did Canadian citizens with Turing Award graduate?” Note that computation graph stays the same!

Follow the computation graph:

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 60

Computation Graph

Turing Award Canada

Projection Projection

Canada Turing Award

Embedding Process

?

slide-61
SLIDE 61

¡ Geometric Projection Operator 𝒬 ¡ 𝒬 : Box × Relation → Box

𝐷𝑓𝑜 𝑟F = 𝐷𝑓𝑜 𝑟 + 𝐷𝑓𝑜 𝑠 𝑃𝑔𝑔 𝑟F = 𝑃𝑔𝑔 𝑟 + 𝑃𝑔𝑔(𝑠)

Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 61

𝑟 𝑟′ 𝑠

11/21/19

slide-62
SLIDE 62

¡ Embed queries in vector space

“Where did Canadian citizens with Turing Award graduate?” Note that computation graph stays the same!

Follow the computation graph:

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 62

Computation Graph

Turing Award Canada

Projection Projection Win Citizen

Trudeau Hinton Bengio Pearl Canada Bieber Turing Award

Embedding Space

slide-63
SLIDE 63

¡ Embed queries in vector space

“Where did Canadian citizens with Turing Award graduate?” Note that computation graph stays the same!

Follow the computation graph:

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 63

Computation Graph

Turing Award Canada

Projection Projection Intersection Intersection

Embedding Space

?

Win Citizen

Trudeau Hinton Bengio Pearl Canada Bieber Turing Award

slide-64
SLIDE 64

¡ Geometric Intersection Operator ℐ ¡ ℐ : Box × ⋯× Box → Box

§ The new center is a weighted average. § The new offset shrinks.

Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 64 11/21/19

slide-65
SLIDE 65

¡ Geometric Intersection Operator ℐ ¡ ℐ : Box × ⋯× Box → Box

𝐷𝑓𝑜 𝑟{3A|; = ?

{

𝒙{ ⊙ 𝐷𝑓𝑜 𝑟{ 𝑃𝑔𝑔 𝑟{3A|; = min 𝑃𝑔𝑔 𝑟+ , … , 𝑃𝑔𝑔 𝑟3 ⊙ 𝜏(𝐸𝑓𝑓𝑞𝑡𝑓𝑢𝑡(𝐫+, … , 𝐫3))

Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 65

weight guarantees shrinking Sigmoid function: squashes output in (0,1) dimension-wise product

11/21/19

slide-66
SLIDE 66

¡ Embed queries in vector space

“Where did Canadian citizens with Turing Award graduate?” Note that computation graph stays the same!

Follow the computation graph:

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 66

Computation Graph

Turing Award Canada

Projection Projection Intersection Intersection Win Citizen

Trudeau Hinton Bengio Pearl Canada Bieber Turing Award

Embedding Space

slide-67
SLIDE 67

¡ Embed queries in vector space

“Where did Canadian citizens with Turing Award graduate?” Note that computation graph stays the same!

Follow the computation graph:

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 67

Computation Graph

Turing Award Canada

Projection Projection Projection Intersection Intersection Win Citizen

Trudeau Hinton Bengio Pearl

Graduate

McGill Edinburgh Canada Bieber Cambridge Turing Award

Embedding Space

NYU

slide-68
SLIDE 68

¡ Given a query box 𝐫 and entity vector 𝐰,

𝑒„…† 𝐫, 𝐰 = 𝑒…‡A 𝐫, 𝐰 + 𝛽 ⋅ 𝑒{3(𝐫, 𝐰) where 0 < 𝛽 < 1.

Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 68

𝑒…‡A(𝐫, 𝐰) 𝑒{3(𝐫, 𝐰) 𝑤 𝐷𝑓𝑜(𝑟)

11/21/19

slide-69
SLIDE 69

¡ Given a set of queries and answers,

ℒ = − log 𝜏 𝛿 − 𝑒„…† 𝑟, 𝑤 − log 𝜏(𝑒„…† 𝑟, 𝑤{

F − 𝛿)

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 69

𝛿 𝛿 − log 𝜏 𝛿 − 𝑒„…† 𝑟, 𝑤 minimize loss → minimize 𝑒„…†(𝑟, 𝑤) − log 𝜏 𝑒„…† 𝑟, 𝑤′ − 𝛿 minimize loss → maximize 𝑒„…†(𝑟, 𝑤′)

slide-70
SLIDE 70

¡ Can query2box handle different relation

patterns?

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 70

Embedding Symmetry Composition One-to-many TransE û ü û TransH ü û ü Query2Box ü ü ü For details please check the paper https://openreview.net/forum?id=BJgr4kSFDS

slide-71
SLIDE 71

¡ 1-to-N, N-to-1, N-to-N relations. ¡ Example: Both (ℎ, 𝑠, 𝑢+) and (ℎ, 𝑠, 𝑢/) exist. ¡ Box Embedding can handle since 𝑢+ and 𝑢/ will

be mapped to different locations in the box of (ℎ, 𝑠). ü

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 71

𝐢 𝐮+ 𝐮/ 𝐢 + 𝐬

slide-72
SLIDE 72

¡ Symmetric Relations:

𝑠 ℎ, 𝑢 ⇒ 𝑠 𝑢, ℎ ∀ℎ, 𝑢

¡ Example: Family, Roommate ¡ Box Embedding

𝐷𝑓𝑜 𝑠 = 0 ü

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 72

𝐢 𝐮 𝐢 + 𝐬

For symmetric relations 𝑠, we could assign 𝐷𝑓𝑜 𝑠 = 0. In this case, as long as 𝑢 is in the box of (ℎ, 𝑠), it is guaranteed that ℎ is in the box of (𝑢, 𝑠). So we have 𝑠(ℎ, 𝑢) ⇒ 𝑠(𝑢, ℎ)

𝐮 + 𝐬

slide-73
SLIDE 73

¡ Composition Relations:

𝑠

+ 𝑦, 𝑧 ∧ 𝑠 / 𝑧, 𝑨 ⇒ 𝑠 1 𝑦, 𝑨

∀𝑦, 𝑧, 𝑨

¡ Example: My mother’s husband is my father. ¡ Box Embedding

𝐬1 = 𝐬+ + 𝐬/ ü

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 73

𝐲 𝐬1 𝐳 𝐴 𝐲 + 𝐬𝟐 𝐳 + 𝐬𝟑 𝐲 + 𝐬𝟐 + 𝐬𝟑

For composition relations, if 𝑧 is in the box of (𝑦, 𝑠

+) and 𝑨 is in the box of (𝑧, 𝑠/), it is

guaranteed that 𝑨 is in the box of (𝑦, 𝑠

+ + 𝑠/).

slide-74
SLIDE 74

¡ Can we embed even more complex queries?

“Where did Canadians with Turing Award or Nobel graduate?”

¡ Conjunctive queries + disjunction is called

Existential Positive First-order (EPFO) queries.

¡ Can we also design a disjunction operator and

embed EPFO queries in low-dimensional vector space? YES!

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 74

For details please check the paper https://openreview.net/forum?id=BJgr4kSFDS

slide-75
SLIDE 75

¡ Datasets: FB15K, FB15K-237 ¡ Goal: can the model discover true answers that

cannot be achieved by traversing the KG?

§ Training KG: Training Edges § Validation KG: Training Edges + Validation Edges § Test KG: Training Edges + Validation Edges + Test Edges

¡ Queries:

Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 89

3i 2i 3p 2p 1p Training Conjunctive Queries ip pi Unseen Conjunctive Queries

u u u u

2u up Union Queries

11/21/19

slide-76
SLIDE 76

¡ Given a query structure, use pre-order traversal (traverse

from root to leaves) to assign an entity/relation for every node/edge.

¡ We explicitly rule out degenerated queries.

Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 90

root leaf leaf

𝒔 𝒔•𝟐

𝑊 𝑊

?

𝑤\

𝒔 𝒔

𝑤\ 𝑤\ 𝑊

?

11/21/19

slide-77
SLIDE 77

¡ After instantiation, run post-order traversal (traverse

from leaves 𝑤+, 𝑤/ to root) to achieve all answers.

¡ For test queries, we guarantee that they cannot be fully

answered on training/validation KG.

Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 91

𝑤+ 𝑤/ 𝑠

+

𝑠/ 𝑠1

root

11/21/19

slide-78
SLIDE 78

Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 92

3i 2i 3p 2p 1p Training Conjunctive Queries ip pi Unseen Conjunctive Queries

u u u u

2u up Union Queries

11/21/19

slide-79
SLIDE 79

¡ What does query2box actually learn?

Example: “List male instrumentalists who play string instruments”

¡ We use T-SNE to reduce the embedding space

to a 2-dimensional space, in order to visualize the query results

11/21/19 Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 93

slide-80
SLIDE 80

Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 94

“List male instrumentalists who play string instruments”

String Instrument Male

Projection Projection Projection Intersection Intersection

Embedding of 14951 entities

11/21/19

slide-81
SLIDE 81

Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 95

Anchor

“List male instrumentalists who play string instruments”

String Instrument

11/21/19

slide-82
SLIDE 82

Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 96

TP FP TN FN

“List male instrumentalists who play string instruments”

String Instrument

Projection

TPR: 100% FPR: 0% # of string instruments: 10

11/21/19

slide-83
SLIDE 83

Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 97

TP FP TN FN

“List male instrumentalists who play string instruments”

String Instrument

Projection Projection

# of instrumentalists: 472 TPR: 98.4% FPR: 0.01%

11/21/19

slide-84
SLIDE 84

Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 98

“List male instrumentalists who play string instruments”

Male

Anchor

11/21/19

slide-85
SLIDE 85

Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 99

TP FP TN FN

Male

Projection

TPR: 97.9% FPR: 0.01%

“List male instrumentalists who play string instruments”

# of men: 3555

11/21/19

slide-86
SLIDE 86

Jure Leskovec, Stanford CS224W: Machine Learning with Graphs, http://cs224w.stanford.edu 100

TP FP TN FN

String Instrument Male

Projection Projection Projection Intersection Intersection

“List male instrumentalists who play string instruments”

# of answers: 396 TPR: 99.4% FPR: 0.01%

11/21/19