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
{{ message }}
This repository was archived by the owner on Nov 18, 2023. It is now read-only.
* Upgrading to use Grakn commit 760c46dc1f19d572c2abaa61fc5a16bf4ced4312
* Upgrades kglib to use Grakn commit 760c46dc1f19d572c2abaa61fc5a16bf4ced4312, mostly requiring syntax changes and the temporary lack of limits to query result length
* Minor changes to printing confusion matrices and properly passes attribute label values
* Improves READMEs
* Fix for label_extraction_test
This repository is the centre of all research projects conducted at Grakn Labs. In particular, it's focus is on the integration of machine learning with the Grakn knowledge graph.
3
3
4
-
Our first project is on [*Knowledge Graph Convolutional Networks* (KGCNs)](/kglib/kgcn).
4
+
At present this repo contains one project: [*Knowledge Graph Convolutional Networks* (KGCNs)](/kglib/kgcn).
Copy file name to clipboardExpand all lines: kglib/kgcn/README.md
+19-16Lines changed: 19 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,45 +1,48 @@
1
1
# Knowledge Graph Convolutional Networks (KGCNs)
2
2
3
-
This project introduces a novel model: the Knowledge Graph Convolutional Network. The principal idea of this work is to build a bridge between knowledge graphs and machine learning. KGCNs can be used to create vector representations or *embeddings* of any labelled set of Grakn concepts. As a result, a KGCN can be trained directly for the classification or regression of Concepts stored in Grakn. Future work will include building embeddings via unsupervised learning.
3
+
This project introduces a novel model: the *Knowledge Graph Convolutional Network* (KGCN). The principal idea of this work is to forge a bridge between knowledge graphs and machine learning, using [Grakn](https://github.com/graknlabs/grakn) as the knowledge graph. A KGCN can be used to create vector representations, *embeddings*, of any labelled set of Grakn Concepts via supervised learning. As a result, a KGCN can be trained directly for the classification or regression of Concepts stored in Grakn. Future work will include building embeddings via unsupervised learning.
4
4
5
5
6
6
7
7
## Methodology
8
8
9
-
The ideology behind this project is described [here](https://blog.grakn.ai/knowledge-graph-convolutional-networks-machine-learning-over-reasoned-knowledge-9eb5ce5e0f68). The principles of the implementation are based on [GraphSAGE](http://snap.stanford.edu/graphsage/), from the Stanford SNAP group, made to work over a **knowledge graph**. Instead of working on a typical property graph, a KGCN learns from the context of a *typed hypergraph*, Grakn. Additionally, it learns from facts deduced by Grakn's *automated logical reasoner*. From this point on some understanding of [Grakn's docs](http://dev.grakn.ai) is assumed.
9
+
The ideology behind this project is described [here](https://blog.grakn.ai/knowledge-graph-convolutional-networks-machine-learning-over-reasoned-knowledge-9eb5ce5e0f68). The principles of the implementation are based on [GraphSAGE](http://snap.stanford.edu/graphsage/), from the Stanford SNAP group, made to work over a **knowledge graph**. Instead of working on a typical property graph, a KGCN learns from the context of a *typed hypergraph*, **Grakn**. Additionally, it learns from facts deduced by Grakn's *automated logical reasoner*. From this point onwards some understanding of [Grakn's docs](http://dev.grakn.ai) is assumed.
10
10
11
-
#### How does a KGCN work?
11
+
#### How do KGCNs work?
12
12
13
-
The purpose of this method is to derive embeddings for a set of Concepts (and thereby directly learn to classify them). We start by querying Grakn to find a set of examples with labels. Following that, we gather data about the neighbourhood of each example Concept. We do this by considering their *k-hop* neighbours.
13
+
The purpose of this method is to derive embeddings for a set of Concepts (and thereby directly learn to classify them). We start by querying Grakn to find a set of labelled examples. Following that, we gather data about the neighbourhood of each example Concept. We do this by considering their *k-hop* neighbours.
14
14
15
-
We retrieve the data concerning this neighbourhood from Grakn. This includes information on the *types*, *roles*, and *attribute* values of each neighbour encountered.
15
+
We retrieve the data concerning this neighbourhood from Grakn. This information includes the *type hierarchy*, *roles*, and *attribute* values of each neighbouring Concept encountered.
16
16
17
-
To create embeddings, we build a network in TensorFlow that successively aggregates and combines features from the K hops until a 'summary' representation remains - an embedding. In our example these embeddings are directly optimised to perform multi-class classification via a single subsequent dense layer and softmax cross entropy.
17
+
To create embeddings, we build a network in TensorFlow that successively aggregates and combines features from the K hops until a 'summary' representation remains - an embedding. In our example these embeddings are directly optimised to perform multi-class classification. This is achieved by passing the embeddings to a single subsequent dense layer and determining loss via softmax cross entropy with the labels retrieved.
18
18
19
-

19
+

20
20
21
21
22
22
23
-
## Example - CITES Animal Trade Data
23
+
## Usage by example - CITES Animal Trade Data
24
24
25
-
####Quickstart
25
+
### Quickstart
26
26
27
27
**Requirements:**
28
28
29
29
- Python 3.6.3 or higher
30
-
31
30
- kglib installed from pip: `pip install --extra-index-url https://test.pypi.org/simple/ grakn-kglib`
32
-
- The `animaltrade` dataset from the latest release. This is a dataset that has been pre-loaded into Grakn v1.5 (so you don't have to run the data import yourself), with two keyspaces: `animaltrade_train` and `animaltrade_test`.
31
+
- The `grakn-animaltrade.zip` dataset from the [latest release](https://github.com/graknlabs/kglib/releases/latest). This is a dataset that has been pre-loaded into Grakn v1.5 (so you don't have to run the data import yourself), with two keyspaces: `animaltrade_train` and `animaltrade_test`.
33
32
34
33
**To use:**
35
34
36
35
- Prepare the data:
37
36
38
37
- If you already have an insatnce of Grakn running, make sure to stop it using `./grakn server stop`
38
+
39
+
- Download the pre-loaded Grakn distribution from the [latest release](https://github.com/graknlabs/kglib/releases/latest)
39
40
40
-
- Unzip the pre-loaded Grakn + dataset from the latest release, the location you store this in doesn't matter
41
+
- Unzip the distribution `unzip grakn-animaltrade.zip `, where you store this doesn't matter
41
42
42
-
-`cd` into the dataset and start Grakn: `./grakn server start`
43
+
- cd into the distribution `cd grakn-animaltrade`
44
+
45
+
- start Grakn `./grakn server start`
43
46
44
47
- Confirm that the training keyspace is present and contains data
45
48
@@ -61,12 +64,12 @@ To create embeddings, we build a network in TensorFlow that successively aggrega
61
64
62
65
The CITES dataset details exchanges of animal-based products between countries. In this example we aim to predict the value of `appendix` for a set of samples. This `appendix` can be thought of as the level of endangerment that a `traded-item` is subject to, where `1` represents the highest level of endangerment, and `3` the lowest.
63
66
64
-
The `main` function will:
67
+
The [main](examples/animal_trade/main.py) function will:
65
68
66
-
- Search Grakn for 30 concepts (with an labels) to use as the training set, 30 for the evaluation set, and 30 for the prediction set using queries such as:
69
+
- Search Grakn for 30 concepts (with attributes as labels) to use as the training set, 30 for the evaluation set, and 30 for the prediction set using queries such as (limiting the returned stream):
67
70
68
71
```
69
-
match $e(exchanged-item: $traded-item) isa exchange, has appendix $appendix; $appendix 1; limit 30; get;
72
+
match $e(exchanged-item: $traded-item) isa exchange, has appendix $appendix; $appendix 1; get;
70
73
```
71
74
72
75
This searches for an `exchange` between countries that has an `appendix` (endangerment level) of `1`, and finds the `traded-item` that was exchanged
0 commit comments