Datasets¶
Bundled example datasets for quickstarts and worked examples. Small datasets ship
inside the wheel and load offline; larger ones are downloaded once from GitHub on
first use and cached locally (under ~/.cache/topica/datasets, or
TOPICA_DATA_HOME). Each loader returns a pandas DataFrame ready for
from_dataframe; pass return_path=True for the cached CSV path
without pandas.
import topica
df = topica.datasets.load_gadarian()
corpus = topica.from_dataframe(
df, text_col="open.ended.response", stopwords=topica.ENGLISH_STOPWORDS
)
topica.datasets.load_gadarian ¶
Load the Gadarian & Albertson immigration experiment (341 documents).
The canonical stm prevalence example. Open-ended survey responses with
an anxiety-prime treatment and pid_rep (Republican identification).
Raw, untokenized text lives in the open.ended.response column, so build a
corpus with stopword removal::
df = topica.datasets.load_gadarian()
corpus = topica.from_dataframe(
df, text_col="open.ended.response", stopwords=topica.ENGLISH_STOPWORDS
)
This dataset is bundled in the wheel and loads offline. Pass
return_path=True for the CSV path instead of a DataFrame.
topica.datasets.load_poliblog ¶
Load the CMU 2008 political blog corpus (a 2,000-document sample).
The text in the text column is already tokenized and stemmed
(space-separated), as in the stm poliblog vignette, so no stopword
removal is needed::
df = topica.datasets.load_poliblog()
corpus = topica.from_dataframe(df, text_col="text")
Covariates: rating (Liberal/Conservative), day, blog. Downloaded
once and cached. Pass return_path=True for the CSV path.
topica.datasets.load_dubois ¶
Load Du Bois-era articles from The Crisis, 1910-1922 (704 documents).
Raw text in the text column; covariates year, decade,
volume, issue, author, subjects. Build a corpus with
stopword removal::
df = topica.datasets.load_dubois()
corpus = topica.from_dataframe(
df, text_col="text", stopwords=topica.ENGLISH_STOPWORDS
)
Downloaded once and cached. Pass return_path=True for the CSV path.
topica.datasets.get_data_home ¶
Return the directory where downloaded datasets are cached.
Defaults to ~/.cache/topica/datasets; override with the
TOPICA_DATA_HOME environment variable. The directory is created if it
does not exist.
topica.datasets.clear_cache ¶
Delete every cached (downloaded) dataset file. Vendored datasets are
unaffected; the next load_* call re-downloads what it needs.