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]

Metadata

Release files for akin 2.0.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.0.0
File Size Uploaded Provenance Actions
akin-2.0.0.tar.gz 9.9 kB Without provenance Details for akin-2.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 19.4 kB

Release files / akin-2.0.0.tar.gz

Download URL akin-2.0.0.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
dccfe66e2ae0f55a85f58be411c0c1225eb10f49022e40b0a716a35348cd1894
BLAKE2b-256 checksum
How to use checksums
1d280a83e1a685bc31085a29b4688c82052560aaaf744725b66d5f83517e982e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.3

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

Download URL akin-2.0.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60bb132c34bd1df4a1e70c72b7417b5242ab89b70728e6f1e1dd38d8c7735479
BLAKE2b-256 checksum
How to use checksums
1c78bf83006a372f11d2c58c1a836239cde7e2fa87be3fc7220a34cd291b0654
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.3

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