Labelled Topic Clustering
Labelled Topic Clustering is as the name suggests, feed it an array of sentences and it will cluster them with human-readable names.
The aim of this project is to make it as easy-as-possible to:
- generate topic clusters on a text dataset using a cosine-similarity approach.
- get human-readable labels for those clusters
Installation
To use the TopicClusterer class, you need to install the required packages. Assuming you have a package manager like pip, you can install the dependencies as follows:
pip install labelled-topic-clustering
Usage
- Initialize the TopicClusterer:
from topic_clusterer import TopicClusterer
hf_token = "your_hugging_face_token"
model = "your_model_name"
clusterer = TopicClusterer(hf_token, model, debug=True)
- Get clusters:
sentences = [
"the weather is great",
"This is some perfect weather",
"we're having some really good weather",
"my dog ate my homework",
"why do dogs love homework?",
"dog keeps devouring my homework"
]
clusters = clusterer.get_clusters(sentences)
Example Output
[[0, 1, 2], [3, 4, 5]]
clusters will be a 2d array representing clusters with sentence indicies for the original dataset
- Get labels from clusters:
clusters_labelled = clusterer.get_labels_from_clusters(clusters, sentences)
Example Output
{'Weather great perfect': [0, 1, 2], 'Dog eat homework': [3, 4, 5]}
clusters_labelled is a dictionary where the keys are topic labels, and the values are arrays of sentence indices corresponding to the original dataset.
You can also just get it all at once:
# Get clusters with labels
labelled_clusters = clusterer.get_clusters_with_labels(sentences)
print(labelled_clusters)
Looing Forward
I have done virtually no performance testing as I wrote this once and it was all I needed for a side project.
Some ideas to work on:
- Allow custom tokenizers
- Benchmark performance on large datasets
- Allow for feature extraction locally
Metadata
Release files for labelled-topic-clustering 1.0.19
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| labelled-topic-clustering-1.0.19.tar.gz | 6.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| labelled_topic_clustering-1.0.19-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.4 kB
Release files / labelled-topic-clustering-1.0.19.tar.gz
| Download URL | labelled-topic-clustering-1.0.19.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
50574e53b901152146d9789f7794bc9dd9a7483e9cd74b688394abd6f6367c88
|
|
BLAKE2b-256 checksum How to use checksums |
c137f11f95a8068c4b0e3f63cea5649a000b241c8f57132f1bc4b660a4cf2d82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|
Release files / labelled_topic_clustering-1.0.19-py3-none-any.whl
| Download URL | labelled_topic_clustering-1.0.19-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
41a4458ef03bacecfbac26e7942f72a4bc6dd7f7fd74ad52ce0dfeda84a92bc6
|
|
BLAKE2b-256 checksum How to use checksums |
9b7059ebecbda4fd56aa34e821c2d69ea8fabf0f5edbd71934f17ff9f984ed89
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|