Fulltext-like search using NLP concept
Library for fulltext search using NLP concept. Use deeppavlov for paraphrase identification and Vantage-Point tree (based on jvptree) for fast search.
Installation
Install and update using pip:
pip install -U nlp-text-search
Usage
First init data, create deeppavlov settings and Doc2Vec for emdedding.
import deeppavlov
from gensim.models.doc2vec import Doc2Vec, TaggedDocument
from gensim.utils import simple_preprocess
from nlp_text_search import create_settings, LinearizedDist, SaveableVPTreeSearchEngine
paraphrases = [
(('красная ручка', 'синяя ручка'), 1),
(('красная ручка', 'зеленая ручка'), 1),
(('красная машина', 'синяя машина'), 1),
(('красная машина', 'зеленая машина'), 1),
(('синяя ручка', 'красная ручка'), 1),
(('синяя ручка', 'зеленая ручка'), 1),
(('синяя машина', 'красная машина'), 1),
(('синяя машина', 'зеленая машина'), 1),
(('красная ручка', 'красная машина'), 0),
(('красная ручка', 'синяя машина'), 0),
(('красная ручка', 'зеленая машина'), 0),
(('синяя ручка', 'красная машина'), 0),
(('синяя ручка', 'синяя машина'), 0),
(('синяя ручка', 'зеленая машина'), 0)
]
all_texts = list(set([t[0][0] for t in paraphrases] + [t[0][1] for t in paraphrases]))
settings = create_settings(paraphrases, 'test')
deeppavlov.train_model(settings)
doc2vec = Doc2Vec([TaggedDocument(simple_preprocess(t), [i]) for i, t in enumerate(all_texts)],
min_count=1, workers=1, negative=0, dm=0, hs=1)
Then create search engine and search nearest neighbors
se = DefaultSearchEngine(settings, doc2vec, LinearizedDist, points=all_texts)
print(se.search('красная ручка', 4))
returns
[('красная ручка', 0), ('зеленая ручка', 0.05778998136520386), ('синяя ручка', 0.06721997261047363), ('синяя машина', 0.48162001371383667)]
You also can save and load search engine
se.save('se')
se = DefaultSearchEngine.load('se')
Metadata
Release files for nlp-text-search 0.6.16
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 |
|---|---|---|---|---|
| nlp-text-search-0.6.16.tar.gz | 21.6 kB | Without provenance | Details for nlp-text-search-0.6.16.tar.gz |
Release files / nlp-text-search-0.6.16.tar.gz
| Download URL | nlp-text-search-0.6.16.tar.gz |
|---|---|
| Size | 21.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
024fe75a705645ada57e83f3ce53226ea299ae9dc31eba448c0b8e0bfb20f6e6
|
|
BLAKE2b-256 checksum How to use checksums |
78474f4de1aaf99895cc71219ee3d1da8b6754b6d304f8861898d7ddfdc37ced
|
| 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/50.3.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5
|
Security for nlp-text-search 0.6.16
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.