benroodman commited on
Commit
68daca9
·
verified ·
1 Parent(s): 45cedf4

Update README.md to reflect refactoring of temporal_data and src/ restructuring

Browse files
Files changed (1) hide show
  1. README.md +65 -13
README.md CHANGED
@@ -144,27 +144,38 @@ dataset_info:
144
  - split: train
145
  path: data/raw/lobbying_data_lobbyview/reports.csv
146
 
 
 
 
 
 
 
 
 
 
 
 
147
  - config_name: src_build_campaign_events
148
  data_files:
149
  - split: train
150
- path: src/build_campaign_events.py
151
  - config_name: src_build_geographical_edges
152
  data_files:
153
  - split: train
154
- path: src/build_geographical_edges.py
155
  - config_name: src_build_lobbying_events
156
  data_files:
157
  - split: train
158
- path: src/build_lobbying_events.py
159
- - config_name: src_config
160
  data_files:
161
  - split: train
162
- path: src/config.py
163
- - config_name: src_temporal_data
164
  data_files:
165
  - split: train
166
- path: src/temporal_data.py
167
-
168
  license: cc-by-nc-sa-4.0
169
  task_categories:
170
  - graph-ml
@@ -197,14 +208,14 @@ The dataset represents the relationship between **1,137 legislators** and **6,82
197
 
198
  ### Dataset Structure
199
 
200
- HillStreet is divided into pre-built graph objects for deep learning and a relational tabular database accessed via Hugging Face configurations.
201
 
202
  #### 1. Dynamic Graph Objects (`.pt` & `.npy`)
203
  For immediate use in Graph Neural Networks (GNNs) and Temporal Graph Networks (TGNs), the core of HillStreet consists of annual **PyTorch Geometric Temporal** objects.
204
- - **Graph Files:** `hillstreet_temporal_graph_YEAR.pt`
205
- - **Temporal Integrity:** Every node feature and edge is instantiated based on its **public disclosure date**, not its reference date, ensuring a look-ahead-bias-free environment for backtesting.
206
- - **Node Features:** Includes rolling DW-NOMINATE scores, SEC fiscal facts, and Census district employment statistics.
207
- - **ID Mappings:** `src_id_map.npy` (Legislator Bioguide IDs) and `dst_id_map.npy` (Company Tickers).
208
 
209
  #### 2. Relational Tables (Hugging Face Configs)
210
  For researchers using flat-feature models (XGBoost, LightGBM) or custom graph builders, the structural connective tissue is provided as multiple dataset configurations. You can load these individually using the Hugging Face `datasets` library (e.g., `load_dataset("benroodman/HillStreet", "processed_events_lobbying")`).
@@ -221,6 +232,47 @@ The raw, underlying tables are also available as distinct configurations for cus
221
  - **Corporate & Industry:** `raw_sec_financials`, `raw_naics_*` crosswalks, and `raw_district_industries_*` configs.
222
  - **Lobbying:** `raw_lobbyview_*` configs.
223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  ### Feature Engineering & Normalization
225
  To stabilize variance in graph training, continuous features are transformed using signed log-scaling:
226
  $$x' = \text{sign}(x) \times \log(1 + |x|)$$
 
144
  - split: train
145
  path: data/raw/lobbying_data_lobbyview/reports.csv
146
 
147
+ # --- Source code (src/) ---
148
+ # config.py and temporal_data.py live at the top of the package; the data-prep
149
+ # scripts, node_features.py, and feature_lookups.py live in src/data_prep/.
150
+ - config_name: src_config
151
+ data_files:
152
+ - split: train
153
+ path: src/config.py
154
+ - config_name: src_temporal_data
155
+ data_files:
156
+ - split: train
157
+ path: src/temporal_data.py
158
  - config_name: src_build_campaign_events
159
  data_files:
160
  - split: train
161
+ path: src/data_prep/build_campaign_events.py
162
  - config_name: src_build_geographical_edges
163
  data_files:
164
  - split: train
165
+ path: src/data_prep/build_geographical_edges.py
166
  - config_name: src_build_lobbying_events
167
  data_files:
168
  - split: train
169
+ path: src/data_prep/build_lobbying_events.py
170
+ - config_name: src_node_features
171
  data_files:
172
  - split: train
173
+ path: src/data_prep/node_features.py
174
+ - config_name: src_feature_lookups
175
  data_files:
176
  - split: train
177
+ path: src/data_prep/feature_lookups.py
178
+
179
  license: cc-by-nc-sa-4.0
180
  task_categories:
181
  - graph-ml
 
208
 
209
  ### Dataset Structure
210
 
211
+ HillStreet is divided into pre-built graph objects for deep learning, a relational tabular database accessed via Hugging Face configurations, and the source code used to build everything from the raw tables.
212
 
213
  #### 1. Dynamic Graph Objects (`.pt` & `.npy`)
214
  For immediate use in Graph Neural Networks (GNNs) and Temporal Graph Networks (TGNs), the core of HillStreet consists of annual **PyTorch Geometric Temporal** objects.
