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


Installation

pip install semantic_counter

Usage

from semantic_counter.semantic_vectorizer import SemanticCountVectorizer 
sentences = ['this is a test sentences','this is another test sentence']
svect = SemanticCountVectorizer(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.3.tar.gz (3.5 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.3-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: semantic_counter-0.0.3.tar.gz
  • Upload date:
  • Size: 3.5 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.3.tar.gz
Algorithm Hash digest
SHA256 bc0a666de417899d7fa843d89d45b257a9285c465d552d65bc1a76a0def64fdb
MD5 4b1ffec646c6b6c43c03d02ae1f8ce7f
BLAKE2b-256 1f1c96cac0507a1b3e754dc4d37df23287eac0af5c94a6be4eb535acf75c6df5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for semantic_counter-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 855d8d8d0bff8975573ec5039d8c2599b753b2b5e2bbb0af35d73455fd2b126f
MD5 62eaaf73f7c89dbc4d3169a78f44ce7f
BLAKE2b-256 423ac0f896fd5319c91208f995f78b6b8df39de983c6cce6c471758b60961882

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