
파이썬에서 빠르고 가벼우 며 사용자 정의 가능한 퍼지 및 의미 론적 텍스트 검색.
Neofuzz는 벡터화 및 가장 가까운 이웃 검색 기술을 기반으로 한 퍼지 검색 라이브러리입니다.
이제 Levenshtein 거리를 사용하여 검색 결과를 재정렬 할 수 있습니다! 때때로 N- 그램 프로세스 또는 벡터화 된 프로세스는 결과를 올바르게 주문하지 않습니다. 이 경우 인덱스 된 코퍼스에서 더 많은 수의 예제를 검색 한 다음 Levenshtein 거리로 결과를 개선 할 수 있습니다.
from neofuzz import char_ngram_process
process = char_ngram_process ()
process . index ( corpus )
process . extract ( "your query" , limit = 30 , refine_levenshtein = True )대부분의 퍼지 검색 라이브러리는 동일한 몇 가지 퍼지 검색 알고리즘 (해밍 거리, Levenshtein 거리)에서 지옥을 최적화하는 데 의존합니다. 불행히도 이러한 알고리즘의 복잡성으로 인해 최적화의 양은 원하는 속도를 얻지 못할 것입니다.
Neofuzz는 전통적인 알고리즘에 의존하여 특정 속도 제한을 넘을 수 없으며 텍스트 벡터화를 사용하고 벡터 공간에서 가장 가까운 이웃 검색을 사용 하여이 프로세스 속도를 높이는 것을 실현합니다.
속도 대 정확도의 딜레마에 관해서는 Neofuzz가 최대한의 속도를냅니다.
PYPI에서 Neofuzz를 설치할 수 있습니다.
pip install neofuzz 플러그 앤 플레이 경험을 원한다면 char_ngram_process() 프로세스를 사용하여 일반적으로 좋은 빠르고 더러운 프로세스를 만들 수 있습니다.
from neofuzz import char_ngram_process
# We create a process that takes character 1 to 5-grams as features for
# vectorization and uses a tf-idf weighting scheme.
# We will use cosine distance for the nearest neighbour search.
process = char_ngram_process ( ngram_range = ( 1 , 5 ), metric = "cosine" , tf_idf = True )
# We index the options that we are going to search in
process . index ( options )
# Then we can extract the ten most similar items the same way as in
# thefuzz
process . extract ( "fuzz" , limit = 10 )
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[( 'fuzzer' , 67 ),
( 'Januzzi' , 30 ),
( 'Figliuzzi' , 25 ),
( 'Fun' , 20 ),
( 'Erika_Petruzzi' , 20 ),
( 'zu' , 20 ),
( 'Zo' , 18 ),
( 'blog_BuzzMachine' , 18 ),
( 'LW_Todd_Bertuzzi' , 18 ),
( 'OFU' , 17 )]사용자 정의 프로세스를 작성하여 Neofuzz의 동작을 사용자 정의 할 수 있습니다. 후드 아래에서 모든 Neofuzz 프로세스는 동일한 두 구성 요소에 의존합니다.
텍스트의 단어/시맨틱 내용에 더 관심이 있으시면 기능으로 사용할 수도 있습니다. 이것은 문학 작품과 같은 더 긴 텍스트에서 특히 유용 할 수 있습니다.
from neofuzz import Process
from sklearn . feature_extraction . text import TfidfVectorizer
# Vectorization with words is the default in sklearn.
vectorizer = TfidfVectorizer ()
# We use cosine distance because it's waay better for high-dimentional spaces.
process = Process ( vectorizer , metric = "cosine" )퍼지 검색 프로세스의 속도가 충분하지 않다는 것을 알 수 있습니다. 이 경우 일부 매트릭스 분해 방법 또는 주제 모델로 생성 된 벡터의 치수를 감소시키는 것이 바람직 할 수 있습니다.
예를 들어 여기서는 NMF (우수한 주제 모델과 엄청나게 빠른 것도)를 사용하여 퍼지 검색 파이프 라인을 가속화합니다.
from neofuzz import Process
from sklearn . feature_extraction . text import TfidfVectorizer
from sklearn . decomposition import NMF
from sklearn . pipeline import make_pipeline
# Vectorization with tokens again
vectorizer = TfidfVectorizer ()
# Dimensionality reduction method to 20 dimensions
nmf = NMF ( n_components = 20 )
# Create a pipeline of the two
pipeline = make_pipeline ( vectorizer , nmf )
process = Process ( pipeline , metric = "cosine" )Neofuzz를 사용하면 시맨틱 임베드를 쉽게 사용할 수 있으며주의 기반 언어 모델 (Bert), 간단한 신경 단어 또는 문서 임베딩 (Word2Vec, Doc2Vec, FastText 등) 또는 OpenAI의 LLM을 모두 사용할 수 있습니다.
내장 된 Sklearn 호환 벡터즈기가 많이있는 BELLETTER를 시도하는 것이 좋습니다.
pip install embetter from embetter . text import SentenceEncoder
from neofuzz import Process
# Here we will use a pretrained Bert sentence encoder as vectorizer
vectorizer = SentenceEncoder ( "all-distilroberta-v1" )
# Then we make a process with the language model
process = Process ( vectorizer , metric = "cosine" )
# Remember that the options STILL have to be indexed even though you have a pretrained vectorizer
process . index ( options )