An easy to use semantic (soft) querying on pandas dataframes.
Project description
SoftPandas - Semantic Querying for Pandas
Example Usage:
- Let's say we want to get all red and black swim shorts that cost less than 600$
python test.py
Or play with this code:
import pandas as pd
from core.data_types import InputDataType
from core.soft_dataframe import SoftDataFrame
from embedders.clip_embedder import OpenClipEmbedder
from embedders.sentence_transformer_embedder import SentenceTransformerEmbedder
from sklearn.metrics.pairwise import cosine_similarity
lang_model = SentenceTransformerEmbedder('thenlper/gte-small',
metric=cosine_similarity, threshold=0.82, device="cpu")
vision_model = OpenClipEmbedder('ViT-B-32-256', metric=cosine_similarity,
threshold=0.25, pretrained="datacomp_s34b_b86k")
df = pd.read_csv("sample_data/men-swimwear.csv")
df = SoftDataFrame(df, soft_columns={'NAME': InputDataType.text,
'DESCRIPTION & COLOR': InputDataType.text,
'FABRIC': InputDataType.text},
models={InputDataType.text: lang_model, InputDataType.image: vision_model}
)
relevant_price_items = df.query("PRICE < 600")
df_filtered_desc = relevant_price_items.soft_query("'DESCRIPTION & COLOR' ~= 'red and black swim shorts'")
df = df_filtered_desc.add_soft_columns({'IMAGE': InputDataType.image}, inplace=False)
df_filtered_image = df.soft_query("'IMAGE' ~= 'red and black swim shorts'")
print(df_filtered_image)
- Saving and loading:
relevant_price_items.to_pickle("relevant_items.p")
a = pd.read_pickle("relevant_items.p")
TODO:
Add saving methods for SoftDataFrameMethod for adding new columns- Add dealing with Nans
if a column is Nan, just ignore it- If value isn't there, it shouldn't pass condition - similar to normal querying
- Batching of initial encoding -
- don't do it one by one
use device (cuda, mps, tpu, etc.)
- make into a package
- requirements file
- Add image
Long Term Goals:
- Add automatic feature extraction from images into new columns
- allows hard querying using visual data!
- Add ability to soft query based on Image
- Expand to more modalities
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
softpandas-0.1.tar.gz
(16.3 kB
view details)
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
softpandas-0.1-py3-none-any.whl
(15.6 kB
view details)
File details
Details for the file softpandas-0.1.tar.gz.
File metadata
- Download URL: softpandas-0.1.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20afa15880c0aee168966a12cb87035a1b49e946c28191c20ecab308f9721e4a
|
|
| MD5 |
7abecd766b64d3547bc244fff75ecf34
|
|
| BLAKE2b-256 |
5d673e53e7d14f46fea5931ad0fd4607580a5aa7f30165c22594f003462949d3
|
File details
Details for the file softpandas-0.1-py3-none-any.whl.
File metadata
- Download URL: softpandas-0.1-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
802d60dcb2fedddf0c2ee99904269005a241f8c309f0e7455e072ff28657c541
|
|
| MD5 |
3ea53aa0af9a42e204db6b85eaf6287f
|
|
| BLAKE2b-256 |
cf9ef4eda61f9fa6f2bb4f140cb02c25ed1ec9ffd626bc3bd1f91f437d8b8164
|