Skip to content

Commit f1208ab

Browse files
Merge pull request #104 from x-tabdeveloping/readme_draft_updates
Incorporated feedback from peer review
2 parents 80b075e + f148fa8 commit f1208ab

File tree

3 files changed

+53
-18
lines changed

3 files changed

+53
-18
lines changed

README.md

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ pip install turftopic
3636
If you intend to use CTMs, make sure to install the package with Pyro as an optional dependency.
3737

3838
```bash
39-
pip install turftopic[pyro-ppl]
39+
pip install "turftopic[pyro-ppl]"
4040
```
4141

4242
If you want to use clustering models like BERTopic or Top2Vec, install:
4343

4444
```bash
45-
pip install turftopic[umap-learn]
45+
pip install "turftopic[umap-learn]"
4646
```
4747

4848
### Fitting a Model
@@ -52,6 +52,8 @@ scikit-learn workflows.
5252

5353
Here's an example of how you use KeyNMF, one of our models on the 20Newsgroups dataset from scikit-learn.
5454

55+
> If you are using a Mac, you might have to install the required SSL certificates on your system in order to be able to download the dataset.
56+
5557
```python
5658
from sklearn.datasets import fetch_20newsgroups
5759

@@ -68,7 +70,8 @@ Turftopic also comes with interpretation tools that make it easy to display and
6870
```python
6971
from turftopic import KeyNMF
7072

71-
model = KeyNMF(20).fit(corpus)
73+
model = KeyNMF(20)
74+
document_topic_matrix = model.fit_transform(corpus)
7275
```
7376

7477
### Interpreting Models
@@ -131,6 +134,8 @@ model.print_topic_distribution(
131134

132135
Turftopic now allows you to automatically assign human readable names to topics using LLMs or n-gram retrieval!
133136

137+
> You will need to `pip install "turftopic[openai]"` for this to work.
138+
134139
```python
135140
from turftopic import KeyNMF
136141
from turftopic.namers import OpenAITopicNamer
@@ -154,6 +159,8 @@ model.print_topics()
154159

155160
You can use a set of custom vectorizers for topic modeling over **phrases**, as well as **lemmata** and **stems**.
156161

162+
> You will need to `pip install "turftopic[spacy]"` for this to work.
163+
157164
```python
158165
from turftopic import BERTopic
159166
from turftopic.vectorizers.spacy import NounPhraseCountVectorizer
@@ -175,10 +182,34 @@ model.print_topics()
175182

176183
### Visualization
177184

178-
Turftopic does not come with built-in visualization utilities, [topicwizard](https://github.com/x-tabdeveloping/topicwizard), an interactive topic model visualization library, is compatible with all models from Turftopic.
185+
Turftopic comes with a number of visualization and pretty printing utilities for specific models and specific contexts, such as hierarchical or dynamic topic modelling.
186+
You will find an overview of these in the [Interpreting and Visualizing Models](https://x-tabdeveloping.github.io/turftopic/model_interpretation/) section of our documentation.
187+
188+
```
189+
pip install "turftopic[datamapplot, openai]"
190+
```
191+
192+
```python
193+
from turftopic import ClusteringTopicModel
194+
from turftopic.namers import OpenAITopicNamer
195+
196+
model = ClusteringTopicModel(feature_importance="centroid").fit(corpus)
197+
198+
namer = OpenAITopicNamer("gpt-4o-mini")
199+
model.rename_topics(namer)
200+
201+
fig = model.plot_clusters_datamapplot()
202+
fig.show()
203+
```
204+
205+
<center>
206+
<img src="https://github.com/x-tabdeveloping/turftopic/blob/main/docs/images/cluster_datamapplot.png?raw=true" width="70%" style="margin-left: auto;margin-right: auto;">
207+
</center>
208+
209+
In addition, Turftopic is natively supported in [topicwizard](https://github.com/x-tabdeveloping/topicwizard), an interactive topic model visualization library, is compatible with all models from Turftopic.
179210

180211
```bash
181-
pip install topic-wizard
212+
pip install "turftopic[topic-wizard]"
182213
```
183214

184215
By far the easiest way to visualize your models for interpretation is to launch the topicwizard web app.
@@ -189,10 +220,10 @@ import topicwizard
189220
topicwizard.visualize(corpus, model=model)
190221
```
191222

192-
<figure>
223+
<center>
193224
<img src="https://x-tabdeveloping.github.io/topicwizard/_images/screenshot_topics.png" width="70%" style="margin-left: auto;margin-right: auto;">
194225
<figcaption>Screenshot of the topicwizard Web Application</figcaption>
195-
</figure>
226+
</center>
196227

