{"id":13738442,"url":"https://github.com/koaning/embetter","last_synced_at":"2025-05-14T23:04:36.650Z","repository":{"id":45777468,"uuid":"423194667","full_name":"koaning/embetter","owner":"koaning","description":"just a bunch of useful embeddings for scikit-learn pipelines","archived":false,"fork":false,"pushed_at":"2025-03-24T20:37:58.000Z","size":7439,"stargazers_count":497,"open_issues_count":19,"forks_count":17,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-14T12:18:21.742Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://koaning.github.io/embetter/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koaning.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-10-31T16:05:10.000Z","updated_at":"2025-04-29T05:33:40.000Z","dependencies_parsed_at":"2024-11-29T03:09:44.676Z","dependency_job_id":"d053240a-7405-4abd-a906-db962729309d","html_url":"https://github.com/koaning/embetter","commit_stats":{"total_commits":294,"total_committers":11,"mean_commits":"26.727272727272727","dds":0.1768707482993197,"last_synced_commit":"62ec9083a28df272a177a9a9fc5a090cd636638b"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koaning%2Fembetter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koaning%2Fembetter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koaning%2Fembetter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koaning%2Fembetter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koaning","download_url":"https://codeload.github.com/koaning/embetter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243358,"owners_count":22038046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T03:02:22.612Z","updated_at":"2025-05-14T23:04:31.638Z","avatar_url":"https://github.com/koaning.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\n# embetter\n\n\u003e \"Just a bunch of useful embeddings for scikit-learn pipelines, to get started quickly.\"\n\n\u003cimg src=\"https://raw.githubusercontent.com/koaning/embetter/main/docs/images/icon.png\" width=\"125\" height=\"125\" align=\"right\" /\u003e\n\n\u003cbr\u003e \n\nEmbetter 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](https://www.youtube.com/watch?v=gDk7_f3ovIk). It's also meant to play nice with [bulk](https://github.com/koaning/bulk) and [scikit-partial](https://github.com/koaning/scikit-partial) but it can also be used together with your favorite ANN solution like [lancedb](https://lancedb.github.io/lancedb/).\n\n## Install \n\nYou can install via pip.\n\n```\npython -m pip install embetter\n```\n\nMany of the embeddings are optional depending on your use-case, so if you\nwant to nit-pick to download only the tools that you need: \n\n```\npython -m pip install \"embetter[text]\"\npython -m pip install \"embetter[spacy]\"\npython -m pip install \"embetter[sense2vec]\"\npython -m pip install \"embetter[gensim]\"\npython -m pip install \"embetter[bpemb]\"\npython -m pip install \"embetter[vision]\"\npython -m pip install \"embetter[all]\"\n```\n\n## API Design \n\nThis is what's being implemented now. \n\n```python\n# Helpers to grab text or image from pandas column.\nfrom embetter.grab import ColumnGrabber\n\n# Representations/Helpers for computer vision\nfrom embetter.vision import ImageLoader, TimmEncoder, ColorHistogramEncoder\n\n# Representations for text\nfrom embetter.text import SentenceEncoder, MatryoshkaEncoder, Sense2VecEncoder, BytePairEncoder, spaCyEncoder, GensimEncoder, TextEncoder\n\n# Representations from multi-modal models\nfrom embetter.multi import ClipEncoder\n\n# Finetuning components \nfrom embetter.finetune import FeedForwardTuner, ContrastiveTuner, ContrastiveLearner, SbertLearner\n\n# External embedding providers, typically needs an API key\nfrom embetter.external import CohereEncoder, OpenAIEncoder\n```\n\nAll of these components are scikit-learn compatible, which means that you\ncan apply them as you would normally in a scikit-learn pipeline. Just be aware\nthat these components are stateless. They won't require training as these \nare all pretrained tools. \n\n## Text Example\n\nTo run this example, make sure that you `pip install 'embetter[sbert]'`. \n\n```python\nimport pandas as pd\nfrom sklearn.pipeline import make_pipeline \nfrom sklearn.linear_model import LogisticRegression\n\nfrom embetter.grab import ColumnGrabber\nfrom embetter.text import SentenceEncoder\n\n# This pipeline grabs the `text` column from a dataframe\n# which then get fed into Sentence-Transformers' all-MiniLM-L6-v2.\ntext_emb_pipeline = make_pipeline(\n  ColumnGrabber(\"text\"),\n  SentenceEncoder('all-MiniLM-L6-v2')\n)\n\n# This pipeline can also be trained to make predictions, using\n# the embedded features. \ntext_clf_pipeline = make_pipeline(\n  text_emb_pipeline,\n  LogisticRegression()\n)\n\ndataf = pd.DataFrame({\n  \"text\": [\"positive sentiment\", \"super negative\"],\n  \"label_col\": [\"pos\", \"neg\"]\n})\nX = text_emb_pipeline.fit_transform(dataf, dataf['label_col'])\ntext_clf_pipeline.fit(dataf, dataf['label_col']).predict(dataf)\n```\n\n## Image Example\n\nThe goal of the API is to allow pipelines like this: \n\n```python\nimport pandas as pd\nfrom sklearn.pipeline import make_pipeline \nfrom sklearn.linear_model import LogisticRegression\n\nfrom embetter.grab import ColumnGrabber\nfrom embetter.vision import ImageLoader\nfrom embetter.multi import ClipEncoder\n\n# This pipeline grabs the `img_path` column from a dataframe\n# then it grabs the image paths and turns them into `PIL.Image` objects\n# which then get fed into CLIP which can also handle images.\nimage_emb_pipeline = make_pipeline(\n  ColumnGrabber(\"img_path\"),\n  ImageLoader(convert=\"RGB\"),\n  ClipEncoder()\n)\n\ndataf = pd.DataFrame({\n  \"img_path\": [\"tests/data/thiscatdoesnotexist.jpeg\"]\n})\nimage_emb_pipeline.fit_transform(dataf)\n```\n\n## Batched Learning \n\nAll of the encoding tools you've seen here are also compatible\nwith the [`partial_fit` mechanic](https://scikit-learn.org/0.15/modules/scaling_strategies.html#incremental-learning) \nin scikit-learn. That means\nyou can leverage [scikit-partial](https://github.com/koaning/scikit-partial)\nto build pipelines that can handle out-of-core datasets. \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoaning%2Fembetter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoaning%2Fembetter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoaning%2Fembetter/lists"}