Skip to content
Permalink
Browse files

Fixing merge conflict

  • Loading branch information...
tabacof committed Jul 11, 2019
2 parents a9ffee0 + 17951fc commit 71e9d0e643696918fe2f5b54f676871411d70a90
Showing with 4,311 additions and 627,037 deletions.
  1. +1 −1 LICENSE
  2. +0 −1 MANIFEST.in
  3. +7 −7 README.md
  4. +8 −1 ampligraph/__init__.py
  5. +14 −1 ampligraph/datasets/__init__.py
  6. +147 −0 ampligraph/datasets/abstract_dataset_adapter.py
  7. +177 −92 ampligraph/datasets/datasets.py
  8. +209 −0 ampligraph/datasets/numpy_adapter.py
  9. +499 −0 ampligraph/datasets/sqlite_adapter.py
  10. +116 −49 ampligraph/discovery/discovery.py
  11. +8 −1 ampligraph/evaluation/__init__.py
  12. +14 −11 ampligraph/evaluation/metrics.py
  13. +371 −329 ampligraph/evaluation/protocol.py
  14. +15 −6 ampligraph/latent_features/__init__.py
  15. +110 −83 ampligraph/latent_features/loss_functions.py
  16. +20 −12 ampligraph/latent_features/misc.py
  17. +1,274 −1,174 ampligraph/latent_features/models.py
  18. +416 −0 ampligraph/latent_features/optimizers.py
  19. +7 −0 ampligraph/latent_features/pool_functions.py
  20. +0 −625,000 ampligraph/latent_features/prime_number_list.txt
  21. +42 −25 ampligraph/latent_features/regularizers.py
  22. +7 −0 ampligraph/utils/__init__.py
  23. +114 −47 ampligraph/utils/model_utils.py
  24. +6 −0 docs/changelog.md
  25. +3 −1 docs/examples.md
  26. +174 −22 docs/experiments.rst
  27. BIN docs/img/embeddings_projector.png
  28. +1 −1 docs/install.md
  29. +27 −0 docs/references.bib
  30. +2 −2 experiments/config.json
  31. +9 −2 experiments/predictive_performance.py
  32. +3 −0 jenkins.sh
  33. +11 −2 setup.py
  34. +7 −0 tests/__init__.py
  35. +7 −0 tests/ampligraph/__init__.py
  36. +7 −0 tests/ampligraph/datasets/__init__.py
  37. +12 −6 tests/ampligraph/datasets/test_datasets.py
  38. +68 −17 tests/ampligraph/discovery/test_discovery.py
  39. +7 −0 tests/ampligraph/evaluation/__init__.py
  40. +7 −0 tests/ampligraph/evaluation/test_metrics.py
  41. +301 −92 tests/ampligraph/evaluation/test_protocol.py
  42. +7 −0 tests/ampligraph/latent_features/__init__.py
  43. +8 −0 tests/ampligraph/latent_features/test_misc.py
  44. +42 −48 tests/ampligraph/latent_features/test_models.py
  45. +7 −0 tests/ampligraph/latent_features/test_regularizers.py
  46. +7 −0 tests/ampligraph/utils/__init__.py
  47. +12 −4 tests/ampligraph/utils/test_model_utils.py
@@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2019 The AmpliGraph Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -1,3 +1,2 @@
include ampligraph/latent_features/prime_number_list.txt
include ampligraph/logger.conf

@@ -114,18 +114,18 @@ pip install -e .
```python
>> import ampligraph
>> ampligraph.__version__
'1.1-dev'
'1.0.3'
```


## Predictive Power Evaluation (MRR Filtered)

| |FB15k |WN18 |WN18RR |FB15K-237|YAGO3-10 |
|----------|------|-------|-------|---------|---------|
| TransE | 0.55 | 0.50 | 0.23 | 0.31 | 0.24 |
| DistMult | 0.79 | 0.83 | 0.44 | 0.29 | 0.49 |
| ComplEx | 0.79 | 0.94 | 0.44 | 0.30 | 0.50 |
| HolE | 0.80 | 0.94 | 0.47 | 0.28 | 0.50 |
| |FB15k |WN18 |WN18RR |FB15K-237 |YAGO3-10 |
|----------|----------|-----------|-----------|-------------|-------------|
| TransE | 0.55 | 0.50 | 0.23 | 0.31 | 0.24 |
| DistMult | 0.79 | 0.83 | 0.44 | 0.29 | 0.49 |
| ComplEx | 0.79 | **0.94** | **0.50** | **0.33** | **0.50** |
| HolE | **0.80** | **0.94** | 0.47 | 0.28 | **0.50** |


