Skip to main content

Package to calculate the similarity score of two sentences

Project description

Sentence Similarity

Package to calculate the similarity score between two sentences

Examples

Using Transformers

from sentence_similarity import sentence_similarity
sentence_a = "paris is a beautiful city"
sentence_b = "paris is a grogeous city"

Supported Models

You can access some of the official model through the sentence_similarity class. However, you can directly type the HuggingFace's model name such as bert-base-uncased or distilbert-base-uncased when instantiating a sentence_similarity.

See all the available models at huggingface.co/models.

model=sentence_similarity(model_name='distilbert-base-uncased',embedding_type='cls_token_embedding')

BERT is bidirectional, the [CLS] is encoded including all representative information of all tokens through the multi-layer encoding procedure. The representation of [CLS] is individual in different sentences. Set embedding_type to cls_token_embedding, To compute the similarity score between two sentences based on [CLS] token.

paper link (https://arxiv.org/pdf/1810.04805.pdf)

score=model.get_score(sentence_a,sentence_b,metric="cosine")
print(score)

Available metric are euclidean, manhattan, minkowski, cosine score.

Using Sentence Transformers

from sentence_similarity import sentence_similarity
sentence_a = "paris is a beautiful city"
sentence_b = "paris is a grogeous city"

Supported Models

You can access all the pretrained models of Sentence-Transformers

See all the available models at sbert/models.

model=sentence_similarity(model_name='distilbert-base-uncased',embedding_type='sentence_embedding')

Sentence-BERT (SBERT), a modification of the pretrained BERT network that use siamese and triplet network structures to derive semantically meaningful sentence embeddings that can be compared using cosine-similarity. Set embedding_type to sentence_embedding (default embedding_type), To compute the similarity score between two sentences based on sbert.

paper link (https://arxiv.org/pdf/1908.10084.pdf)

score=model.get_score(sentence_a,sentence_b,metric="cosine")
print(score)

Available metric are euclidean, manhattan, minkowski, cosine score.

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

sentence_similarity-1.0.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

sentence_similarity-1.0.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file sentence_similarity-1.0.0.tar.gz.

File metadata

  • Download URL: sentence_similarity-1.0.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for sentence_similarity-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fa7c67fea77e37f1e7fb4a3d46474f8e6eb24573f1b724c5dd3f845d01d4a71e
MD5 a1bc430596e50f89d9137ace13500a22
BLAKE2b-256 be26acc525a2ac2198df7cd1994d518df21d9f7e5c83d7add101adf230da692a

See more details on using hashes here.

File details

Details for the file sentence_similarity-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: sentence_similarity-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for sentence_similarity-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aefb73cce7733e1b95289119aedb9a734c16b1209ead4e9bc5516a8e26087128
MD5 c243e7a5bf78a4c9c15a5243a3368ca5
BLAKE2b-256 f60adf518576521e80a6edc77b10b38207acef3078ccac67dcffb8ff8eb86679

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