Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lukostaz committed Oct 22, 2019
2 parents 19c5321 + 8ee05e5 commit 07ce70f
Show file tree
Hide file tree
Showing 57 changed files with 4,960 additions and 3,709 deletions.
106 changes: 106 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
.common-values:

docker-image: &docker-image circleci/python:3.6.4

restore-cache: &restore-cache
keys:
- v1-dependencies-{{ checksum "setup.py" }}-{{ checksum "requirements.txt" }}

create-venv: &create-venv
name: Create virtualenv
command: /usr/local/bin/python3 -m venv venv

save-cache: &save-cache
paths:
- ./venv
key: v1-dependencies-{{ checksum "setup.py" }}-{{ checksum "requirements.txt" }}

install-package: &install-package
name: Install package
command: |
. venv/bin/activate
venv/bin/python3 -m pip install tensorflow==1.13.1
venv/bin/python3 -m pip install .
version: 2
jobs:
build:
docker:
- image: *docker-image
steps:
- checkout
- restore_cache: *restore-cache
- run: *create-venv
- save_cache: *save-cache
- run: *install-package

pip-check:
docker:
- image: *docker-image
steps:
- checkout
- restore_cache: *restore-cache
- run: *create-venv
- save_cache: *save-cache
- run: *install-package
- run:
name: Pip check
command: |
. venv/bin/activate
venv/bin/python3 -m pip check
test:
docker:
- image: *docker-image
steps:
- checkout
- restore_cache: *restore-cache
- run: *create-venv
- save_cache: *save-cache
- run: *install-package
- run:
name: Unit tests with Pytest
command: |
. venv/bin/activate
venv/bin/python3 -m pytest tests
lint:
docker:
- image: *docker-image
steps:
- checkout
- restore_cache: *restore-cache
- run: *create-venv
- save_cache: *save-cache
- run:
name: Linting with flake8
command: |
. venv/bin/activate
venv/bin/python3 -m pip install flake8
venv/bin/python3 -m flake8 ampligraph --max-line-length 120 --ignore=W291,W293
docs:
docker:
- image: *docker-image
steps:
- checkout
- restore_cache: *restore-cache
- run: *create-venv
- save_cache: *save-cache
- run: *install-package
- run:
name: Making docs with Sphinx
command: |
. venv/bin/activate
cd docs
make clean autogen html
workflows:
version: 2
checks:
jobs:
- build
- pip-check
- lint
- docs
- test
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

