The SimilarityChecker module determines the similarity between two items.
Project description
Installation
Run
pip install llm-similarity-checker
This module includes three classes:
- AnalysisMatcher
- NumericMatcher
- AltairGraphComparer
AnalysisMatcher
This class performs sentence comparison using state-of-the-art transformer models in natural language processing (NLP). Leveraging the Hugging Face transformers library, it tokenizes input sentences, extracts embeddings using a pre-trained model, and calculates similarity scores between sentences.
Example:
from similarity_checker import AnalysisMatcher
reference = "Based on the visualization 'Sale Price vs. Unit Profit' and 'Bulk Price vs. Bulk Profit', it appears that there's a positive correlation between price and profit for both individual unit sales and bulk sales."
sentence1 = "Both pricing strategies do not have positive linear relationship with their respective revenues."
sentence2 = "Both pricing strategies have positive linear relationship with their respective revenues."
# Initialize the AnalysisMatcher
matcher = AnalysisMatcher()
# Perform matches for answer_query1
match1 = matcher.match(reference, sentence1)
match2 = matcher.match(reference, sentence2)
# Print results
print("Match results for sentence1:")
print(match1)
print("\nMatch results for sentence2:")
print(match2)
Output:
Match results for sentence1:
(0.24839641153812408, False)
Match results for sentence2:
(0.6842396259307861, True)
NumericMatcher
This class focuses on extracting numerical values from strings and comparing them against target values. It uses regular expressions to locate and normalize numeric values from input strings, handling variations like comma separators.
Example:
sentence = "The top 5 most preferred car brands in the UAE, based on the average proportion across cities, are:\n\n| brand | avg_proportion |\n|:--------------|:-----------------|\n| Nissan | 0.159158 |\n| Toyota | 0.0978399 |\n| Mercedes-Benz | 0.0843513 |\n| Honda | 0.0776763 |\n| BMW | 0.056902 |"
target1 = 0.159
target2 = 0
matcher = NumericMatcher()
print(matcher.match(sentence, target1))
print(matcher.match(sentence, target2))
AltairGraphComparer
This class compares two Altair graphs to determine their similarity.
Example:
chart1 = "{\"config\": {\"view\": {\"continuousWidth\": 400, \"continuousHeight\": 300}}, \"data\": {\"name\": \"data-679d61f96919a9b00678a3858e27aa15\"}, \"mark\": \"bar\", \"encoding\": {\"tooltip\": [{\"field\": \"month\", \"type\": \"nominal\"}, {\"field\": \"booking_duration\", \"type\": \"quantitative\"}], \"x\": {\"axis\": {\"labelAngle\": -45, \"title\": \"Month\"}, \"field\": \"month\", \"sort\": null, \"type\": \"nominal\"}, \"y\": {\"field\": \"booking_duration\", \"title\": \"Average Booking Duration (Days)\", \"type\": \"quantitative\"}}, \"selection\": {\"selector001\": {\"type\": \"interval\", \"bind\": \"scales\", \"encodings\": [\"x\", \"y\"]}}, \"title\": \"Average Booking Duration by Month\", \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.17.0.json\", \"datasets\": {\"data-679d61f96919a9b00678a3858e27aa15\": [{\"month\": \"January\", \"booking_duration\": -778.581308411215, \"month_order\": 0}]}}"
chart2 = "{\"config\": {\"view\": {\"continuousWidth\": 400, \"continuousHeight\": 300}}, \"data\": {\"name\": \"data-71fd4bd6411150f723ef9e15bf55c9ea\"}, \"mark\": \"bar\", \"encoding\": {\"tooltip\": [{\"field\": \"month\", \"type\": \"nominal\"}, {\"field\": \"booking_duration\", \"type\": \"quantitative\"}], \"x\": {\"axis\": {\"labelAngle\": -45, \"title\": \"Month\"}, \"field\": \"month\", \"sort\": null, \"type\": \"nominal\"}, \"y\": {\"field\": \"booking_duration\", \"title\": \"Average Booking Duration (Days)\", \"type\": \"quantitative\"}}, \"selection\": {\"selector001\": {\"type\": \"interval\", \"bind\": \"scales\", \"encodings\": [\"x\", \"y\"]}}, \"title\": \"Average Booking Duration by Month\", \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.17.0.json\", \"datasets\": {\"data-71fd4bd6411150f723ef9e15bf55c9ea\": [{\"month\": \"January\", \"booking_duration\": 1.8288770053475936, \"month_order\": 0}]}}"
matcher = AltairGraphComparer()
matcher.match(chart1, chart2)
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 llm_similarity_checker-0.1.1.tar.gz.
File metadata
- Download URL: llm_similarity_checker-0.1.1.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fe66af5a96a1dda8e923da00b0c813f92f8af73851e92a73bd65b967ba022aa
|
|
| MD5 |
12773a6d8bab6ef8583b20d15a02543e
|
|
| BLAKE2b-256 |
388d67ef56be8853d05b54c45297404258855ff7ff02418bac2e28d96d598ade
|
File details
Details for the file llm_similarity_checker-0.1.1-py3-none-any.whl.
File metadata
- Download URL: llm_similarity_checker-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
704e12d9ce8a9192be99b51ffa9f4427a0ad9e2d869d8ffd3bf1433d996e2bdd
|
|
| MD5 |
51abe9d845181fa89f82c7cdf2e66acd
|
|
| BLAKE2b-256 |
b41ea45f3d4cf20f7560b3c8a3bccb0a884be2942468319fc1aea6f2dca020a7
|