Skip to main content

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

If you have a GPU you can make kiez faster by installing faiss (if you do not already have it in your environment):

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.

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

  pip install kiez[nmslib]

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

    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:

    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

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/

Metadata

Release files for kiez 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kiez 0.5.0
File Size Uploaded Provenance Actions
kiez-0.5.0.tar.gz 30.0 kB Without provenance Details for kiez-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kiez 0.5.0
File Interpreter ABI Platform Actions
kiez-0.5.0-py3-none-any.whl Python 3 none any Details for kiez-0.5.0-py3-none-any.whl

Total release size: 68.9 kB

Release files / kiez-0.5.0.tar.gz

Download URL kiez-0.5.0.tar.gz
Size 30.0 kB
Tags Source
SHA-256 checksum
How to use checksums
bf62ec6711ffd9c4a7848513fdfc5453d6bd95384b7d6c0eb21d01c38b2469c6
BLAKE2b-256 checksum
How to use checksums
899e7330c2237cc27147014f865355dd7f58d134b81e830f97c91d34b6a84ba2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.10.6 Linux/5.19.0-38-generic

Release files / kiez-0.5.0-py3-none-any.whl

Download URL kiez-0.5.0-py3-none-any.whl
Size 38.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bbf025ef100c0f8136446dec965e0c63b3a0597044f342e481bbe8f5f08f7f60
BLAKE2b-256 checksum
How to use checksums
0bb09e6c691cf6cc776272bd050f759b650b7fd1119332d552ac8bbd0473f58b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.10.6 Linux/5.19.0-38-generic

Security for kiez 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page