Skip to main content

A Generic Sentence Embedding Library

In natural language processing, we need to vectorize or encode text data to let machine proocess it. In the past, we mostly use encoders such as one-hot, term frequency, and TF-IDF (normalized term frequency). There are many challenges with these techniques that you can read here. In the recent years, the deep learning advancements give us opportunity to encode sentences or words in more meaningful format. The word2vec library was one of the major advancement in this field. Or, the BERT language model provides us a powerful sentence encoders that can be used in many projects.

The sentence embedding or encoding is an important step of many NLP projects. Plus, we believe that a flexible sent2vec library is needed to build a prototype fast. That is why we have initiated this project. In the early releases, you will have access to the standard encoders. We will add more curated techniques in the later releases. Hope you can use this library in your exciting NLP projects.

Library

The library requires the following libraries:

  • transformers
  • pandas
  • numpy
  • torch

Install

It can be installed using pip:

pip install sent2vec

Usage

This is how to initialize the library and provide the data.

from sent2vec.vectorizer import Vectorizer

sentences = [
    "This is an awesome book to learn NLP.",
    "DistilBERT is an amazing NLP library.",
    "We can interchangeably use embedding, encoding, or vectorizing.",
]
vectorizer = Vectorizer(sentences)

If you want to use the pre-trained DistilBertModel, you must use the code below.

vectors = vectorizer.sent2vec_bert()

Now, you can compute distance between vectors[0] and vectors[1] as well as distance between vectors[0] and vectors[2]. You can see that the third sentence is different from other sentences.

And, that's pretty much it!

Metadata

Release files for sent2vec 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sent2vec 0.0.2
File Size Uploaded Provenance Actions
sent2vec-0.0.2.tar.gz 3.3 kB Without provenance Details for sent2vec-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sent2vec 0.0.2
File Interpreter ABI Platform Actions
sent2vec-0.0.2-py3-none-any.whl Python 3 none any Details for sent2vec-0.0.2-py3-none-any.whl

Total release size: 7.0 kB

Release files / sent2vec-0.0.2.tar.gz

Download URL sent2vec-0.0.2.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b049568ece787912c5b30a615fd1f417472c43b9126a9106647eb08ec05cddd3
BLAKE2b-256 checksum
How to use checksums
7a3db4bfcadd3ef69d251292ad3a5db756822dd41983173e0d8d03c9403cebe2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.3

Release files / sent2vec-0.0.2-py3-none-any.whl

Download URL sent2vec-0.0.2-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
86bbfd2c1c977d0b712a92d2533ed94f6578efa458cb86be3f38cea29a98c504
BLAKE2b-256 checksum
How to use checksums
f9bad58c3d70bee5473f20eb4a82132b090a555e1afb18b5c0bfa6e1c2f3f054
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.3

Security for sent2vec 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page