Master thesis conducted at the University of Amsterdam, in collaboration with Socialdatabase.
The repository is derived from PECOS.
Create a conda environment:
conda create -n "giant-xrt" python=3.8
conda activate giant-xrt
Install pytorch:
With cuda:
conda install pytorch==1.9.0 cudatoolkit=10.2 -c pytorch
Without cuda:
conda install pytorch==1.9.0 -c pytorch
Install GNN related packages
With cuda:
ptcu_version="1.9.0+cu102"
Without cuda:
ptcu_version="1.9.0+cpu"
pip install torch-scatter -f "https://pytorch-geometric.com/whl/torch-${ptcu_version}.html"
pip install torch-sparse -f "https://pytorch-geometric.com/whl/torch-${ptcu_version}.html"
pip install torch-cluster -f "https://pytorch-geometric.com/whl/torch-${ptcu_version}.html"
pip install torch-spline-conv -f "https://pytorch-geometric.com/whl/torch-${ptcu_version}.html"
pip install torch-geometric
pip install ogb==1.3.2
Set up and install PECOS dependencies:
python3 -m pip install --editable ./
dataset=ogbn-arxiv # or ogbn-products
mkdir experiments/graphSAGE_nodedegree
python -u baseline_models/gnn.py \
--use_sage \
--node_feature degree \
--dataset_name ${dataset} \
--hidden_channels 50 | tee -a experiments/graphSAGE_nodedegree/train.log
# Download data
cd data/proc_data_multi_task
dataset=ogbn-arxiv # or ogbn-products
bash download_data.sh ${dataset}
cd ../../
# Train model
mkdir experiments/bert_classifier
mkdir models/bert_classifier
source activate giant-xrt
python -u baseline_models/bert_classifier.py \
--model_dir models/bert_classifier \
--experiment_dir experiments/bert_classifier \
--raw-text-path data/proc_data_multi_task/ogbn-arxiv/X.all.txt \
--text_tokenizer_path data/proc_data_multi_task/ogbn-arxiv/xrt_models/text_encoder/text_tokenizer \
--dataset ${dataset} \
| tee -a experiments/bert_classifier/train.log
# Download data
cd data/proc_data_multi_task
dataset=ogbn-arxiv # or ogbn-products
bash download_data.sh ${dataset}
cd ../../
# Process data
source activate giant-xrt
bash proc_data_multi_task.sh ${dataset}
# Train model
experiment_name=giant_mlp
runs=10
data_dir=data/proc_data_multi_task/${dataset}
model_dir=models/${experiment_name}
experiment_dir=experiments/${experiment_name}
cache_dir=models/cache
params_path=data/proc_data_multi_task/params_xrt_${dataset}.json
bash GIANT_pipeline.sh ${data_dir} ${model_dir} ${experiment_dir} ${cache_dir} ${params_path} ${runs}
Change GIANT_pipeline.sh for different settings of GIANT+MLP:
--model-shortcut "bert-base-uncased"--model-shortcut "distilbert-base-uncased"--model-shortcut "sentence-transformers/all-distilroberta-v1"--include-Xval-Xtest-for-training "true"--include-Xval-Xtest-for-training "false"Note: in this repository, we make a clear distinction between multi-label classification tasks and multi-class classification tasks (whereas in real-life, the term "label" and "class" might be used interchangeably)
Multi-class classification: each input will have only one output class. This is the case of the main node classification task.Multi-label classification: each input can have multiple output labels. This is the case of the auxiliary neighborhood prediction task.The proposed model learns both the Multi-class classification task and the Multi-label classification task, and backpropagate the loss in tandem for both tasks
# Download data
cd data/proc_data_multi_task
dataset=ogbn-arxiv # or ogbn-products
bash download_data.sh ${dataset}
cd ../../
# Process data
source activate giant-xrt
bash proc_data_multi_task.sh ${dataset}
# Train model
experiment_name=E2EG
runs=10
data_dir=data/proc_data_multi_task/${dataset}
model_dir=models/${experiment_name}
experiment_dir=experiments/${experiment_name}
cache_dir=models/cache
params_path=data/proc_data_multi_task/params_mtask_${dataset}.json
bash multi_task_pipeline_${dataset}.sh ${data_dir} ${model_dir} ${experiment_dir} ${cache_dir} ${params_path} ${runs}
No need to change anything if want to use best model setting.
Change multi_task_pipeline_ogbn-arxiv.sh or multi_task_pipeline_ogbn-products.sh for different settings of E2EG:
ogbn-arxiv):
--freeze-mclass-head-range "0|2"--weight-loss-strategy "include_mclass_loss_later_at_round_2"--include-additional-mclass-round "true"--include-additional-mclass-round-HEAD "true"--model-shortcut "bert-base-uncased"--model-shortcut "distilbert-base-uncased"--model-shortcut "sentence-transformers/all-distilroberta-v1"--include-Xval-Xtest-for-training "true"--include-Xval-Xtest-for-training "false"Have to create sweep config folder and define the sweep YAML file first. For more instructions see wandb quickstart.
dataset=ogbn-arxiv # or ogbn-products
# Run sweep
experiment_name=E2EG_sweep
data_dir=data/proc_data_multi_task/${dataset}
model_dir=models/${experiment_name}
experiment_dir=experiments/${experiment_name}
cache_dir=models/cache
params_path=data/proc_data_multi_task/params_mtask_${dataset}.json
bash hyperparams_sweep.sh ${data_dir} ${model_dir} ${experiment_dir} ${cache_dir} ${params_path} sweep_configs/${experiment_name}
After training an E2EG model according to 2.2.1, run the following to get the text embedding using E2EG:
dataset=ogbn-arxiv # or ogbn-products
experiment_name=E2EG
runs=1
data_dir=data/proc_data_multi_task/${dataset}
model_dir=models/${experiment_name}
experiment_dir=experiments/${experiment_name}
cache_dir=models/cache
params_path=data/proc_data_multi_task/params_mtask_${dataset}.json
bash encode_mtask.sh ${data_dir} ${model_dir} ${experiment_dir} ${cache_dir} ${params_path} ${runs}
The encoding is then saved to models/E2EG/run0/X.all.e2eg-emb.npy.
This encoding can then be used the same way as the encoding from GIANT-XRT.
For the experiments in our paper, we replace the embedding from GIANT-XRT with our embedding from E2EG in the top 1 pipelines for ogbn-arxiv and ogbn-products on the OGB leaderboard (Date: 3 June 2022).
ogbn-arxiv: use E2EG's embedding and follows the instruction of the top 1 pipeline's DRGCN repo.ogbn-products: use E2EG's embedding and follows the instruction of the top 1 pipeline's SCR repo.Jupyter Notebook
65.1%
Python
22.5%
C++
11.3%
Shell
1.0%
Master thesis conducted at the University of Amsterdam, in collaboration with Socialdatabase.
The repository is derived from PECOS.
Create a conda environment:
conda create -n "giant-xrt" python=3.8
conda activate giant-xrt
Install pytorch:
With cuda:
conda install pytorch==1.9.0 cudatoolkit=10.2 -c pytorch
Without cuda:
conda install pytorch==1.9.0 -c pytorch
Install GNN related packages
With cuda:
ptcu_version="1.9.0+cu102"
Without cuda:
ptcu_version="1.9.0+cpu"
pip install torch-scatter -f "https://pytorch-geometric.com/whl/torch-${ptcu_version}.html"
pip install torch-sparse -f "https://pytorch-geometric.com/whl/torch-${ptcu_version}.html"
pip install torch-cluster -f "https://pytorch-geometric.com/whl/torch-${ptcu_version}.html"
pip install torch-spline-conv -f "https://pytorch-geometric.com/whl/torch-${ptcu_version}.html"
pip install torch-geometric
pip install ogb==1.3.2
Set up and install PECOS dependencies:
python3 -m pip install --editable ./
dataset=ogbn-arxiv # or ogbn-products
mkdir experiments/graphSAGE_nodedegree
python -u baseline_models/gnn.py \
--use_sage \
--node_feature degree \
--dataset_name ${dataset} \
--hidden_channels 50 | tee -a experiments/graphSAGE_nodedegree/train.log
# Download data
cd data/proc_data_multi_task
dataset=ogbn-arxiv # or ogbn-products
bash download_data.sh ${dataset}
cd ../../
# Train model
mkdir experiments/bert_classifier
mkdir models/bert_classifier
source activate giant-xrt
python -u baseline_models/bert_classifier.py \
--model_dir models/bert_classifier \
--experiment_dir experiments/bert_classifier \
--raw-text-path data/proc_data_multi_task/ogbn-arxiv/X.all.txt \
--text_tokenizer_path data/proc_data_multi_task/ogbn-arxiv/xrt_models/text_encoder/text_tokenizer \
--dataset ${dataset} \
| tee -a experiments/bert_classifier/train.log
# Download data
cd data/proc_data_multi_task
dataset=ogbn-arxiv # or ogbn-products
bash download_data.sh ${dataset}
cd ../../
# Process data
source activate giant-xrt
bash proc_data_multi_task.sh ${dataset}
# Train model
experiment_name=giant_mlp
runs=10
data_dir=data/proc_data_multi_task/${dataset}
model_dir=models/${experiment_name}
experiment_dir=experiments/${experiment_name}
cache_dir=models/cache
params_path=data/proc_data_multi_task/params_xrt_${dataset}.json
bash GIANT_pipeline.sh ${data_dir} ${model_dir} ${experiment_dir} ${cache_dir} ${params_path} ${runs}
Change GIANT_pipeline.sh for different settings of GIANT+MLP:
--model-shortcut "bert-base-uncased"--model-shortcut "distilbert-base-uncased"--model-shortcut "sentence-transformers/all-distilroberta-v1"--include-Xval-Xtest-for-training "true"--include-Xval-Xtest-for-training "false"Note: in this repository, we make a clear distinction between multi-label classification tasks and multi-class classification tasks (whereas in real-life, the term "label" and "class" might be used interchangeably)
Multi-class classification: each input will have only one output class. This is the case of the main node classification task.Multi-label classification: each input can have multiple output labels. This is the case of the auxiliary neighborhood prediction task.The proposed model learns both the Multi-class classification task and the Multi-label classification task, and backpropagate the loss in tandem for both tasks
# Download data
cd data/proc_data_multi_task
dataset=ogbn-arxiv # or ogbn-products
bash download_data.sh ${dataset}
cd ../../
# Process data
source activate giant-xrt
bash proc_data_multi_task.sh ${dataset}
# Train model
experiment_name=E2EG
runs=10
data_dir=data/proc_data_multi_task/${dataset}
model_dir=models/${experiment_name}
experiment_dir=experiments/${experiment_name}
cache_dir=models/cache
params_path=data/proc_data_multi_task/params_mtask_${dataset}.json
bash multi_task_pipeline_${dataset}.sh ${data_dir} ${model_dir} ${experiment_dir} ${cache_dir} ${params_path} ${runs}
No need to change anything if want to use best model setting.
Change multi_task_pipeline_ogbn-arxiv.sh or multi_task_pipeline_ogbn-products.sh for different settings of E2EG:
ogbn-arxiv):
--freeze-mclass-head-range "0|2"--weight-loss-strategy "include_mclass_loss_later_at_round_2"--include-additional-mclass-round "true"--include-additional-mclass-round-HEAD "true"--model-shortcut "bert-base-uncased"--model-shortcut "distilbert-base-uncased"--model-shortcut "sentence-transformers/all-distilroberta-v1"--include-Xval-Xtest-for-training "true"--include-Xval-Xtest-for-training "false"Have to create sweep config folder and define the sweep YAML file first. For more instructions see wandb quickstart.
dataset=ogbn-arxiv # or ogbn-products
# Run sweep
experiment_name=E2EG_sweep
data_dir=data/proc_data_multi_task/${dataset}
model_dir=models/${experiment_name}
experiment_dir=experiments/${experiment_name}
cache_dir=models/cache
params_path=data/proc_data_multi_task/params_mtask_${dataset}.json
bash hyperparams_sweep.sh ${data_dir} ${model_dir} ${experiment_dir} ${cache_dir} ${params_path} sweep_configs/${experiment_name}
After training an E2EG model according to 2.2.1, run the following to get the text embedding using E2EG:
dataset=ogbn-arxiv # or ogbn-products
experiment_name=E2EG
runs=1
data_dir=data/proc_data_multi_task/${dataset}
model_dir=models/${experiment_name}
experiment_dir=experiments/${experiment_name}
cache_dir=models/cache
params_path=data/proc_data_multi_task/params_mtask_${dataset}.json
bash encode_mtask.sh ${data_dir} ${model_dir} ${experiment_dir} ${cache_dir} ${params_path} ${runs}
The encoding is then saved to models/E2EG/run0/X.all.e2eg-emb.npy.
This encoding can then be used the same way as the encoding from GIANT-XRT.
For the experiments in our paper, we replace the embedding from GIANT-XRT with our embedding from E2EG in the top 1 pipelines for ogbn-arxiv and ogbn-products on the OGB leaderboard (Date: 3 June 2022).
ogbn-arxiv: use E2EG's embedding and follows the instruction of the top 1 pipeline's DRGCN repo.ogbn-products: use E2EG's embedding and follows the instruction of the top 1 pipeline's SCR repo.Jupyter Notebook
65.1%
Python
22.5%
C++
11.3%
Shell
1.0%