Package: embetter
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 withbulk labelling. It's a also meant to play nice withbulkandscikit-partialbut it can also be used together with your favorite ANN solution likeweaviate,chromadbandhnswlib.InstallYou can install via pip.python -m pip install embetterMany 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[gensim]"
python -m pip install "embetter[bpemb]"
python -m pip install "embetter[vision]"
python -m pip install "embetter[all]"API DesignThis is what's being implemented now.# Helpers to grab text or image from pandas column.fromembetter.grabimportColumnGrabber# Representations/Helpers for computer visionfromembetter.visionimportImageLoader,TimmEncoder,ColorHistogramEncoder# Representations for textfromembetter.textimportSentenceEncoder,Sense2VecEncoder,BytePairEncoder,spaCyEncoder,GensimEncoder# Representations from multi-modal modelsfromembetter.multiimportClipEncoder# Finetuning componentsfromembetter.finetuneimportFeedForwardTuner,ContrastiveTuner,ContrastiveLearner,SbertLearner# External embedding providers, typically needs an API keyfromembetter.externalimportCohereEncoder,OpenAIEncoderAll 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 Exampleimportpandasaspdfromsklearn.pipelineimportmake_pipelinefromsklearn.linear_modelimportLogisticRegressionfromembetter.grabimportColumnGrabberfromembetter.textimportSentenceEncoder# 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 ExampleThe goal of the API is to allow pipelines like this:importpandasaspdfromsklearn.pipelineimportmake_pipelinefromsklearn.linear_modelimportLogisticRegressionfromembetter.grabimportColumnGrabberfromembetter.visionimportImageLoader,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 LearningAll of the encoding tools you've seen here are also compatible
with thepartial_fitmechanicin scikit-learn. That means
you can leveragescikit-partialto build pipelines that can handle out-of-core datasets.