Worked notebooks and data
Follow the code and saved outputs, then adapt the examples to your data
These Python notebooks come from the graduate course behind the book. Read the code alongside its saved outputs, asking what each step changes and how you would adapt it to your data. You can examine the workflow before setting up the software.
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), with links for reviewing 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 examining a regression specification.
The data
The network notebook uses the files below. Download it, create a data/ folder beside it, and save the data files there. Run the notebook from that directory so its relative paths resolve correctly.
| 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. A smaller graph for inspection 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, which is not distributed here, because the source documents are not the author’s to redistribute. Some original loading cells use txt/; others use ./data/txt/. Adjust the paths to your own folder. You can read the saved outputs, but rerunning the notebooks requires your own text corpus.
To use your Chapter 4 corpus, adapt the loading and preprocessing cells to its format. Check a small batch before running a model over the full collection.
What these run on
These course notebooks were executed in 2023 and do not include a complete pinned environment. A current installation may not reproduce their saved outputs. Start with a small part of the workflow and record the versions you use.
- The Chapter 8 notebook includes its input data. It uses
pandas,pyarrow,networkx,matplotlib,seaborn,statsmodels, andtqdm. Check the network counts against the saved outputs as you work through it. Its final regression also uses ascholarly_citationvariable absent from the shared data. Read the notes on this gap and the centrality and regression choices before using those results. - The Chapter 6 notebooks require additional language-model packages, including
stanza,tensorflow_hub,tensorflow_text,top2vec,bertopic,umap,hdbscan,sentence_transformers. Model downloads and package compatibility can require additional setup. Use the automated coding tool guide to find the relevant documentation when adapting a notebook.
If you want a dependency-light path into the same material, the supervised learning primer ships a single runnable script that uses NumPy, pandas, and scikit-learn.
Provenance
The adaptation changes the shared edge list to parquet, points shared network paths to ./data/, and revises explanatory notes for readers of the book. Computational outputs remain those of the original course runs.