Skip to contents

Preparing texts

Clean texts, find their languages and their duplicates, and cut long texts or pool short ones into documents of a useful length.

clean_texts()
Clean texts before tokenising
detect_language()
Detect the language of texts
get_stop_words()
Stop words of one or several languages
find_duplicate_texts()
Find duplicated and near-duplicated texts
chunk_texts()
Split long texts into chunks, by words or by paragraphs
pool_texts()
Pool short texts into longer documents

From texts to tokens

Count the words and expressions of each document, find the ones that characterise it, filter the vocabulary, and build the input of a topic model.

extract_ngrams()
Extract n-grams from texts and count them by document
score_collocations()
Score candidate collocations of a corpus
select_collocations()
Select collocations with a rule
compare_collocation_rules()
Compare rules for selecting collocations
compute_tf_idf()
Term frequency-inverse document frequency (tf-idf)
filter_group_quantile()
Keep the rows above a quantile of a metric, within each group
filter_vocabulary()
Filter the vocabulary and report what each rule removes
vocabulary_diagnostics()
What each filtering step removes from the vocabulary
plot_vocabulary_diagnostics()
Plot what each filtering step removes
tokens_to_stm()
Build the input of stm() from a long token table

Choosing a topic model

Fit many candidate models (several vocabularies, numbers of topics and random starts) and compute the quality measures proposed in the literature.

evaluate_topic_models()
Evaluate topic models over corpora and numbers of topics
topic_coherence()
Coherence of each topic's top words
topic_exclusivity()
Exclusivity of each topic's top words
topic_diversity()
Topic diversity
topic_similarity()
Similarity between topics
ldatuning_metrics()
Number-of-topics criteria of Arun et al. (2010) and Deveaud et al. (2014)
topic_stability()
Stability of topics across runs
match_topics()
Match the topics of two models
topic_diagnostics()
Diagnostics of each topic of a model
model_metrics()
Summary metrics of one fitted model

Plotting model metrics

Figures to compare candidate models and to inspect single topics.

plot_model_metrics()
Metrics of a topic model evaluation by number of topics
plot_k_frontier()
Coherence-exclusivity frontier of a grid of topic models
plot_topic_diagnostics()
Coherence and exclusivity of each topic of one model
plot_topic_stability()
Stability of topics across runs, by number of topics
pareto_frontier()
Pareto frontier of two criteria
coherence_exclusivity_score()
Weighted harmonic mean of coherence and exclusivity

Validating topics with humans

Build tests in which coders spot the intruder among a topic’s words or topics, give them the sheets, and score their answers.

make_word_intrusion()
Word intrusion test
make_word_set_intrusion()
Word-set intrusion test
make_topic_intrusion()
Topic intrusion test
write_intrusion_sheets()
Write the coder sheets of an intrusion test
read_intrusion_responses()
Read filled coder sheets
score_intrusion()
Score an intrusion test
plot_intrusion_results()
Plot the results of an intrusion test

Reading topics

Describe each topic by its most characteristic words, by labels and by the documents where it dominates.

topic_terms()
Top terms of each topic, by one or several measures
term_counts()
Term counts of an STM corpus
topic_labels()
Short topic labels from an STM model
topic_documents()
Representative documents of each topic
topic_word_mass()
Probability mass of a set of words in each topic
marginal_topic_model()
Collapse a content-covariate STM to one word distribution per topic
topic_summary()
One-table summary of the topics of a model
topic_correlation()
Correlations between topics
topic_prevalence_by()
Average topic proportions by group of documents

Topic prevalence and covariate effects

Follow the attention given to each topic, for instance over time.

topic_effects()
Simulated topic effects from an STM estimateEffect() object
plot_topic_prevalence()
Average topic prevalence of an STM model
plot_topic_prevalence_over_time()
Topic prevalence over a continuous covariate

Package