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.4.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.4-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: semantic_counter-0.0.4.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.4.tar.gz
Algorithm Hash digest
SHA256 7c322fc7c1bdaa9af944c7cb99fcfacbc2c7f75b1c7a67130628d406a5744d80
MD5 9610802a2da72ffa90fe361790c57cb3
BLAKE2b-256 b02eeb5a16f70917f0b39cc34f3a1e06d67c8a00fcc18e6c6c99417586685271

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for semantic_counter-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ba9a58754062983eab019136eeae69661a7302921a6e850cda9e8b08243f1932
MD5 2b4f0d1dfcb20a8845e859cae991a923
BLAKE2b-256 72f59f4e3c8448d7406a72402d3b6f1bd42a3dba1b88ea50395ce4436a0d6c86

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