Skip to main content

Just a bunch of useful embeddings to get started quickly.

Project description

embetter

"Just a bunch of useful embeddings to get started quickly."


Embetter implements scikit-learn compatible embeddings for computer vision and text. It should make it very easy to quickly build proof of concepts using scikit-learn pipelines and, in particular, should help with bulk labelling. It's a also meant to play nice with bulk and scikit-partial.

Install

You can install via pip.

python -m pip install embetter

Many of the embeddings are optional depending on your use-case, so if you want to nit-pick to download only the tools that you need:

python -m pip install "embetter[text]"
python -m pip install "embetter[sentence-tfm]"
python -m pip install "embetter[spacy]"
python -m pip install "embetter[sense2vec]"
python -m pip install "embetter[bpemb]"
python -m pip install "embetter[vision]"
python -m pip install "embetter[all]"

API Design

This is what's being implemented now.

# Helpers to grab text or image from pandas column.
from embetter.grab import ColumnGrabber

# Representations/Helpers for computer vision
from embetter.vision import ImageLoader, TimmEncoder, ColorHistogramEncoder

# Representations for text
from embetter.text import SentenceEncoder, Sense2VecEncoder, BytePairEncoder

# Finetuning components 
from embetter.finetune import ForwardFinetuner

# External embedding providers, typically needs an API key
from embetter.external import CohereEncoder, OpenAIEncoder

All of these components are scikit-learn compatible, which means that you can apply them as you would normally in a scikit-learn pipeline. Just be aware that these components are stateless. They won't require training as these are all pretrained tools.

Text Example

import pandas as pd
from sklearn.pipeline import make_pipeline 
from sklearn.linear_model import LogisticRegression

from embetter.grab import ColumnGrabber
from embetter.text import SentenceEncoder

# This pipeline grabs the `text` column from a dataframe
# which then get fed into Sentence-Transformers' all-MiniLM-L6-v2.
text_emb_pipeline = make_pipeline(
  ColumnGrabber("text"),
  SentenceEncoder('all-MiniLM-L6-v2')
)

# This pipeline can also be trained to make predictions, using
# the embedded features. 
text_clf_pipeline = make_pipeline(
  text_emb_pipeline,
  LogisticRegression()
)

dataf = pd.DataFrame({
  "text": ["positive sentiment", "super negative"],
  "label_col": ["pos", "neg"]
})
X = text_emb_pipeline.fit_transform(dataf, dataf['label_col'])
text_clf_pipeline.fit(dataf, dataf['label_col']).predict(dataf)

Image Example

The goal of the API is to allow pipelines like this:

import pandas as pd
from sklearn.pipeline import make_pipeline 
from sklearn.linear_model import LogisticRegression

from embetter.grab import ColumnGrabber
from embetter.vision import ImageLoader, TimmEncoder

# This pipeline grabs the `img_path` column from a dataframe
# then it grabs the image paths and turns them into `PIL.Image` objects
# which then get fed into MobileNetv2 via TorchImageModels (timm).
image_emb_pipeline = make_pipeline(
  ColumnGrabber("img_path"),
  ImageLoader(convert="RGB"),
  TimmEncoder("mobilenetv2_120d")
)

dataf = pd.DataFrame({
  "img_path": ["tests/data/thiscatdoesnotexist.jpeg"]
})
image_emb_pipeline.fit_transform(dataf)

Batched Learning

All of the encoding tools you've seen here are also compatible with the partial_fit mechanic in scikit-learn. That means you can leverage scikit-partial to build pipelines that can handle out-of-core datasets.

Available Components

The goal of the library is remain small but to offer a few general tools that might help with bulk labelling in particular, but general scikit-learn pipelines as well.

class link What it does
ColumnGrabber docs dataframeColumnGrabberlist with column contents
SentenceEncoder docs list of textSentenceEncoderembedding array
Sense2VecEncoder docs list of textSense2VecEncoderembedding array
spaCyEncoder docs list of textspaCyEncoderembedding array
BytePairEncoder docs list of textBytePairEncoderembedding array
ImageLoader docs list of pathsImageLoaderlist of PIL images
ColorHistogramEncoder docs list of PIL imagesColorHistogramEncoderembedding array
TimmEncoder docs list of PIL imagesTimmEncoderembedding array
ForwardFinetuner docs array + labelsForwardFinetunerfinetuned array
CohereEncoder docs list of textCohereEncoderembedding array
OpenAIEncoder docs list of textOpenAIEncoderembedding array

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

embetter-0.3.5.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

embetter-0.3.5-py2.py3-none-any.whl (24.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file embetter-0.3.5.tar.gz.

File metadata

  • Download URL: embetter-0.3.5.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.9

File hashes

Hashes for embetter-0.3.5.tar.gz
Algorithm Hash digest
SHA256 dbc303c81526637ec05c46d5fc4fb4ace1b776597d2a14e0f2e82b16a2dd92a2
MD5 2cf3a5af14320f21a8a76f7cfa867f0d
BLAKE2b-256 3ea0f123ecd3f594c4e2655d3fa69b898a763e09cf7a84067b3b919f559dd945

See more details on using hashes here.

File details

Details for the file embetter-0.3.5-py2.py3-none-any.whl.

File metadata

  • Download URL: embetter-0.3.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.9

File hashes

Hashes for embetter-0.3.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bd5da42e104bccbc9c12876ad393adb0da5f1e69a5a93600919cfa6f1b21d909
MD5 7dfc4673c8de1285f0db9c927a540c0d
BLAKE2b-256 9b1f77c8d06bd6d7a410e1f6e4c305a52e2a4297d22f2a69940d31d1adc44bbc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page