Skip to main content

High-level API for creating sentence and token embeddings

Project description

embedders

With embedders, you can easily convert your text 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.

How to install

You can set up this library via either running pip install embedders, or via cloning this repository and running pip install -r requirements.txt in your repository.

This library uses spaCy for tokenization; to apply it, please download the respective language model first.

Caution: We currently have this tested for Python 3 up to Python 3.9. If your installation runs into issues, please contact us.

Example

Calculating sentence embeddings

from embedders.classification.contextual import TransformerSentenceEmbedder
from embedders.classification.reduce import PCASentenceReducer

corpus = [
    "I went to Cologne in 2009",
    "My favorite number is 41",
    ...
]

embedder = TransformerSentenceEmbedder("bert-base-cased")
embeddings = embedder.encode(corpus) # contains a list of shape [num_texts, embedding_dimension]

# if the dimension is too large, you can also apply dimensionality reduction
reducer = PCASentenceReducer(embedder)
embeddings_reduced = reducer.fit_transform(corpus)

Calculating token embeddings

from embedders.extraction.count_based import CharacterTokenEmbedder
from embedders.extraction.reduce import PCATokenReducer

corpus = [
    "I went to Cologne in 2009",
    "My favorite number is 41",
    ...
]

embedder = CharacterTokenEmbedder("en_core_web_sm")
embeddings = embedder.encode(corpus) # contains a list of ragged shape [num_texts, num_tokens (text-specific), embedding_dimension]

# if the dimension is too large, you can also apply dimensionality reduction
reducer = PCATokenReducer(embedder)
embeddings_reduced = reducer.fit_transform(corpus)

How to contribute

Currently, the best way to contribute is via adding issues for the kind of transformations you like and starring this repository :-)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

embedders-0.0.2-py2.py3-none-any.whl (8.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file embedders-0.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: embedders-0.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.7

File hashes

Hashes for embedders-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9bdf8d81794731b800e2c4bcb30fcb36766b541d64a8c0fb7ae87413d6b77d1b
MD5 473190d299cabdd40926305c89d7ae6a
BLAKE2b-256 98585d0b3faf81b0226dc0956bd5e7cb3df1b6dc057a04ead9c329f43076d35a

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