Topeax
Topeax (Kardos, 2026) is a probabilistic topic model based on the Peax clustering model, which finds topics based on peaks in point density in the embedding space. The model can recover the number of topics automatically.
In the following example I run a Topeax model on the BBC News corpus, and plot the steps of the algorithm to inspect how our documents have been clustered and why:
# pip install datasets, plotly
from datasets import load_dataset
from turftopic import Topeax
ds = load_dataset("gopalkalpande/bbc-news-summary", split="train")
topeax = Topeax(random_state=42)
doc_topic = topeax.fit_transform(list(ds["Summaries"]))
fig = topeax.plot_steps(hover_text=[text[:200] for text in corpus])
fig.show()
topeax.print_topics()
| Topic ID | Highest Ranking |
|---|---|
| 0 | mobile, microsoft, digital, technology, broadband, phones, devices, internet, mobiles, computer |
| 1 | economy, growth, economic, deficit, prices, gdp, inflation, currency, rates, exports |
| 2 | profits, shareholders, shares, takeover, shareholder, company, profit, merger, investors, financial |
| 3 | film, actor, oscar, films, actress, oscars, bafta, movie, awards, actors |
| 4 | band, album, song, singer, concert, rock, songs, rapper, rap, grammy |
| 5 | tory, blair, labour, ukip, mps, minister, election, tories, mr, ministers |
| 6 | olympic, tennis, iaaf, federer, wimbledon, doping, roddick, champion, athletics, olympics |
| 7 | rugby, liverpool, england, mourinho, chelsea, premiership, arsenal, gerrard, hodgson, gareth |
How does Topeax work?
The Topeax algorithm, similar to clustering topic models consists of two consecutive steps. One of them discovers the underlying clusters in the data, the other one estimates term importance scores for each topic in the corpus.
1. Clustering
Documents embeddings first get projected into two-dimensional space using t-SNE. In order to identify clusters, we first calculate a Kernel Density Estimate over the embedding space, then find local maxima in the KDE by grid approximation. When we discover local maxima (peaks), we assume these to be cluster means. Cluster density is then approximated with a Gaussian Mixture, where we fix means to the density peaks and then use expectation-maximization to fit the rest of the parameters. (see Figure 2) Documents are then assigned to the component with the highest responsibility:
where \(z_d\) is the cluster label for document \(d\), \(r_{kd}\) is the responsibility of component \(k\) for document \(d\) and \(\hat{x}_d\) is the 2D embedding of document \(d\).
2. Term Importance Estimation
Topeax uses a combined semantic-lexical term importance, which is the geometric mean of the NPMI method (see Clustering Topic Models for more detail) and a slightly modified centroid-based method. The modified centroids are calculated like so:
where \(t_k\) is the embedding of topic \(k\) and \(x_d\) is the embedding of document \(d\).
Visualization
Topeax has a number of plots available that can aid you when interpreting your results:
Density Plots
One can plot the kernel density estimate on both a 2D and a 3D plot.
topeax.plot_density()
topeax.plot_density3d()
Component Plots
You can also create a plot over the mixture components/clusters found by the model.
topeax.plot_components()
You can also create a datamapplot figure similar to clustering models:
# pip install turftopic[datamapplot]
topeax.plot_components_datamapplot()
Citation
Please cite Turftopic and Kardos (2026) when using the Topeax model:
@article{
Kardos2025,
title = {Turftopic: Topic Modelling with Contextual Representations from Sentence Transformers},
doi = {10.21105/joss.08183},
url = {https://doi.org/10.21105/joss.08183},
year = {2025},
publisher = {The Open Journal},
volume = {10},
number = {111},
pages = {8183},
author = {Kardos, Márton and Enevoldsen, Kenneth C. and Kostkan, Jan and Kristensen-McLachlan, Ross Deans and Rocca, Roberta},
journal = {Journal of Open Source Software}
}
@misc{kardos2026topeaximprovedclustering,
title={Topeax -- An Improved Clustering Topic Model with Density Peak Detection and Lexical-Semantic Term Importance},
author={Márton Kardos},
year={2026},
eprint={2601.21465},
archivePrefix={arXiv},
primaryClass={cs.AI},
url={https://arxiv.org/abs/2601.21465},
}
API Reference
turftopic.models.topeax.Topeax
Bases: GMM
Topic model based on the Peax clustering algorithm. The algorithm discovers the number of topics automatically, and is based on GMM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder |
Union[Encoder, str, MultimodalEncoder]
|
Model to encode documents/terms, all-MiniLM-L6-v2 is the default. |
'sentence-transformers/all-MiniLM-L6-v2'
|
vectorizer |
Optional[CountVectorizer]
|
Vectorizer used for term extraction. Can be used to prune or filter the vocabulary. |
None
|
perplexity |
int
|
Number of neighbours to take into account when running TSNE. |
50
|
random_state |
Optional[int]
|
Random state to use so that results are exactly reproducible. |
None
|
trf_kwargs |
Keyword arguments to apply when loading the Encoder model. |
None
|
|
encode_kwargs |
Keyword arguments to apply encoding documents with the encoder. |
None
|
Source code in turftopic/models/topeax.py
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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
merge_models(models, match_threshold=0.7, merge_method='asymmetric_mean', weighted=True)
classmethod
Merges multiple ClusteringTopicModel models together. The original models will not be modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models |
list[Topeax]
|
ClusteringTopicModel models to merge together. |
required |
match_threshold |
Cosine similarity threshold, above which topics are to be considered the same. |
0.7
|
|
merge_method |
str | Callable
|
Method for merging the two topic models.
- |
'asymmetric_mean'
|
weighted |
Indicates whether the merge aggregation should be weighted by the number of documents the two models have seen. |
True
|
Returns:
| Type | Description |
|---|---|
ClusteringTopicModel
|
Merged model. |
Source code in turftopic/models/topeax.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
merge_with(other, match_threshold=0.7, merge_method='asymmetric_mean', weighted=True)
Updates topic model by merging it with another one trained on the new data.
!!! warning: Only static properties of a model will be taken into account when merging. Attributes associated with top exemplars and temporal data will be DELETED from the model. The model will be modified in-place. We recommend that you save the original model to disk to avoid losing data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other |
Topeax
|
Other Topeax model to merge this one with. |
required |
match_threshold |
Cosine similarity threshold, above which topics are to be considered the same. |
0.7
|
|
merge_method |
str | Callable
|
Method for merging the two topic models.
- |
'asymmetric_mean'
|
weighted |
Indicates whether the merge aggregation should be weighted by the number of documents the two models have seen. |
True
|
Returns:
| Type | Description |
|---|---|
Self
|
|
Source code in turftopic/models/topeax.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
turftopic.models.topeax.Peax
Bases: ClusterMixin, BaseEstimator
Clustering model based on density peaks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
random_state |
Optional[int]
|
Random seed to use for fitting gaussian mixture to peaks. |
None
|
Source code in turftopic/models/topeax.py
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 | |