[![Documentation Status](https://readthedocs.org/projects/ampligraph/badge/?version=latest)](http://ampligraph.readthedocs.io/?badge=latest)

[Join the conversation on Slack](https://join.slack.com/t/ampligraph/shared_invite/enQtNTc2NTI0MzUxMTM5LTRkODk0MjI2OWRlZjdjYmExY2Q3M2M3NGY0MGYyMmI4NWYyMWVhYTRjZDhkZjA1YTEyMzBkMGE4N2RmNTRiZDg)
![](docs/img/slack_logo.png)

**Open source library based on TensorFlow that predicts links between concepts in a knowledge graph.**

Expand Down Expand Up @@ -41,7 +43,7 @@ It then combines embeddings with model-specific scoring functions to predict uns
AmpliGraph includes the following submodules:

* **Datasets**: helper functions to load datasets (knowledge graphs).
* **Models**: knowledge graph embedding models. AmpliGraph contains TransE, DistMult, ComplEx, HolE. (More to come!)
* **Models**: knowledge graph embedding models. AmpliGraph contains **TransE**, **DistMult**, **ComplEx**, **HolE**, **ConvKB**. (More to come!)
* **Evaluation**: metrics and evaluation protocols to assess the predictive power of the models.
* **Discovery**: High-level convenience APIs for knowledge discovery (discover new facts, cluster entities, predict near duplicates).

Expand Down Expand Up @@ -114,24 +116,24 @@ pip install -e .
```python
>> import ampligraph
>> ampligraph.__version__
'1.1.0'
'1.2.0'
```


## Predictive Power Evaluation (MRR Filtered)

AmpliGraph includes implementations of TransE, DistMult, ComplEx and HolE.
AmpliGraph includes implementations of TransE, DistMult, ComplEx, HolE and ConvKB.
Their predictive power is reported below and compared against the state-of-the-art results in literature.
[More details available here](https://docs.ampligraph.org/en/latest/experiments.html).

| |FB15K-237 |WN18RR |YAGO3-10 | FB15k |WN18 |
|-----------------|----------|---------|-----------|------------|---------------|
| Literature Best | **0.35***| 0.48* | 0.49* | **0.84**** | **0.95*** |
| TransE (AmpliGraph) | 0.31 | 0.22 | 0.49 | 0.63 | 0.65 |
| DistMult (AmpliGraph) | 0.31 | 0.45 | 0.49 | 0.78 | 0.82 |
| ComplEx (AmpliGraph) | 0.32 | **0.50**| **0.50** | 0.80 | 0.94 |
| HolE (AmpliGraph) | 0.31 | 0.47 | **0.50** | 0.80 | 0.93 |

| |FB15K-237 |WN18RR |YAGO3-10 | FB15k |WN18 |
|------------------------------|----------|---------|-----------|------------|---------------|
| Literature Best | **0.35***| 0.48* | 0.49* | **0.84**** | **0.95*** |
| TransE (AmpliGraph) | 0.31 | 0.22 | **0.51** | 0.63 | 0.66 |
| DistMult (AmpliGraph) | 0.31 | 0.47 | 0.50 | 0.78 | 0.82 |
| ComplEx (AmpliGraph) | 0.32 | **0.51**| 0.49 | 0.80 | 0.94 |
| HolE (AmpliGraph) | 0.31 | 0.47 | 0.50 | 0.80 | 0.94 |
| ConvKB (AmpliGraph) | 0.23 | 0.39 | 0.30 | 0.65 | 0.80 |

<sub>
* Timothee Lacroix, Nicolas Usunier, and Guillaume Obozinski. Canonical tensor decomposition for knowledge base
Expand Down
2 changes: 1 addition & 1 deletion ampligraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import logging.config
import pkg_resources

__version__ = '1.1.0'
__version__ = '1.2.0'
__all__ = ['datasets', 'latent_features', 'discovery', 'evaluation', 'utils']

logging.config.fileConfig(pkg_resources.resource_filename(__name__, 'logger.conf'), disable_existing_loggers=False)
4 changes: 2 additions & 2 deletions ampligraph/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"""Helper functions to load knowledge graphs."""

from .datasets import load_from_csv, load_from_rdf, load_fb15k, load_wn18, load_fb15k_237, load_from_ntriples, \
load_yago3_10, load_wn18rr
load_yago3_10, load_wn18rr, load_wn11, load_fb13

from .abstract_dataset_adapter import AmpligraphDatasetAdapter
from .sqlite_adapter import SQLiteAdapter
from .numpy_adapter import NumpyDatasetAdapter


__all__ = ['load_from_csv', 'load_from_rdf', 'load_from_ntriples', 'load_wn18', 'load_fb15k',
'load_fb15k_237', 'load_yago3_10', 'load_wn18rr',
'load_fb15k_237', 'load_yago3_10', 'load_wn18rr', 'load_wn11', 'load_fb13',
'AmpligraphDatasetAdapter', 'NumpyDatasetAdapter', 'SQLiteAdapter']
45 changes: 8 additions & 37 deletions ampligraph/datasets/abstract_dataset_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,55 +89,26 @@ def set_filter(self, filter_triples):
"""
raise NotImplementedError('Abstract Method not implemented!')

def get_next_train_batch(self, batch_size=1, dataset_type="train"):
def get_next_batch(self, batches_count=-1, dataset_type="train", use_filter=False):
"""Generator that returns the next batch of data.
Parameters
----------
batch_size : int
data size that needs to be returned
dataset_type: string
indicates which dataset to use
Returns
-------
batch_output : nd-array
yields a batch of triples from the dataset type specified
"""
raise NotImplementedError('Abstract Method not implemented!')

def get_next_eval_batch(self, batch_size=1, dataset_type="test"):
"""Generator that returns the next batch of data.
Parameters
----------
batch_size : int
data size that needs to be returned
dataset_type: string
indicates which dataset to use
batches_count: int
number of batches per epoch (default: -1, i.e. uses batch_size of 1)
use_filter : bool
Flag to indicate whether to return the concepts that need to be filtered
Returns
-------
batch_output : nd-array
yields a batch of triples from the dataset type specified
"""
raise NotImplementedError('Abstract Method not implemented!')

def get_next_batch_with_filter(self, batch_size=1, dataset_type="test"):
"""Generator that returns the next batch of data along with the filter.
Parameters
----------
batch_size : int
data size that needs to be returned
dataset_type: string
indicates which dataset to use
Returns
-------
batch_output : nd-array [n,3]
yields a batch of triples from the dataset type specified
participating_objects : nd-array [n,1]
all objects that were involved in the s-p-? relation
all objects that were involved in the s-p-? relation. This is returned only if use_filter is set to true.
participating_subjects : nd-array [n,1]
all subjects that were involved in the ?-p-o relation
all subjects that were involved in the ?-p-o relation. This is returned only if use_filter is set to true.
"""
raise NotImplementedError('Abstract Method not implemented!')

Expand Down
Loading

0 comments on commit 07ce70f

Please sign in to comment.