BunkaTopicModeling¶
A class to perform topic modeling on a set of documents.
This class utilizes clustering (default KMeans) to identify topics within a collection of documents. Each document and term is represented by embeddings, and topics are formed based on these embeddings. Topics are named using the top terms associated with them.
Source code in bunkatopics/topic_modeling/topic_model_builder.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
__init__(n_clusters=10, ngrams=[1, 2], name_length=15, top_terms_overall=1000, min_count_terms=2, min_docs_per_cluster=10, x_column='x', y_column='y', custom_clustering_model=None)
¶
Constructs all the necessary attributes for the BunkaTopicModeling object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_clusters |
int
|
Number of clusters for K-Means. Defaults to 10. |
10
|
ngrams |
list
|
List of n-gram lengths to consider. Defaults to [1, 2]. |
[1, 2]
|
name_length |
int
|
Maximum length of topic names. Defaults to 15. |
15
|
top_terms_overall |
int
|
Number of top terms to consider overall. Defaults to 1000. |
1000
|
min_count_terms |
int
|
Minimum count of terms to be considered. Defaults to 2. |
2
|
min_docs_per_cluster |
int
|
Minimum count of documents per topic |
10
|
x_column |
str
|
Column name for x-coordinate in the DataFrame. Defaults to "x". |
'x'
|
y_column |
str
|
Column name for y-coordinate in the DataFrame. Defaults to "y". |
'y'
|
custom_clustering_model |
optional
|
Custom clustering model instance, if any. Defaults to None. |
None
|
Source code in bunkatopics/topic_modeling/topic_model_builder.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
fit_transform(docs, terms)
¶
Analyzes documents and terms to form topics, assigns names to these topics based on the top terms, and returns a list of Topic instances.
This method performs clustering on the document embeddings to identify distinct topics. Each topic is named based on the top terms associated with it. The method also calculates additional topic properties such as centroid coordinates and convex hulls.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docs |
List[[Document]
|
List of Document objects representing the documents to be analyzed. |
required |
terms |
List[Term]
|
List of Term objects representing the terms to be considered in topic naming. |
required |
Returns: List[Topic]: A list of Topic objects, each representing a discovered topic with attributes like name, size, centroid coordinates, and convex hull.
Notes
- If a custom clustering model is not provided, the method defaults to using KMeans for clustering.
- Topics are named using the most significant terms within each cluster.
- The method calculates the centroid and convex hull for each topic based on the document embeddings.
Source code in bunkatopics/topic_modeling/topic_model_builder.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|