Skip to main content

Akin

License: MIT Build Status PyPI - Downloads


Python library for detecting near duplicate texts in a corpus at scale using Locality Sensitive Hashing.

This algorithm identifies similar texts in a corpus by efficiently estimating their Jaccard similarity with sub-linear time complexity. This can be used to detect near duplicate texts at scale or locate different versions of a document.

Installation

Install from PyPI using pip:

python3 -m pip install akin

Or with uv using:

uv add akin

API Documentation

See the API documentation here for API and usage guide.

Quick Start Example

from akin import OPMinHash, LSH

content = [
    'Jupiter is primarily composed of hydrogen with a quarter of its mass being helium',
    'Jupiter moving out of the inner Solar System would have allowed the formation of inner '
    'planets.',
    'A helium atom has about four times as much mass as a hydrogen atom, so the composition '
    'changes when described as the proportion of mass contributed by different atoms.',
    'Jupiter is primarily composed of hydrogen and a quarter of its mass being helium',
    'A helium atom has about four times as much mass as a hydrogen atom and the composition '
    'changes when described as a proportion of mass contributed by different atoms.',
    'Theoretical models indicate that if Jupiter had much more mass than it does at present, it '
    'would shrink.',
    'This process causes Jupiter to shrink by about 2 cm each year.',
    'Jupiter is mostly composed of hydrogen with a quarter of its mass being helium',
    'The Great Red Spot is large enough to accommodate Earth within its boundaries.'
]

labels = [i for i in range(0, len(content))]

# Generate MinHash signatures.
minhash = OPMinHash(n_gram=9, permutations=100, hash_bits=64, seed=3)
signatures = minhash.transform(content)

# Create LSH model.
lsh = LSH(permutations=100, jaccard_similarity=0.5, probability=0.95)
lsh.update(signatures, labels)

# Query to find near duplicates for text 1.
print(lsh.query(0))
>>> [3, 7]

# Generate minhash signature and add new texts to LSH model.
new_text = [
    'Jupiter is primarily composed of hydrogen with a quarter of its mass being helium',
    'Jupiter moving out of the inner Solar System would have allowed the formation of '
    'inner planets.'
]

new_labels = ['doc1', 'doc2']

new_signatures = minhash.transform(new_text)
lsh.update(new_signatures, new_labels)
print(lsh.query(0))
>>> ['doc_1', 3, 7]

# Remove text and label from model.
lsh.remove([7])
print(lsh.query(0))
>>> ['doc1', 3]

Building and publishing

The source project requires Python 3.14 or newer. Release metadata is maintained in pyproject.toml.

Build the source distribution and wheel from the repository root:

uv lock
uv build
uvx --from twine twine check dist/akin-2.0.0*

Before publishing, install the wheel in a clean environment and check the public imports:

uv venv --python 3.14 /tmp/akin-release-check
uv pip install --python /tmp/akin-release-check/bin/python dist/akin-2.0.0-py3-none-any.whl
cd /tmp
/tmp/akin-release-check/bin/python -c "from akin import KMinHash, OPMinHash, LSH"

After validation, return to the repository root and upload the release:

uv publish dist/akin-2.0.0.tar.gz dist/akin-2.0.0-py3-none-any.whl

Authenticate using your PyPI publishing credentials when prompted; never commit tokens to the repository. Each PyPI release must use a version that has not already been published.

Metadata

Release files for akin 2.1.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 akin 2.1.0
File Size Uploaded Provenance Actions
akin-2.1.0.tar.gz 10.6 kB Without provenance Details for akin-2.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 20.5 kB

Release files / akin-2.1.0.tar.gz

Download URL akin-2.1.0.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
24150bc4e43f7125666b1a05ef454d1cbf8a59cd9c1dbee10b391423cbd78240
BLAKE2b-256 checksum
How to use checksums
d033fbccc815e710996a03f17ec48a58c5f2d7ce4989ec7c6f30fe8d4cc2ff5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.3

Release files / akin-2.1.0-py3-none-any.whl

Download URL akin-2.1.0-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e474fc0808cf149ea55a4430e5253294c6bb78452c6f54205150ff645f5deaa
BLAKE2b-256 checksum
How to use checksums
0fddb1462d3a3e2cd1b4af38951c8c4fba1ac2dc446ea4c84bc58d82516c9f7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.3

Security for akin 2.1.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