Templates for PolyFuzz string matching and similarity models.
Project description
Sinapsis PolyFuzz
Templates for fuzzy string matching and semantic similarity using PolyFuzz
🐍 Installation • 🚀 Features • 📚 Usage example • 📙 Documentation • 🔍 License
Sinapsis PolyFuzz provides a powerful and flexible implementation for fuzzy string matching and semantic similarity matching. It integrates PolyFuzz models into Sinapsis templates, enabling string matching pipelines with various backends including TF-IDF, Edit Distance, RapidFuzz, Sentence-BERT, Flair (🤗 Transformers, FastText, GloVe), Gensim, spaCy, and Universal Sentence Encoder.
🐍 Installation
Install using your package manager of choice. We encourage the use of uv
Example with uv:
uv pip install sinapsis-polyfuzz --extra-index-url https://pypi.sinapsis.tech
or with raw pip:
pip install sinapsis-polyfuzz --extra-index-url https://pypi.sinapsis.tech
Optional Dependencies
PolyFuzz supports multiple embedding backends. Install the extras you need:
# Sentence-BERT embeddings
uv pip install "sinapsis-polyfuzz[sbert]" --extra-index-url https://pypi.sinapsis.tech
# Flair embeddings
uv pip install "sinapsis-polyfuzz[flair]" --extra-index-url https://pypi.sinapsis.tech
# Word2Vec embeddings
uv pip install "sinapsis-polyfuzz[gensim]" --extra-index-url https://pypi.sinapsis.tech
# Universal Sentence Encoder
uv pip install "sinapsis-polyfuzz[use]" --extra-index-url https://pypi.sinapsis.tech
# FastText embeddings
uv pip install "sinapsis-polyfuzz[fast]" --extra-index-url https://pypi.sinapsis.tech
# spaCy for text processing
uv pip install "sinapsis-polyfuzz[spacy]" --extra-index-url https://pypi.sinapsis.tech
# Install all extras
uv pip install "sinapsis-polyfuzz[all]" --extra-index-url https://pypi.sinapsis.tech
🚀 Features
Templates Supported
This module includes multiple templates tailored for different fuzzy matching approaches:
- TFIDFWrapper: Classic TF-IDF based fuzzy string matching using character n-grams and cosine similarity.
- EditDistanceWrapper: Edit distance-based matching with customizable distance functions.
- RapidFuzzWrapper: Fast implementation of fuzzy string matching (fuzzywuzzy alternative) with MIT license.
- EmbeddingsWrapper: Flair-based embeddings matching supporting all 🤗 Transformers models.
- SentenceTransformersWrapper: Sentence-BERT embeddings for semantic similarity using sentence-transformers.
- GensimEmbeddingsWrapper: Word embeddings matching using Gensim (e.g., Word2Vec, GloVe).
- SpacyEmbeddingsWrapper: spaCy embeddings for linguistic similarity matching.
- USEEmbeddingsWrapper: Universal Sentence Encoder (USE) for deep semantic similarity using TensorFlow Hub.
- *PairWrapper (e.g. TFIDFPairWrapper, EditDistancePairWrapper, RapidFuzzPairWrapper, ...): Paired-matching variants of every matcher. Instead of a static
to_list, they match a column of one DataFramePacket against a column of another (selected bysourceor index) and append aFrom/To/Similaritymatches packet. They short-circuit (return the container unchanged) when the reference column is empty, and expose a backend-independentmin_similaritypost-filter that drops weak matches (use this rather than the matcher's own threshold, which only some backends honor). For short alphanumeric codes, RapidFuzzPairWrapper is the most reliable — unlike n-gram TF-IDF it does not rank a single-character substitution (e.g.KML029→KML028) above a formatting variant (KML029→KML29). - ExactMatch: Splits reference values into exact (normalized) matches against a target column and a non-exact residual. Emits an
exact_matchespacket (From/To/Similarity= 1.0) and ano_exact_matchesresidual packet to feed a downstream fuzzy*PairWrapper.
[!TIP] Use CLI command
sinapsis info --all-template-namesto show a list with all the available Template names installed with Sinapsis PolyFuzz.
🌍 General Attributes
All templates share the following attributes defined in PolyfuzzBaseAttributes:
target_column(str, required): The name of the column in the DataFrame to be used as the source for matching.to_list(list[str], optional): A list of strings to match against. If not provided, the model will match within the target column itself.overwrite(bool, optional): Whether to overwrite the original packet content with results. If False, creates new packets. Defaults toFalse.
[!TIP] Use CLI command
sinapsis info --example-template-config TEMPLATE_NAMEto produce an example Agent config for the Template specified in TEMPLATE_NAME.
For example, for TFIDFWrapper use sinapsis info --example-template-config TFIDFWrapper to produce an example config like:
agent:
name: my_test_agent
templates:
- template_name: InputTemplate
class_name: InputTemplate
attributes: {}
- template_name: TFIDFWrapper
class_name: TFIDFWrapper
template_input: InputTemplate
attributes:
target_column: '`replace_me:<class ''str''>`'
to_list: null
overwrite: false
tfidf_init:
n_gram_range: !!python/tuple
- 3
- 3
clean_string: true
min_similarity: 0.75
top_n: 1
cosine_method: sparse
model_id: null
remove_space_ngrams: true
📚 Usage example
Below is an example YAML configuration for fuzzy string matching using TF-IDF. In this example, we define an agent named my_test_agent and configure a matching template to find similar strings between a source column and a target list.
Config
agent:
name: my_test_agent
description: "Agent utilizing TF-IDF for fuzzy string matching."
templates:
- template_name: InputTemplate
class_name: InputTemplate
attributes: {}
- template_name: CSVDatasetReader
class_name: CSVDatasetReader
template_input: InputTemplate
attributes:
root_dir: "artifacts"
path_to_csv: "example.csv"
store_as_time_series: false
- template_name: TFIDFWrapper
class_name: TFIDFWrapper
template_input: CSVDatasetReader
attributes:
target_column: "from_list"
to_list:
- "Apple Inc"
- "Microsoft Corporation"
- "Google LLC"
- "Amazon.com"
- "Netflix Inc"
- "Tesla Motors"
- "Meta Platforms"
- "NVIDIA Corp"
- "Intel Corp"
overwrite: true
tfidf_init:
n_gram_range:
- 3
- 3
clean_string: true
min_similarity: 0.5
top_n: 1
cosine_method: sparse
remove_space_ngrams: true
This configuration defines an agent and a sequence of templates to perform fuzzy string matching:
- InputTemplate: Entry point for the pipeline.
- CSVDatasetReader: Reads a CSV file containing strings to match (from sinapsis-data-readers).
- TFIDFMatcher: Performs fuzzy matching using TF-IDF with character n-grams, minimum similarity of 0.5, returning top 1 matches.
[!IMPORTANT] The
CSVDatasetReadertemplate corresponds to sinapsis-data-readers. If you want to use the example, please make sure you install the package.The
to_listattribute specifies the reference strings to match against. If omitted, the model will match strings within the target column against themselves.
To run the config, use the CLI:
sinapsis run name_of_config.yml
📙 Documentation
Documentation for this and other sinapsis packages is available on the sinapsis website
Tutorials for different projects within sinapsis are available at sinapsis tutorials page
🔍 License
This project is licensed under the AGPLv3 license, which encourages open collaboration and sharing. For more details, please refer to the LICENSE file.
For commercial use, please refer to our official Sinapsis website for information on obtaining a commercial license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sinapsis_polyfuzz-0.1.0.tar.gz.
File metadata
- Download URL: sinapsis_polyfuzz-0.1.0.tar.gz
- Upload date:
- Size: 27.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eebf4b234d696493c1c501d4ab7fca7a8402bab2f489aa2a7932377f2b3959b9
|
|
| MD5 |
5633d5cba94fc26d934537857da63d0a
|
|
| BLAKE2b-256 |
12f5397ac3d6c5183741af120b48deba153814b64b9bbe99b3731493f9d5163b
|
File details
Details for the file sinapsis_polyfuzz-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sinapsis_polyfuzz-0.1.0-py3-none-any.whl
- Upload date:
- Size: 27.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ad3e5011a7c117ad8a5fa3e238b7894da3cafcff697f1d24e0969dc7599d213
|
|
| MD5 |
ef82902d7cd794fec9130019d32d865d
|
|
| BLAKE2b-256 |
67fd338276c2a6babaee0f8d59689c57c5d4733f06db39e19f4e63aae2a934a5
|