-
Notifications
You must be signed in to change notification settings - Fork 0
data collection
The ingestion layer that fetches raw data from four external sources into data/raw/. Designed for high-throughput, fault-tolerant, and reproducible operation.
src/collection/
├── config.py → Concurrency settings, timeouts, batch sizes
├── news.py → Async Google News scraper (170K+ articles)
├── visa.py → Travel.State.Gov PDF/Excel downloader
├── encounter.py → CBP CSV downloader
├── trends.py → HF Hub snapshot sync
├── hf_sync.py → Bidirectional Hugging Face sync
└── utils.py → Retry logic, logging, throttling
| Stream | Module | Method | Output |
|---|---|---|---|
| Visa Data | visa.py |
Scrape + parallel download PDFs | data/raw/visa/ |
| Encounter Data | encounter.py |
Async semaphore-controlled CSVs | data/raw/encounter/ |
| Google News | news.py |
Async RSS + batch URL decode | data/raw/news/ |
| Google Trends | trends.py |
HF Hub snapshot_download()
|
data/raw/trends/ |
All network operations use semaphore-limited concurrency to avoid rate-limiting:
- News scraping:
Semaphore(12)with adaptive throttling on 429 responses - HTTP connection pooling (max 16 concurrent)
The retry_errors() decorator in utils.py implements:
- Exponential backoff with jitter (prevents thundering herd)
- Distinguishes retryable errors (429, 503, 504) from non-retryable (400, 403, 404)
- Parses
Retry-Afterheaders when present
News collection checkpoints progress every 25 articles with atomic JSON writes, enabling resumption after interruption.
Google News URL decoding is batched (20 URLs per request), achieving 40–50% fewer HTTP calls. HTML extraction uses ProcessPoolExecutor(4) to bypass the GIL.
# Full pipeline via run.sh
bash run.sh
# Individual collectors
python -m src.collection.visa
python -m src.collection.encounter
python -m src.collection.trendsOr bootstrap everything from Hugging Face:
python -m src.main bootstrap --org sdsc2005-migration- Collection Module — Full source code documentation
- News Scraper — Deep dive on news collection
- HF Sync — Hugging Face sync mechanism
- Data Processing — Next stage in the pipeline
- Reproducibility — End-to-end setup instructions
- Project Overview — Goals, research questions, methodology, and team
- Glossary — Key terms used throughout this wiki
Raw inputs that feed the prediction system.
| Page | Description |
|---|---|
| Visa Data | US Department of State visa issuance statistics (108 monthly PDFs) |
| Encounter Data | CBP Southwest border encounter statistics (FY2019–2026) |
| Google News | 170K+ news articles across 15 countries × 8 topics |
| Google Trends | Monthly search-interest time series (15 countries × 8 keywords) |
| Exchange Rates | IMF Real Effective Exchange Rate for 6 countries |
The end-to-end flow from raw data to production forecasts.
| Page | Description |
|---|---|
| Data Collection | Ingestion layer: async scraping, bounded concurrency, retry logic |
| Data Processing | PDF parsing, JSON→Parquet, encounter merging |
| NLP Enrichment | Embedding → Clustering → Labeling → Sentiment |
| Panel Construction | Feature engineering: 18 lag features, 6 lead targets |
| Training Pipeline | Out-of-time train/test split, 4 architectures |
| Inference Pipeline | Horizon-aware ensemble, production prediction flow |
Machine learning architectures and their roles in the ensemble.
| Page | Description |
|---|---|
| Random Forest | cuML GPU Random Forest — best at short horizons (Lead 1–2) |
| LSTM | MigrationLSTM — country-aware with SurgeJointLoss |
| Transformer | MigrationTransformer — best at long horizons (Lead 5–6) |
| Horizon-Aware Ensemble | Dynamic weighting: RF→short, Transformer→long |
| SurgeJointLoss | Dual-objective loss: Huber + BCE for crisis detection |
| Jina v5 Embeddings | TensorRT INT8 news article embeddings (768-dim) |
| Flan-T5 Summarization | TensorRT INT8 cluster labeling engine |
Statistical techniques driving the lead-lag and surge analysis.
| Page | Description |
|---|---|
| Lead-Lag Analysis | Pearson correlation at 0–6 month offsets |
| Surge Detection | Quantile-based and σ-threshold spike identification |
| Sentiment Analysis | Rule-based lexicon scoring for migration-relevant news |
| Event Clustering | HDBSCAN GPU clustering + LED label generation |
| Cross-Correlation Analysis | CCF analysis, VAR benchmarking, ADF stationarity tests |
| Multiple Comparison Correction | Benjamini-Hochberg FDR for 58 significant signals |
What the system discovered about migration predictability.
| Page | Description |
|---|---|
| Event-Visa Findings | News events as leading indicators (r=0.617 at 3-month lag) |
| Exchange Rate Findings | Exchange rate signals (DR r=0.498 at 2-month lag) |
| Model Performance | Ensemble results: F1=0.96 at Lead 1, F1=0.86 at Lead 6 |
Reference documentation for every src/ subpackage and key files.
| Page | Description |
|---|---|
| Main Entry Point |
src/main.py CLI: bootstrap, collect-live, sync-data |
| Collection Module |
src/collection/* — visa, encounter, news, trends, HF sync |
| Processing Module |
src/processing/* — parse, merge, build_panel, summarize |
| Analysis Module |
src/analysis/* — events, exchange_rate, trends_analysis, plots |
| Models Module |
src/models/* — surge_model, train_and_evaluate, inference |
| News Scraper | Deep dive: batch decoding, checkpoint recovery, throttling |
| PDF Parser | Deep dive: PyMuPDF table extraction, VISA_MAP normalization |
| TensorRT Engines | Deep dive: Jina-v5, Flan-T5, LED TensorRT engines |
| Build Panel Detail | Deep dive: lag/lead construction, forward-fill strategies |
| HF Sync | Deep dive: bidirectional Hugging Face Hub sync |
Compute, reproducibility, and operational details.
| Page | Description |
|---|---|
| GPU Acceleration | TensorRT INT8, cuML, CUDA streams, NVML profiling |
| Reproducibility | HF bootstrap, run.sh pipeline, dependency checking |