215
+ - **Graph Files:** `hillstreet_temporal_graph_YEAR.pt` — one annual shard per active year.
216
+ - **Temporal Integrity:** Every node feature and edge is instantiated based on its **public disclosure date**, not its reference date, ensuring a look-ahead-bias-free environment for backtesting. Structural edges additionally carry a `last_seen` timestamp (most recent interaction) alongside `t` (the start of the relationship), so recency/days-since features can be computed at load time.
217
+ - **ID Mappings:** `src_id_map.npy` (Legislator Bioguide IDs row index) and `dst_id_map.npy` (Company Tickers → row index). These define the global node ordering the static node tensors are aligned to.
218
+ - **Node Features:** `node_features_static.pt` (the five static node tensors) plus `node_features_meta.json` (dimensions and categorical vocabularies). Produced by Phase 3 of the pipeline and aligned to the ID maps above. With the default configuration flags, legislator features combine a trading-performance summary, chamber/party/leadership indicators, DW-NOMINATE ideology coordinates (evaluated as of the snapshot date), and committee-membership indicators; company features encode the SIC industry division. Integer category indices for legislator **state** and company **sector**/**industry** are also provided for use as learned embeddings. Note that Census district employment enters the graph as **geo edge weights** (not node features), and SEC fiscal facts are shipped as a raw table that can be enabled as company node features via a configuration flag (off by default).
219
 
220
  #### 2. Relational Tables (Hugging Face Configs)
221
  For researchers using flat-feature models (XGBoost, LightGBM) or custom graph builders, the structural connective tissue is provided as multiple dataset configurations. You can load these individually using the Hugging Face `datasets` library (e.g., `load_dataset("benroodman/HillStreet", "processed_events_lobbying")`).
 
232
  - **Corporate & Industry:** `raw_sec_financials`, `raw_naics_*` crosswalks, and `raw_district_industries_*` configs.
233
  - **Lobbying:** `raw_lobbyview_*` configs.
234
 
235
+ #### 3. Source Code (`src/`)
236
+ The complete pipeline that turns the raw tables into the processed edge tables and graph objects is included as `src_*` configurations. The package is laid out as:
237
+
238
+ ```
239
+ src/
240
+ ├── __init__.py
241
+ ├── config.py # central paths + feature flags
242
+ ├── temporal_data.py # pipeline orchestrator (Phases 1–4)
243
+ └── data_prep/
244
+ ├── __init__.py
245
+ ├── build_lobbying_events.py
246
+ ├── build_campaign_events.py
247
+ ├── build_geographical_edges.py
248
+ ├── node_features.py
249
+ └── feature_lookups.py
250
+ ```
251
+
252
+ - **`config.py`** — Resolves the project root and centralizes every input/output path and the feature flags (which structural channels and node-feature blocks are enabled). The data-prep scripts import it via `from src import config`.
253
+ - **`build_lobbying_events.py`** — Maps lobbying clients to tickers (via NAICS→SIC→ticker crosswalks) and links them to sponsoring legislators, writing `data/processed/events_lobbying.csv`.
254
+ - **`build_campaign_events.py`** — Aggregates corporate PAC and 527 contributions above a conviction threshold, maps donors to legislators, and writes `data/processed/events_campaign_finance.csv`.
255
+ - **`build_geographical_edges.py`** — Builds industrial-constituency edges from Census County Business Patterns district data (top industries per district by employment), writing `data/processed/events_geographical_industry.csv`.
256
+ - **`temporal_data.py`** — The orchestrator. Ingests the trade table and the three processed event tables, broadcasts sector-level structural events to individual tickers, collapses repeated structural pairs into single weighted edges (keeping both first-seen `time` and `last_seen`), writes the per-channel edge parquets, and shards the unified edge stream into annual PyTorch Geometric `TemporalData` objects with global node-id maps. It then invokes Phase 3 to build the aligned static node tensors.
257
+ - **`node_features.py`** — Phase 3. Once `temporal_data.py` has written `src_id_map.npy` / `dst_id_map.npy`, `build_node_features()` assembles the five static node tensors (legislator features, legislator state embedding index, company features, company sector and industry embedding indices) **aligned to those maps**, saving `node_features_static.pt` and `node_features_meta.json`. It is called automatically by `temporal_data.py` (skip with `--skip_node_features`); it is not run standalone.
258
+ - **`feature_lookups.py`** — Helper module imported by `node_features.py`. Provides the as-of-date lookup classes (`TermLookup`, `PoliticianBioLookup`, `IdeologyLookup`, `CommitteeLookup`, `CompanySICLookup`, `CompanyFinancialsLookup`) that resolve a legislator's or company's attributes from the raw tables (congress terms, DW-NOMINATE ideology, committee assignments, company SIC, SEC financials) at a given snapshot date. It is not executed directly.
259
+
260
+ ### Reproduction Pipeline
261
+ All commands are run from the repository root. The three builders are independent of one another and produce the processed event tables that `temporal_data.py` consumes; run them first, then the orchestrator:
262
+
263
+ ```bash
264
+ # 1. Build the three processed structural-event tables (any order)
265
+ python src/data_prep/build_lobbying_events.py
266
+ python src/data_prep/build_campaign_events.py
267
+ python src/data_prep/build_geographical_edges.py
268
+
269
+ # 2. Build edge parquets, annual PyG shards, node-id maps, and aligned node features
270
+ # (Phase 3 node features run automatically at the end)
271
+ python src/temporal_data.py
272
+ ```
273
+
274
+ `temporal_data.py` expects the trade table at `data/processed/ml_dataset_continuous.csv`. It does **not** call the three build scripts itself — it reads their CSV outputs — but it **does** invoke `node_features.py` (which imports `feature_lookups.py`) as its final phase, so both must be present.
275
+
276
  ### Feature Engineering & Normalization
277
  To stabilize variance in graph training, continuous features are transformed using signed log-scaling:
278
  $$x' = \text{sign}(x) \times \log(1 + |x|)$$