Worked notebooks and data
Runnable versions of the pipelines the exercise chapters describe
The exercise chapters stay language-agnostic so you can work in Python, R, or Stata. These notebooks are the other half of that: one concrete worked path, with real output from a real run, so you have something to read against while you build your own version.
They come from the graduate course the book grew out of. Every output you see was produced by executing the notebook, not written by hand: the site never runs code at build time.
The notebooks
Text representation
Chapter 6. Preprocessing with NLTK and Stanza, named-entity recognition, Word2Vec and GloVe embeddings, and three ways to measure document similarity.
Topic modeling
Chapter 6. The same corpus through three topic models (an embedding-plus-clustering pipeline, Top2Vec, and BERTopic), followed by a CNN text classifier.
Network analysis
Chapter 8. Building a bipartite graph, projecting it to a co-citation network, pruning by k-core, visualizing, and testing a hypothesis on the result.
The data
The network notebook runs end to end on the files below. Download the notebook and the data/ folder side by side and the paths resolve as written.
| File | What it is | Size |
|---|---|---|
policy_scholarly_edges.parquet |
38,237 edges linking policy documents to the scholarly works they cite. The starting point for the Chapter 8 notebook. | 1.4 MB |
g_scholarly.graphml |
The co-citation network projected from those edges: 15,746 works, 39,680 weighted ties. | 5.6 MB |
g_scholarly_k.graphml |
Its k-core at k=13: 1,179 works, 16,653 ties. The version worth opening in Gephi. | 1.9 MB |
Both GraphML files load with nx.read_graphml() and open directly in Gephi or Cytoscape. The notebook regenerates them from the parquet file, so you can either use them as given or rebuild them and check that you get the same graph.
The Chapter 6 notebooks read a folder of policy documents from ./data/txt/, which is not distributed here, because the source documents are not the author’s to redistribute. Those notebooks are therefore readable but not directly runnable: every cell’s output is committed, so you can follow exactly what each step produced, but rerunning requires substituting your own corpus.
Point them at the corpus you built in Chapter 4 and they will work. That substitution is the exercise anyway.
What these run on
The notebooks were executed in 2023 and their dependencies are pinned to nothing: they install whatever is current. Two consequences worth knowing before you spend an afternoon on an environment:
- The Chapter 8 notebook is the reliable one. It needs only
pandas,networkx,matplotlib,seaborn,statsmodels, andtqdm, all of which are stable. It should run today with no changes. - The Chapter 6 notebooks carry heavier and more brittle dependencies:
stanza,tensorflow_hub,tensorflow_text,top2vec,bertopic,umap,hdbscan,sentence_transformers. Several have had breaking releases since 2023, and the TensorFlow Hub pieces in particular are awkward to install now. Read them for the pipeline logic rather than treating them as a working environment, and use the maintained automated coding tool guide for current equivalents.
If you want a dependency-light path into the same material, the supervised learning primer ships a single runnable script that needs only scikit-learn.
Provenance
These were imported from the course repository by scripts/import_notebooks.py, which records the two changes made on the way in: the edge list was converted from a Python pickle to parquet (unpickling runs arbitrary code, which is not a thing to hand someone as a download), and the data paths were rewritten to ./data/. Cell outputs were not touched.