## Documentation
@@ -1,8 +1,15 @@
# Copyright 2019 The AmpliGraph Authors. All Rights Reserved.
#
# This file is Licensed under the Apache License, Version 2.0.
# A copy of the Licence is available in LICENCE, or at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
"""Explainable Link Prediction is a library for relational learning on knowledge graphs."""
import logging.config
import pkg_resources

__version__ = '1.1-dev'
__version__ = '1.0.3'
__all__ = ['datasets', 'latent_features', 'evaluation']

logging.config.fileConfig(pkg_resources.resource_filename(__name__, 'logger.conf'), disable_existing_loggers=False)
@@ -1,7 +1,20 @@
# Copyright 2019 The AmpliGraph Authors. All Rights Reserved.
#
# This file is Licensed under the Apache License, Version 2.0.
# A copy of the Licence is available in LICENCE, or at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
"""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

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',
'AmpligraphDatasetAdapter', 'NumpyDatasetAdapter', 'SQLiteAdapter']
@@ -0,0 +1,147 @@
import abc


class AmpligraphDatasetAdapter(abc.ABC):
"""Abstract class for dataset adapters
Developers can design in similar format to adapt data from different sources to feed to ampligraph.
"""
def __init__(self):
"""Initialize the class variables
"""
self.dataset = {}

# relation to idx mappings
self.rel_to_idx = {}
# entities to idx mappings
self.ent_to_idx = {}
# Mapped status of each dataset
self.mapped_status = {}

def use_mappings(self, rel_to_idx, ent_to_idx):
"""Use an existing mapping with the datasource.
"""
self.rel_to_idx = rel_to_idx
self.ent_to_idx = ent_to_idx
# set the mapped status to false, since we are changing the dictionary
for key in self.dataset.keys():
self.mapped_status[key] = False

def generate_mappings(self, use_all=False):
"""Generate mappings from either train set or use all dataset to generate mappings
Parameters
----------
use_all : boolean
If True, it generates mapping from all the data. If False, it only uses training set to generate mappings
Returns
-------
rel_to_idx : dictionary
Relation to idx mapping dictionary
ent_to_idx : dictionary
entity to idx mapping dictionary
"""
raise NotImplementedError('Abstract Method not implemented!')

def get_size(self, dataset_type="train"):
"""Returns the size of the specified dataset
Parameters
----------
dataset_type : string
type of the dataset
Returns
-------
size : int
size of the specified dataset
"""

raise NotImplementedError('Abstract Method not implemented!')

def set_data(self, dataset, dataset_type=None, mapped_status=False):
"""set the dataset based on the type
Parameters
----------
dataset : nd-array or dictionary
dataset of triples
dataset_type : string
if the dataset parameter is an nd- array then this indicates the type of the data being based
mapped_status : bool
indicates whether the data has already been mapped to the indices
"""
raise NotImplementedError('Abstract Method not implemented!')

def map_data(self, remap=False):
"""map the data to the mappings of ent_to_idx and rel_to_idx
Parameters
----------
remap : boolean
remap the data, if already mapped. One would do this if the dictionary is updated.
"""
raise NotImplementedError('Abstract Method not implemented!')

def set_filter(self, filter_triples):
"""set's the filter that need to be used while generating evaluation batch
Parameters
----------
filter_triples : nd-array
triples that would be used as filter
"""
raise NotImplementedError('Abstract Method not implemented!')

def get_next_train_batch(self, batch_size=1, dataset_type="train"):
"""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
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
participating_subjects : nd-array [n,1]
all subjects that were involved in the ?-p-o relation
"""
raise NotImplementedError('Abstract Method not implemented!')

def cleanup(self):
"""Cleans up the internal state
"""
raise NotImplementedError('Abstract Method not implemented!')

0 comments on commit 71e9d0e

Please sign in to comment.
You can’t perform that action at this time.