Skip to main content

Hubness reduced nearest neighbor search for entity alignment with knowledge graph embeddings

Project description

kiez logo

kiez

Actions Status Documentation Status Stable python versions License BSD3 - Clause Code style: black

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 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:

pip install kiez

To make kiez faster it is recommended to install faiss as well (if you do not already have it in your environment):

pip install kiez[faiss-cpu]

or if you have a gpu:

pip install kiez[faiss-gpu]

If you need specific cuda versions for faiss see their installation instructions and install it seperately.

You can also get other specific libraries with e.g.:

  pip install kiez[nmslib]

If you want to install all of them use:

  pip install kiez[all]

Usage

Simple nearest neighbor search for source entities in target space:

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:

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
from kiez.neighbors import Faiss
faiss = Faiss(n_candidates=10)
from kiez.hubness_reduction import CSLS
hr = CSLS()
# fit and get neighbors
k_inst = Kiez(n_neighbors=5, algorithm=faiss, hubness=hr)
k_inst.fit(source, target)
nn_dist, nn_ind = k_inst.kneighbors()

Documentation

You can find more documentation on readthedocs

Benchmark

The results and configurations of our experiments can be found in a seperate benchmarking repository

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:

git clone git@github.com:dobraczka/kiez.git
cd kiez
poetry install

To run the tests (given you are in the kiez folder):

poetry run pytest tests

Or install nox and run:

nox

which checks all the linting as well.

License

kiez is licensed under the terms of the BSD-3-Clause license. Several files were modified from scikit-hubness, distributed under the same license. 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/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kiez-0.4.3.tar.gz (29.7 kB view details)

Uploaded Source

Built Distribution

kiez-0.4.3-py3-none-any.whl (40.4 kB view details)

Uploaded Python 3

File details

Details for the file kiez-0.4.3.tar.gz.

File metadata

  • Download URL: kiez-0.4.3.tar.gz
  • Upload date:
  • Size: 29.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.19.0-35-generic

File hashes

Hashes for kiez-0.4.3.tar.gz
Algorithm Hash digest
SHA256 89b59482a62b420431af3cfe237e843503e1279362534e75acb7b55fc5973ea1
MD5 13a9acf1192f56e0b0c3a531c442d60b
BLAKE2b-256 eaf13910cc5717cfb348d5e377c889b8bfeddce88d33069a616eb1dfeb667db0

See more details on using hashes here.

File details

Details for the file kiez-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: kiez-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 40.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.19.0-35-generic

File hashes

Hashes for kiez-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 03dd42c7b4e27ab02f938d1701268e318bb7bacfcaa1a9fa910ef442984bdca7
MD5 87a7abcf26ef5184e9def36643685128
BLAKE2b-256 0743ec46426a0af9848d269d091110821d4c1aa0059d25b8ceba70b71bfa842d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page