Archived
1
0
Fork
You've already forked quick-topic
0
ARCHIVED: Quick code for building and optimizing topic models in Python. Uses spaCy and gensim.
This repository has been archived on 2026年06月30日. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
  • Python 100%
2026年06月30日 11:19:03 +02:00
dynamic Update README and polish some script errors. 2022年09月30日 11:01:27 +02:00
quick_topic Add initial BERTopic script. Still a WIP. 2024年11月30日 18:13:20 +01:00
tests Clean requirements, remove some unused stuff. 2023年09月13日 18:41:35 +02:00
.gitignore Add visualizations and OpenAI-based topic labelling. 2024年12月20日 09:48:15 +01:00
.mise.toml Add visualizations and OpenAI-based topic labelling. 2024年12月20日 09:48:15 +01:00
authors-topics Clean up corpus-find-word. 2022年12月04日 16:06:02 +01:00
build-bertopic-models Add visualizations and OpenAI-based topic labelling. 2024年12月20日 09:48:15 +01:00
build-document-topics More work bringing things to the new code style. 2022年12月04日 15:53:39 +01:00
build-models Missing parameter in build-models. 2023年05月14日 10:32:17 +02:00
COPYING First draft of some corpus-making code, not done yet. 2022年01月28日 21:58:08 +01:00
corpus-find-word Clean up corpus-find-word. 2022年12月04日 16:06:02 +01:00
docs-for-topics DRY up document detail printing. 2022年12月04日 16:57:44 +01:00
docs-for-word-in-topic Add missing file; clean up docs-for-word-in-topic, document. 2022年12月04日 17:04:56 +01:00
README.md Remove docs for removed scripts. 2024年11月30日 12:00:06 +01:00
requirements.txt Add visualizations and OpenAI-based topic labelling. 2024年12月20日 09:48:15 +01:00
topic-correlation Add a topic correlation script. 2023年11月22日 12:35:40 +01:00
topics-for-words Add a "sum" option to topics-for-words. 2023年05月14日 13:21:57 +02:00
topics-over-time No, *really* fix bucket print. 2022年12月04日 16:44:58 +01:00
vis-bertopic Add visualizations and OpenAI-based topic labelling. 2024年12月20日 09:48:15 +01:00
vis-pyldavis Don't renumber topis in this visualization. 2024年02月08日 10:38:45 +01:00
vis-umap First beta of TSNE. 2022年12月04日 18:39:49 +01:00
words-for-topics Fix up words-for-topics. 2022年12月04日 16:47:23 +01:00

Quick-Topic

A few scripts that I cobbled together to build and evaluate quick topic models and document corpora using Gensim, starting with documents in the Sciveyor JSON schema format.

Scripts

All of these scripts accept required and optional configuration parameters as command-line arguments. Run script --help to get more information about configuration.

Build Corpora and Models

build-models: Builds topic models on the generated corpus in the current directory. Twenty-nine models are created at sizes 2-25 (each size), and from 50-150 (every 25). They are then evaluated using the C_v coherence model, and coherence scores are dumped to the console.

build-document-topics: Builds a matrix representation of the probabilities for each topic in each document. This matrix is an important ingredient in many analyses below, so we precalculate it separately.

Visualize Models

vis-pyldavis: Builds a pyLDAvis HTML file for the requested topic model.

vis-umap: Builds an interactive graph of the UMAP embedding of the documents in the topic model.

Explore Models

corpus-find-word <word-part> [<word-part>...]: Prints out all types in the dictionary containing the given search strings.

docs-for-topics: Prints out the top documents for each topic in the corpus. By default, it will print a pretty-formatted citation for each document, though you may request that another field is printed for each document instead.

docs-for-word-in-topic --word word --topic topic [topic...]: Rank and print the top documents for the value of the probability of the given topics times the number of occurrences of the given word.

docs-like-words <word> [<word>...]: Find the documents that are most similar to the list of words passed, using a cosine-similarity measure (notably, not using any generated topic model). This has fairly large memory requirements.

topics-for-words <word> [word...]: Prints out the probabilities of each word's occurrence in each topic.

topics-over-time: Loads the dates for all documents and prints out the prevalence of each topic in the corpus over time. The years are clustered into buckets of a given size, usually five years.

words-for-topics: Prints out the top N words for each topic in the model.

Analyze Models

authors-topics: Compute the summed topic probability for each author present in the corpus.

Dynamic Topic Models

The dynamic folder contains version of (at least some of) these scripts that work on dynamic topic models. It requires that the Blei et al. binary for dynamic topic modeling is installed; see dynamic/dtmmodel.py for more information.

In general, those scripts have the same names and functions as above; the following are novel:

most-different-words <model.gensim> <topic> <year_1> <year_2>: Print out the words that changed the most (both increase and decrease) within the given topic, between the two years.

Development

There's a requirements.txt file here that should serve for installing all of the required Python packages.

License

Copyright (c) 2022 Charles H. Pence.

Licensed under the GNU GPL v3. See the COPYING file for more details.