197228
Alternatively you can use the [Figures API](https://x-tabdeveloping.github.io/topicwizard/figures.html) in topicwizard for individual HTML figures.
198229

paper.bib

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,15 @@ @inproceedings{sentence_transformers
170170
abstract = "BERT (Devlin et al., 2018) and RoBERTa (Liu et al., 2019) has set a new state-of-the-art performance on sentence-pair regression tasks like semantic textual similarity (STS). However, it requires that both sentences are fed into the network, which causes a massive computational overhead: Finding the most similar pair in a collection of 10,000 sentences requires about 50 million inference computations ({\textasciitilde}65 hours) with BERT. The construction of BERT makes it unsuitable for semantic similarity search as well as for unsupervised tasks like clustering. In this publication, we present Sentence-BERT (SBERT), a modification of the pretrained BERT network that use siamese and triplet network structures to derive semantically meaningful sentence embeddings that can be compared using cosine-similarity. This reduces the effort for finding the most similar pair from 65 hours with BERT / RoBERTa to about 5 seconds with SBERT, while maintaining the accuracy from BERT. We evaluate SBERT and SRoBERTa on common STS tasks and transfer learning tasks, where it outperforms other state-of-the-art sentence embeddings methods."
171171
}
172172
173-
@software{topicwizard,
174-
author = {Kardos, Márton},
175-
month = nov,
176-
title = {{topicwizard: Pretty and opinionated topic model visualization in Python}},
177-
url = {https://github.com/x-tabdeveloping/topic-wizard},
178-
version = {0.5.0},
179-
year = {2023}
173+
@misc{topicwizard,
174+
title={topicwizard -- a Modern, Model-agnostic Framework for Topic Model Visualization and Interpretation},
175+
author={Márton Kardos and Kenneth C. Enevoldsen and Kristoffer Laigaard Nielbo},
176+
year={2025},
177+
eprint={2505.13034},
178+
archivePrefix={arXiv},
179+
primaryClass={cs.CL},
180+
url={https://arxiv.org/abs/2505.13034},
181+
doi="10.48550/arXiv.2505.13034"
180182
}
181183

182184
@article{discourse_analysis,

paper.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ bibliography: paper.bib
3434

3535
# Summary
3636

37-
Turftopic is a topic modelling library including a number of recent topic models that go beyond bag-of-words models and can understand text in context, utilizing representations from transformers.
37+
Topic models are machine learning techniques that are able to discover themes in a set of documents.
38+
Turftopic is a topic modelling library including a number of recent developments in topic modelling that go beyond bag-of-words models and can understand text in context, utilizing representations from transformers.
3839
Turftopic focuses on ease of use, providing a unified interface for a number of different modern topic models, and boasting both model-specific and model-agnostic interpretation and visualization utilities.
3940
While the user is afforded great flexibility in model choice and customization, the library comes with reasonable defaults, so as not to needlessly overwhelm first-time users.
4041
In addition, Turftopic allows the user to: a) model topics as they change over time, b) learn topics on-line from a stream of texts, c) find hierarchical structure in topics, d) learning topics in multilingual texts and corpora.
@@ -50,10 +51,11 @@ Some attempts have been made at creating unified packages for modern topic model
5051
These packages, however, have a focus on neural models and topic model evaluation, have abstract and highly specialized interfaces, and do not include some popular topic models.
5152
Additionally, while model interpretation is fundamental aspect of topic modelling, the interpretation utilities provided in these libraries are fairly limited, especially in comparison with model-specific packages, like BERTopic.
5253

53-
Turftopic unifies state-of-the-art contextual topic models under a superset of the `scikit-learn` [@scikit-learn] API, which users are likely already familiar with, and can be readily included in `scikit-learn` workflows and pipelines.
54+
Turftopic unifies state-of-the-art contextual topic models under a superset of the `scikit-learn` [@scikit-learn] API, which many users may be familiar with, and can be readily included in `scikit-learn` workflows and pipelines.
5455
We focused on making Turftopic first and foremost an easy-to-use library that does not necessitate expert knowledge or excessive amounts of code to get started with, but gives great flexibility to power users.
55-
Furthermore, we included an extensive suite of pretty-printing and visualization utilities that aid users in interpreting their results.
56-
The library also includes three topic models, which to our knowledge only have implementations in Turftopic, these are: KeyNMF [@keynmf], Semantic Signal Separation (S^3^) [@s3], and GMM, a Gaussian Mixture model of document representations with a soft-c-tf-idf term weighting scheme.
56+
Furthermore, we included an extensive suite of pretty-printing and model-specific visualization utilities that aid users in interpreting their results.
57+
In addition, we provide native compatibility with `topicwizard` [@topicwizard], a model-agnostic topic model visualization library.
58+
The library also includes three topic models that, to our knowledge, only have implementations in Turftopic: KeyNMF [@keynmf], Semantic Signal Separation (S^3^) [@s3], and GMM, a Gaussian Mixture model of document representations with a soft-c-tf-idf term weighting scheme.
5759

5860
# Functionality
5961

0 commit comments

Comments
 (0)