A modular, research-friendly toolkit for microscopic information diffusion prediction — focused on next-user forecasting inside information cascades. EchoFlow brings together strong sequence baselines and time-aware graph models, consistent evaluation, and simple experiment management with PyTorch Lightning.
Highlights
- Model zoo:
cyan_rnn,dyhgcn,mshgat,sieve - Time-aware training: automatic time-bin selection, diffusion event builders
- Clean data interface: CSV cascades with
user_id, topic_id, timestamp - Repro-friendly: unified metrics (Hit@k, MAP), CSV summaries, final report files
- Easy to extend: drop-in model factories via
pl/models/<name>.py
Table of Contents
- Overview
- Quick Start
- Data Format
- Configuration
- Training & Evaluation
- Models
- Extending
- Project Structure
- Contributing
- License
EchoFlow targets the microscopic information diffusion task: given a cascade (topic and user sequence over time), predict the next user. It includes:
- Sequence baselines and graph-temporal models
- Unified trainer built on PyTorch Lightning
- Consistent evaluation (Hit@k, MAP) and logging
- Ready-to-use sample datasets
Prerequisites
- Python 3.8+
- PyTorch (recommended 2.0+)
- PyTorch Lightning (recommended 2.x)
Install
pip install -U pip setuptools wheel
pip install torch pytorch-lightning pyyaml
# Optional: for TensorBoard logging
pip install tensorboardRun a model
# Train and evaluate DyHGCN on the built-in Twitter dataset
python -m pl.train \
--dataset twitter \
--model_name dyhgcn \
--config configs/default.yaml
# Alternative: run MS-HGAT
python -m pl.train --dataset android --model_name mshgat --config configs/default.yaml
# Sequence baseline (CYAN-RNN)
python -m pl.train --dataset memetracker --model_name cyan_rnn --config configs/default.yamlNotes
--model_namemust be one of the models present inpl/models/:cyan_rnn,dyhgcn,mshgat,sieve.- You can override any YAML option via CLI flags (see Configuration below).
- Logs, checkpoints, CSV summaries, and a
final_report.txtare saved underlightning_logs/<model>/<version>/.
EchoFlow expects per-dataset directories under dataset/ with a single file interactions.inter in CSV format.
Required header and columns:
user_id,topic_id,timestamp
u_001,t_078,1692201000
u_314,t_078,1692201200
u_001,t_078,1692201400Built-in samples
dataset/twitter/interactions.interdataset/memetracker/interactions.interdataset/android/interactions.interdataset/christianity/interactions.inter
Bring your own data
- Create
dataset/<your_dataset>/interactions.interwith the CSV header above. - Use
--dataset <your_dataset>or set--interactions_pathto a file path directly.
Experiments are configured via YAML and can be overridden by CLI flags.
Default config (configs/default.yaml):
data:
dataset: douban
interactions_path: null
root: dataset
min_len: 4
batch_size: 512
num_workers: 4
pin_memory: true
persistent_workers: true
prefetch_factor: 2
train_max_len: 20
eval_max_len: 20
model:
d_model: 64
n_heads: 4
n_layers: 2
dropout: 0.1
topk: [5, 10, 20]
mask_prob: 0.25
refine_steps: 5
# Time-step auto partitioning: adaptively choose K by timestamp distribution
time_step_split: auto
auto_min_bins: 3
auto_max_bins: 10
optim:
lr: 0.001
weight_decay: 0.01
trainer:
max_epochs: 300
seed: 42
default_root_dir: ./lightning_logs
accelerator: auto
devices: auto
log_every_n_steps: 50
precision: 32
enable_tf32: true
early_stopping:
monitor: val_acc
mode: max
patience: 10
# Run logs: use name/version to differentiate experiment directories
logger: csv
logger_name: GenIDP
# Optional fixed version; leave null to auto-increment as version_0/1/..
logger_version: nullCLI overrides (examples):
# Change batch size and precision
python -m pl.train --dataset twitter --model_name dyhgcn --batch_size 1024 --precision bf16
# Use a specific file path instead of dataset shortcut
python -m pl.train --interactions_path /abs/path/to/interactions.inter --model_name sieve
# Customize metrics top-k
python -m pl.train --dataset memetracker --model_name cyan_rnn --topk 5 10 50Trainer
- Uses PyTorch Lightning
TrainerwithModelCheckpoint,EarlyStopping, andLearningRateMonitor. - Mixed precision and TF32 acceleration can be enabled via config (see
precision,enable_tf32).
Outputs
- Checkpoints: best by
val_acc - CSV summary per epoch:
epoch_summary.csv - Final summary report:
final_report.txtwith validation and test metrics - Logs directory:
lightning_logs/<model>/<version>/
Metrics
- Hit@k and MAP@k (
utils.metrics.compute_hit_map_at_k) - Accuracy (top-1)
Protocol differences vs prior papers
- Reported results on
android,memetracker,twitter, anddoubanmay differ from some original papers because EchoFlow adopts a strict leave-one-out (LOO) evaluation protocol instead of full-sequence prediction. - Concretely: for validation we predict the event at position
L-2givenseq[:L-2]; for test we predict the last eventL-1givenseq[:L-1]. Training uses all contexts fromt=1 .. L-3, holding out the final two events to avoid leakage. - Many prior works evaluate by teacher-forcing across every position of the full sequence or by windowed next-step prediction; those protocols can inflate metrics when the model is exposed to future tokens during evaluation or when early tokens are easier to predict.
Why LOO (advantages)
- Leakage-resistant: holding out the final two events ensures no future information enters validation/test.
- Fair across lengths: every cascade contributes exactly one validation and one test target, avoiding over-weighting long cascades.
- Realistic next-user prediction: the hardest (near-tail) events are evaluated, closer to deployment scenarios.
- Stable early stopping: validation
val_accis computed on consistent LOO targets, improving comparability across runs. - Reproducible metrics: unified Hit@k/MAP@k over the same target positions simplifies cross-model comparison.
Supported models (set via --model_name):
cyan_rnn: Sequence baseline (GRU/LSTM configurable viarnn_type).dyhgcn: Diffusion-aware GCN with time-bin snapshots and attention.mshgat: Multi-Stage Hierarchical Graph Attention over time.sieve: Topic-aware diffusion model with contrastive components.
Time-aware models (dyhgcn, mshgat, sieve) use training diffusion events derived from the first L-2 items of each cascade to avoid leakage.
Add a new model by creating pl/models/<your_name>.py with a factory:
def build_model(vocab_size: int, model_cfg: dict, optim_cfg: dict, **kwargs):
# return a pl.LightningModule
...Conventions
- Sequence models (e.g.,
cyan_rnn) only needvocab_size,model_cfg,optim_cfg. - Time-aware models should accept
events(list of(user_idx, topic_idx, ts)) and optionallynum_topics. - Set
hparams.topkfrommodel_cfgfor consistent metric computation. - Use
AdamWwithlr,weight_decayfromoptim_cfgfor consistency.
Dynamic loading
- The trainer imports
pl.models.<name>and callsbuild_model(...)(orbuild_baseline_model(...)if provided). - Example builder signatures in the repo: see
cyan_rnn.py,dyhgcn.py,mshgat.py,sieve.py.
EchoFlow/
├── configs/ # YAML configs for experiments
├── dataset/ # Built-in datasets (CSV interactions.inter)
├── pl/
│ ├── data_module.py # CascadesDataModule: reading, encoding, splits
│ ├── layers/ # Core layers: time bins, bipartite graphs, transformer PE
│ ├── models/ # Model zoo: cyan_rnn, dyhgcn, mshgat, sieve
│ └── train.py # Training/validation/test entrypoint (CLI + YAML)
└── utils/
├── metrics.py # Hit@k, MAP@k, accuracy
├── diffusion_events.py# Build training diffusion events from cascades
└── train_summary.py # CSV epoch summaries and final report writer
Welcome! Please:
- Use clear commit messages (e.g.,
feat(model): add new attention block). - Keep style consistent and add docstrings/comments where helpful.
- Provide small, reproducible datasets or script snippets when reporting issues.
This project is licensed under the MIT License. See LICENSE for details.
—
If you use EchoFlow in academic work or production, please consider starring the repo. Contributions and feedback are warmly appreciated.