Skip to main content

How to represent sentences in a high-dimensional vector space, a.k.a., sentence embedding.

Project description

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.


The library requires the following libraries:

  • transformers
  • pandas
  • numpy
  • torch


It can be installed using pip:

pip install sent2vec


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 should use the code below.

vectors = vectorizer.sent2vec_bert()

And, that's pretty much it!

Project details

Download files

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

Source Distribution

sent2vec-0.0.1.tar.gz (3.3 kB view hashes)

Uploaded source

Built Distribution

sent2vec-0.0.1-py3-none-any.whl (3.6 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page