Skip to main content

A wrapper around CountVectorizer which counts semantically similar tokens

Project description

Wrapper around CountVectorizer to count phrases based on semantic similarity


SemanticCountVectorizer extends CountVectorizer by counting the frequency of semantically similar tokens. This is useful when searching for frequency of similar but not exact terms.

SemanticCountVectorizer uses sentence_transformers to compute embedding of n-grams and then clusters similar terms using Agglomerative Clustering using cosine similarity as the similarity metric


Usage

from semantic_vectorizer import SemanticCountVectorizer 
sentences = ['this is a test sentences','this is another test sentence']
svect = SemanticVectorizer(embedding_model_name='all-MiniLM-L6-v2', similarity_threshold=0.7, ngram_range=(3,3))
counts=svect.fit_transform(sentences)

Arguments

  • embedding_model_name: Name of the sentence_transformer pretrained model to use. Refer to package website for a list of available models
  • similarity_threshold: value between 0-1 which indicates minimum cosine similarity needed to group tokens.
  • Arguments of sklearn's CountVectorizer as listed here

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

semantic_counter-0.0.1.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

semantic_counter-0.0.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file semantic_counter-0.0.1.tar.gz.

File metadata

  • Download URL: semantic_counter-0.0.1.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for semantic_counter-0.0.1.tar.gz
Algorithm Hash digest
SHA256 463e9d0b4d2e2762c838f4db95282436e5d22db49d2d9e82bbc4267e15a879d9
MD5 5b81541d108a8f67b4c3c7a7fa6c5946
BLAKE2b-256 de0491169f2400e0be350feaf5a155a1615435a5e0e887ac16911dffb95cfc6c

See more details on using hashes here.

File details

Details for the file semantic_counter-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for semantic_counter-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 97d82bdeed0d14565ef6d4d274e8d0e5eabb6c99966d3c6196f4678ca2a0c6b6
MD5 58635adff387679d75b53fdd44066048
BLAKE2b-256 3243768e68a7f30eda81eb70c750ad7407a3d27961a2eab17b403d41174c55e4

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