Note
Go to the end to download the full example code.
Defining a custom corpus for plotting text¶
run this example as a notebook — or grab the .ipynb (also linked at the bottom of the page)
By default, the text samples will be transformed into a vector of word counts and then modeled using Latent Dirichlet Allocation (# of topics = 50) using a model fit to a large sample of wikipedia pages. However, you can optionally pass your own text to fit the semantic model. To do this define corpus as a list of documents (strings). A topic model will be fit on the fly and the text will be plotted.

/home/docs/checkouts/readthedocs.org/user_builds/hypertools/checkouts/latest/hypertools/plot/backend.py:1353: UserWarning: Failed to switch to any interactive backend (TkAgg, QtAgg, Qt5Agg, Qt4Agg, GTK4Agg, GTK3Agg, WXAgg). Falling back to 'Agg'.
warnings.warn(BACKEND_WARNING)
# Code source: Andrew Heusser
# License: MIT
# load hypertools
import hypertools as hyp
# load the data
text_samples = ['i like cats alot', 'cats r pretty cool', 'cats are better than dogs',
'dogs rule the haus', 'dogs are my jam', 'dogs are a mans best friend',
'i haz a cheezeburger?']
# plot it
hyp.plot(text_samples, 'o', corpus=text_samples)
Total running time of the script: (0 minutes 0.050 seconds)