Package: embedders
⚗️ embeddersWithembedders, you can easily convert your texts into sentence- or token-level embeddings within a few lines of code. Use cases for this include similarity search between texts, information extraction such as named entity recognition, or basic text classification.PrerequisitesThis library usesspaCyfor tokenization; to apply it, please download therespective language modelfirst.InstallationYou can set up this library via either running$ pip install embedders, or via cloning this repository and running$ pip install -r requirements.txtin your repository.A sample installation would be:$ conda create --name embedders python=3.9
$ conda activate embedders
$ pip install embedders
$ python -m spacy download en_core_web_smUsageOnce you installed the package, you can apply the embedders with a few lines of code. You can apply embedders on sentence- or token-level.Sentence embeddings"Wow, what a cool tool!"is embedded to[
    2.453, 8.325, ..., 3.863
]Currently, we provide the following sentence embeddings:PathNameEmbeds documents using ...embedders.classification.contextualHuggingFaceSentenceEmbedderlarge, pre-trained transformers fromhttps://huggingface.coembedders.classification.contextualOpenAISentenceEmbedderlarge, pre-trained transformers fromhttps://openai.comembedders.classification.contextualCohereSentenceEmbedderlarge, pre-trained transformers fromhttps://cohere.comembedders.classification.count_basedBagOfCharsSentenceEmbedderplain Bag of Chars approachembedders.classification.count_basedBagOfWordsSentenceEmbedderplain Bag of Words approachembedders.classification.count_basedTfidfSentenceEmbedderTerm Frequency - Inverse Document Frequency (TFIDF) approachToken embeddings"Wow, what a cool tool!"is embedded to[
    [8.453, 1.853, ...],
    [3.623, 2.023, ...],
    [1.906, 9.604, ...],
    [7.306, 2.325, ...],
    [6.630, 1.643, ...],
    [3.023, 4.974, ...]
]Currently, we provide the following token embeddings:PathNameEmbeds documents using ...embedders.extraction.contextualTransformerTokenEmbedderlarge, pre-trained transformers fromhttps://huggingface.coembedders.extraction.count_basedBagOfCharsTokenEmbedderplain Bag of Characters approachYou can choose the embedding category depending on your task at hand. To implement them, you can just grab one of the available methods and apply them to your text corpus as follows (shown for sentence embeddings, but the same is possible for token):fromembedders.classification.contextualimportTransformerSentenceEmbedderfromembedders.classification.reduceimportPCASentenceReducercorpus=["I went to Cologne in 2009","My favorite number is 41",# ...]embedder=TransformerSentenceEmbedder("bert-base-cased")embeddings=embedder.fit_transform(corpus)# contains a list of shape [num_texts, embedding_dimension]Sometimes, you want to reduce the size of the embeddings you received. To do so, you can easily wrap your embedder with some dimensionality reduction technique.# if the dimension is too large, you can also apply dimensionality reductionreducer=PCASentenceReducer(embedder)embeddings_reduced=reducer.fit_transform(corpus)Currently, we provide the following dimensionality reductions:PathNameDescriptionembedders.classification.reducePCASentenceEmbedderWraps embedder into a principial component analysis to reduce the dimensionalityembedders.extraction.reducePCATokenEmbedderWraps embedder into a principial component analysis to reduce the dimensionalityPre-trained embeddersWith growing availability of large, pre-trained models such as provided by🤗 Hugging Face, embedding complex sentences in a wide variety of languages and domains becomes much more applicable. If you want to make use of transformer models, you can just use the configuration string of the respective model, which will automatically pull the correct model for the🤗 Hugging Face Hub.ContributingContributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make aregreatly appreciated.If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!Fork the ProjectCreate your Feature Branch (git checkout -b feature/AmazingFeature)Commit your Changes (git commit -m 'Add some AmazingFeature')Push to the Branch (git push origin feature/AmazingFeature)Open a Pull RequestAnd please don't forget to leave a ⭐ if you like the work!LicenseDistributed under the Apache 2.0 License. See LICENSE.txt for more information.ContactThis library is developed and maintained bykern.ai. If you want to provide us with feedback or have some questions, don't hesitate to contact us. We're super happy to help ✌️