Document De-Duplication
A module for creating and indexing document character trigrams.
Installation
pip install deep_utils.deduplication
A use case scenario
Suppose we have an elasticsearch index my-index setup in AWS with vector name vector1 of size 10000
from deep_utils.deduplication.utils import es_wrapper
from deep_utils.deduplication.vector_generator import create_trigram_vector
from deep_utils.deduplication.elasticsearch import search_similar, add_to_index
es = es_wrapper('<aws endpoint>', 'aws_region')
text_document: str = 'this is test document'
vector = create_trigram_vector('en', text_document)
similar_docs_resp = search_similar(10, ('vector1', vector), 'my-index', es)
total = search_similar_resp['hits']['total']
max_score = search_similar_resp['hits']['max_score']
docs_ids = [x['_id'] for x in similar_docs_resp['hits']['hits']]
docs_scores = [x['_score'] for x in similar_docs_resp['hits']['hits']]
# To add document to index
resp = add_to_index(doc_id='1', vectors=dict(vector1=vector), index_name='my-index', es=es)
hasError = resp['errors']
Motivation
Can be found here
Scripts
There are scripts that generate trigrams from leads(documents) in DEEP.
Modules
trigrams
Just the collection of relevant trigrams for en, es and fr languages.
from deep_utils.deduplication.trigrams import en, es, fr
en_trigrams = en.trigrams # [' th', 'the', 'he ', ....]
es_trigrams = es.trigrams
fr_trigrams = fr.trigrams
NOTE: The trigrams contain 10000 relevant trigrams. So, the vector created will have dimension 10000.
utils
Consists of following functions:
# This is a wrapper function for creating Elasticsearch object
es_wrapper(endpoint: str, region: str, profile_name: str = 'default') -> Elasticsearch`
remove_puncs_and_extra_spaces(text: str) -> str` which is used for preprocessing texts
vector_generator
create_trigram_vector(lang: str, text: str) -> List[float]
create_count_vector(processed_text: str, trigrams: Dict[str, int]) -> List[int]
normalize_count_vector(count_vector: List[int]) -> List[float]
elasticsearch
search_similar(similar_count: int, vector: Tuple[str, List[float]], index_name: str, es: Elasticsearch)
add_to_index(doc_id: int, vectors: Dict[str, List[float]], index_name: str, es: Elasticsearch)
index_exists(index_name: str, es: Es) -> bool
create_knn_vector_index(index_name: str, vector_size: int, es: Es, ignore_error: bool = False) -> Tuple[bool, ErrorString]
create_knn_vector_index_if_not_exists(index_name: str, vector_size: int, es: Es) -> Tuple[bool, ErrorString]
Metadata
Release files for deep-utils.deduplication 1.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| deep_utils.deduplication-1.0.8.tar.gz | 93.0 kB | Without provenance | Details for deep_utils.deduplication-1.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| deep_utils.deduplication-1.0.8-py3-none-any.whl | Python 3 | none | any | Details for deep_utils.deduplication-1.0.8-py3-none-any.whl |
Total release size: 363.5 kB
Release files / deep_utils.deduplication-1.0.8.tar.gz
| Download URL | deep_utils.deduplication-1.0.8.tar.gz |
|---|---|
| Size | 93.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f57bb2a99a95c26add244a5ef751e6a9461b7279e23a7f278793e5c7a5cdc0f
|
|
BLAKE2b-256 checksum How to use checksums |
77e4401f981c5914237c6055d090741b02a87fba87f485d60b175a29175952cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.6
|
Release files / deep_utils.deduplication-1.0.8-py3-none-any.whl
| Download URL | deep_utils.deduplication-1.0.8-py3-none-any.whl |
|---|---|
| Size | 270.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5cfe6d60abea4d3f00728359db55ec9151c22ee5e27e930cd94c7a184bd5601f
|
|
BLAKE2b-256 checksum How to use checksums |
3892fd7168bd6383046b056b50c56561eb6d76b59af043021bf22840c767eefa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.6
|
Security for deep-utils.deduplication 1.0.8
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.