<p align="center">
<img src="https://github.com/dobraczka/kiez/raw/main/docs/kiezlogo.png" alt="kiez logo", width=200/>
</p>
<h2 align="center"> <a href="https://dbs.uni-leipzig.de/file/KIEZ_KEOD_2021_Obraczka_Rahm.pdf">kiez</a></h2>
<p align="center">
<a href="https://github.com/dobraczka/kiez/actions/workflows/main.yml"><img alt="Actions Status" src="https://github.com/dobraczka/kiez/actions/workflows/main.yml/badge.svg?branch=main"></a>
<a href='https://kiez.readthedocs.io/en/latest/?badge=latest'><img src='https://readthedocs.org/projects/kiez/badge/?version=latest' alt='Documentation Status' /></a>
<a href="https://pypi.org/project/kiez"/><img alt="Stable python versions" src="https://img.shields.io/pypi/pyversions/kiez"></a>
<a href="https://github.com/dobraczka/kiez/blob/main/LICENSE"><img alt="License BSD3 - Clause" src="https://img.shields.io/badge/license-BSD--3--Clause-blue"></a>
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
</p>
A Python library for hubness reduced nearest neighbor search for the task of entity alignment with knowledge graph embeddings. The term kiez is a [german word](https://en.wikipedia.org/wiki/Kiez) that refers to a city neighborhood.
## Hubness Reduction
Hubness is a phenomenon that arises in high-dimensional data and describes the fact that a couple of entities are nearest neighbors (NN) of many other entities, while a lot of entities are NN to no one.
For entity alignment with knowledge graph embeddings we rely on NN search. Hubness therefore is detrimental to our matching results.
This library is intended to make hubness reduction techniques available to data integration projects that rely on (knowledge graph) embeddings in their alignment process. Furthermore kiez incorporates several approximate nearest neighbor (ANN) libraries, to pair the speed advantage of approximate neighbor search with increased accuracy of hubness reduction.
## Installation
You can install kiez via pip:
``` bash
pip install kiez
```
If you have a GPU you can make kiez faster by installing [faiss](https://github.com/facebookresearch/faiss) (if you do not already have it in your environment):
``` bash
conda env create -n kiez-faiss python=3.10
conda activate kiez-faiss
conda install -c pytorch -c nvidia faiss-gpu=1.7.4 mkl=2021 blas=1.0=mkl
pip install kiez
```
For more information see their [installation instructions](https://github.com/facebookresearch/faiss/blob/main/INSTALL.md).
You can also get other specific libraries with e.g.:
``` bash
pip install kiez[nmslib]
```
## Usage
Simple nearest neighbor search for source entities in target space:
``` python
from kiez import Kiez
import numpy as np
# create example data
rng = np.random.RandomState(0)
source = rng.rand(100,50)
target = rng.rand(100,50)
# fit and get neighbors
k_inst = Kiez()
k_inst.fit(source, target)
nn_dist, nn_ind = k_inst.kneighbors()
```
Using (A)NN libraries and hubness reduction methods:
``` python
from kiez import Kiez
import numpy as np
# create example data
rng = np.random.RandomState(0)
source = rng.rand(100,50)
target = rng.rand(100,50)
# prepare algorithm and hubness reduction
algo_kwargs = {"n_candidates": 10}
k_inst = Kiez(n_neighbors=5, algorithm="Faiss" algorithm_kwargs=algo_kwargs, hubness="CSLS")
# fit and get neighbors
k_inst.fit(source, target)
nn_dist, nn_ind = k_inst.kneighbors()
```
## Torch Support
Beginning with version 0.5.0 torch can be used, when using `Faiss` as NN library:
```python
from kiez import Kiez
import torch
source = torch.randn((100,10))
target = torch.randn((200,10))
k_inst = Kiez(algorithm="Faiss", hubness="CSLS")
k_inst.fit(source, target)
nn_dist, nn_ind = k_inst.kneighbors()
```
You can also utilize tensor on the GPU:
```python
k_inst = Kiez(algorithm="Faiss", algorithm_kwargs={"use_gpu":True}, hubness="CSLS")
k_inst.fit(source.cuda(), target.cuda())
nn_dist, nn_ind = k_inst.kneighbors()
```
## Documentation
You can find more documentation on [readthedocs](https://kiez.readthedocs.io)
## Benchmark
The results and configurations of our experiments can be found in a seperate [benchmarking repository](https://github.com/dobraczka/kiez-benchmarking)
## Citation
If you find this work useful you can use the following citation:
```
@article{obraczka2022fast,
title={Fast Hubness-Reduced Nearest Neighbor Search for Entity Alignment in Knowledge Graphs},
author={Obraczka, Daniel and Rahm, Erhard},
journal={SN Computer Science},
volume={3},
number={6},
pages={1--19},
year={2022},
publisher={Springer},
url={https://link.springer.com/article/10.1007/s42979-022-01417-1},
doi={10.1007/s42979-022-01417-1},
}
```
## Contributing
PRs and enhancement ideas are always welcome. If you want to build kiez locally use:
```bash
git clone git@github.com:dobraczka/kiez.git
cd kiez
poetry install
```
To run the tests (given you are in the kiez folder):
```bash
poetry run pytest tests
```
Or install [nox](https://github.com/theacodes/nox) and run:
```
nox
```
which checks all the linting as well.
## License
`kiez` is licensed under the terms of the BSD-3-Clause [license](LICENSE.txt).
Several files were modified from [`scikit-hubness`](https://github.com/VarIr/scikit-hubness),
distributed under the same [license](external/SCIKIT_HUBNESS_LICENSE.txt).
The respective files contain the following tag instead of the full license text.
SPDX-License-Identifier: BSD-3-Clause
This enables machine processing of license information based on the SPDX
License Identifiers that are here available: https://spdx.org/licenses/
Raw data
{
"_id": null,
"home_page": "https://github.com/dobraczka/kiez",
"name": "kiez",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "embedding,hubness,knowledge graph,entity resolution,approximate nearest neighbor search,nearest neighbors,knowledge graph embedding",
"author": "Daniel Obraczka",
"author_email": "obraczka@informatik.uni-leipzig.de",
"download_url": "https://files.pythonhosted.org/packages/89/9e/7330c2237cc27147014f865355dd7f58d134b81e830f97c91d34b6a84ba2/kiez-0.5.0.tar.gz",
"platform": null,
"description": "<p align=\"center\">\n<img src=\"https://github.com/dobraczka/kiez/raw/main/docs/kiezlogo.png\" alt=\"kiez logo\", width=200/>\n</p>\n\n<h2 align=\"center\"> <a href=\"https://dbs.uni-leipzig.de/file/KIEZ_KEOD_2021_Obraczka_Rahm.pdf\">kiez</a></h2>\n\n<p align=\"center\">\n<a href=\"https://github.com/dobraczka/kiez/actions/workflows/main.yml\"><img alt=\"Actions Status\" src=\"https://github.com/dobraczka/kiez/actions/workflows/main.yml/badge.svg?branch=main\"></a>\n<a href='https://kiez.readthedocs.io/en/latest/?badge=latest'><img src='https://readthedocs.org/projects/kiez/badge/?version=latest' alt='Documentation Status' /></a>\n<a href=\"https://pypi.org/project/kiez\"/><img alt=\"Stable python versions\" src=\"https://img.shields.io/pypi/pyversions/kiez\"></a>\n<a href=\"https://github.com/dobraczka/kiez/blob/main/LICENSE\"><img alt=\"License BSD3 - Clause\" src=\"https://img.shields.io/badge/license-BSD--3--Clause-blue\"></a>\n<a href=\"https://github.com/psf/black\"><img alt=\"Code style: black\" src=\"https://img.shields.io/badge/code%20style-black-000000.svg\"></a>\n</p>\n\nA Python library for hubness reduced nearest neighbor search for the task of entity alignment with knowledge graph embeddings. The term kiez is a [german word](https://en.wikipedia.org/wiki/Kiez) that refers to a city neighborhood.\n\n## Hubness Reduction\nHubness is a phenomenon that arises in high-dimensional data and describes the fact that a couple of entities are nearest neighbors (NN) of many other entities, while a lot of entities are NN to no one.\nFor entity alignment with knowledge graph embeddings we rely on NN search. Hubness therefore is detrimental to our matching results.\nThis library is intended to make hubness reduction techniques available to data integration projects that rely on (knowledge graph) embeddings in their alignment process. Furthermore kiez incorporates several approximate nearest neighbor (ANN) libraries, to pair the speed advantage of approximate neighbor search with increased accuracy of hubness reduction.\n\n## Installation\nYou can install kiez via pip:\n``` bash\npip install kiez\n```\n\nIf you have a GPU you can make kiez faster by installing [faiss](https://github.com/facebookresearch/faiss) (if you do not already have it in your environment):\n\n``` bash\nconda env create -n kiez-faiss python=3.10\nconda activate kiez-faiss\nconda install -c pytorch -c nvidia faiss-gpu=1.7.4 mkl=2021 blas=1.0=mkl\npip install kiez\n```\n\nFor more information see their [installation instructions](https://github.com/facebookresearch/faiss/blob/main/INSTALL.md).\n\nYou can also get other specific libraries with e.g.:\n\n``` bash\n pip install kiez[nmslib]\n```\n\n## Usage\nSimple nearest neighbor search for source entities in target space:\n``` python\nfrom kiez import Kiez\nimport numpy as np\n# create example data\nrng = np.random.RandomState(0)\nsource = rng.rand(100,50)\ntarget = rng.rand(100,50)\n# fit and get neighbors\nk_inst = Kiez()\nk_inst.fit(source, target)\nnn_dist, nn_ind = k_inst.kneighbors()\n```\nUsing (A)NN libraries and hubness reduction methods:\n``` python\nfrom kiez import Kiez\nimport numpy as np\n# create example data\nrng = np.random.RandomState(0)\nsource = rng.rand(100,50)\ntarget = rng.rand(100,50)\n# prepare algorithm and hubness reduction\nalgo_kwargs = {\"n_candidates\": 10}\nk_inst = Kiez(n_neighbors=5, algorithm=\"Faiss\" algorithm_kwargs=algo_kwargs, hubness=\"CSLS\")\n# fit and get neighbors\nk_inst.fit(source, target)\nnn_dist, nn_ind = k_inst.kneighbors()\n```\n\n## Torch Support\nBeginning with version 0.5.0 torch can be used, when using `Faiss` as NN library:\n\n```python\n\n from kiez import Kiez\n import torch\n source = torch.randn((100,10))\n target = torch.randn((200,10))\n k_inst = Kiez(algorithm=\"Faiss\", hubness=\"CSLS\")\n k_inst.fit(source, target)\n nn_dist, nn_ind = k_inst.kneighbors()\n```\n\nYou can also utilize tensor on the GPU:\n\n```python\n\n k_inst = Kiez(algorithm=\"Faiss\", algorithm_kwargs={\"use_gpu\":True}, hubness=\"CSLS\")\n k_inst.fit(source.cuda(), target.cuda())\n nn_dist, nn_ind = k_inst.kneighbors()\n```\n\n## Documentation\nYou can find more documentation on [readthedocs](https://kiez.readthedocs.io)\n\n## Benchmark\nThe results and configurations of our experiments can be found in a seperate [benchmarking repository](https://github.com/dobraczka/kiez-benchmarking)\n\n## Citation\nIf you find this work useful you can use the following citation:\n```\n@article{obraczka2022fast,\n title={Fast Hubness-Reduced Nearest Neighbor Search for Entity Alignment in Knowledge Graphs},\n author={Obraczka, Daniel and Rahm, Erhard},\n journal={SN Computer Science},\n volume={3},\n number={6},\n pages={1--19},\n year={2022},\n publisher={Springer},\n url={https://link.springer.com/article/10.1007/s42979-022-01417-1},\n doi={10.1007/s42979-022-01417-1},\n}\n```\n\n## Contributing\nPRs and enhancement ideas are always welcome. If you want to build kiez locally use:\n```bash\ngit clone git@github.com:dobraczka/kiez.git\ncd kiez\npoetry install\n```\nTo run the tests (given you are in the kiez folder):\n```bash\npoetry run pytest tests\n```\n\nOr install [nox](https://github.com/theacodes/nox) and run:\n```\nnox\n```\nwhich checks all the linting as well.\n\n## License\n`kiez` is licensed under the terms of the BSD-3-Clause [license](LICENSE.txt).\nSeveral files were modified from [`scikit-hubness`](https://github.com/VarIr/scikit-hubness),\ndistributed under the same [license](external/SCIKIT_HUBNESS_LICENSE.txt).\nThe respective files contain the following tag instead of the full license text.\n\n SPDX-License-Identifier: BSD-3-Clause\n\nThis enables machine processing of license information based on the SPDX\nLicense Identifiers that are here available: https://spdx.org/licenses/\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "Hubness reduced nearest neighbor search for entity alignment with knowledge graph embeddings",
"version": "0.5.0",
"project_urls": {
"Documentation": "https://kiez.readthedocs.io/",
"Homepage": "https://github.com/dobraczka/kiez",
"Repository": "https://github.com/dobraczka/kiez"
},
"split_keywords": [
"embedding",
"hubness",
"knowledge graph",
"entity resolution",
"approximate nearest neighbor search",
"nearest neighbors",
"knowledge graph embedding"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0bb09e6c691cf6cc776272bd050f759b650b7fd1119332d552ac8bbd0473f58b",
"md5": "7f365ad77ebfbf21f630ff5e14acc6ab",
"sha256": "bbf025ef100c0f8136446dec965e0c63b3a0597044f342e481bbe8f5f08f7f60"
},
"downloads": -1,
"filename": "kiez-0.5.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7f365ad77ebfbf21f630ff5e14acc6ab",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 38843,
"upload_time": "2024-01-11T16:48:11",
"upload_time_iso_8601": "2024-01-11T16:48:11.920129Z",
"url": "https://files.pythonhosted.org/packages/0b/b0/9e6c691cf6cc776272bd050f759b650b7fd1119332d552ac8bbd0473f58b/kiez-0.5.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "899e7330c2237cc27147014f865355dd7f58d134b81e830f97c91d34b6a84ba2",
"md5": "2369f4733aeaabff699bf00ca3accc98",
"sha256": "bf62ec6711ffd9c4a7848513fdfc5453d6bd95384b7d6c0eb21d01c38b2469c6"
},
"downloads": -1,
"filename": "kiez-0.5.0.tar.gz",
"has_sig": false,
"md5_digest": "2369f4733aeaabff699bf00ca3accc98",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 30032,
"upload_time": "2024-01-11T16:48:13",
"upload_time_iso_8601": "2024-01-11T16:48:13.943917Z",
"url": "https://files.pythonhosted.org/packages/89/9e/7330c2237cc27147014f865355dd7f58d134b81e830f97c91d34b6a84ba2/kiez-0.5.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-11 16:48:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dobraczka",
"github_project": "kiez",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "kiez"
}