Word-Based Soft Clustering (WBSC)ο
An efficient word-based algorithm for discovering overlapping topics in documents.
π Overviewο
The Word-Based Soft Clustering (WBSC) algorithm identifies overlapping themes in a collection of documents. It operates by first clustering the words used in the documents and then hierarchically merging clusters that contain similar sets of documents. This approach allows a single document to belong to multiple clusters, effectively capturing multi-topic documents.
βοΈ Class Definitionο
class soft_clustering.WBSC(
similarity_threshold: float = 0.33,
min_doc_freq: int = 2,
max_doc_freq_ratio: float = 0.5
)
π Parametersο
Parameter |
Type |
Default |
Description |
|---|---|---|---|
similarity_threshold |
|
|
Tanimoto similarity score required to merge two clusters. |
min_doc_freq |
|
|
The minimum number of documents a word must appear in to be considered. |
max_doc_freq_ratio |
|
|
The maximum ratio of documents a word can appear in to be considered. |
π Usage Examplesο
from soft_clustering import WBSC
from scipy.sparse import csr_matrix
# Create a sample collection of documents
documents = [
"the cat sat on the mat",
"a dog ate my homework",
"the cat and the dog are friends",
"my homework is about machine learning",
"machine learning models need data",
"cat and dog are common pets"
]
# Initialize and fit the model
model = WBSC(similarity_threshold=0.2, min_doc_freq=2)
memberships = model.fit_predict(documents)
print("Membership matrix:\n", memberships.toarray())
π οΈ Methodsο
fit_predict(docs)ο
Run the WBSC clustering algorithm on the provided documents and return the membership matrix.
Parameters:
docs(List[str]): A list of documents to be clustered.
Returns:
memberships(scipy.sparse.csr_matrix, shape(n_docs, n_clusters)): A sparse matrix where a non-zero element indicates a documentβs membership in a cluster.
π Implementation Notesο
Tokenization: The algorithm uses a simple, space-based tokenizer that converts text to lowercase.
Threshold Tuning: The quality and granularity of the resulting clusters are highly dependent on the
similarity_thresholdparameter. Lower values will result in fewer, broader clusters, while higher values will produce more, specific clusters.
π Referenceο
King-Ip Lin, Ravikumar Kondadadi. A WORD-BASED SOFT CLUSTERING ALGORITHM FOR DOCUMENTS.(https://www.cs.memphis.edu/~linki/_mypaper/CATA01.doc).