# MAXP-DGL-Graph-Machine-Learning-Challenge
<!-- ![title](./title.png) -->
[ 2021 MAXP 命题赛 任务一:[基于DGL的图机器学习任务 ](https://www.biendata.xyz/competition/maxp_dgl/) ] | [ Team: *Graph@ICT* ]
[2021-MAXP-DGL图机器学习大赛解决方案-8-Graph@ICT.pdf](./2021-MAXP-DGL图机器学习大赛解决方案-8-Graph@ICT.pdf)
最终Test成绩(b榜):rank6🥉,[[获奖名单](https://www.biendata.xyz/competition/maxp_dgl/winners/)] | [[答辩视频](https://www.bilibili.com/video/BV1fr4y1v737?p=2)]。
有任何问题请联系 chihuixuan21@mails.ucas.ac.cn.
P.S. [一位大佬整理的前排解决方案](https://github.com/CYBruce/MAXP-DGL-solutions)。
<!-- ![res](./result.png) -->
## 依赖包:
```bash
dgl-cu102==0.7.2
pytorch==1.7.0
sklearn
pandas
numpy
datetime
tqdm
...
```
## 环境安装
<!-- 依赖包见`requirement.txt`. -->
```bash
pip install -r requirement.txt
```
## GPU
+ Tesla V100 (32GB)
## 关键路径
```bash
.
|--dataset
|--outputs
|--GAMLP
| |--scripts
| |--output
|--gnn
|--node2vec
```
## 运行 Final Test
**为了完整复现,我们建议从头进行端到端的训练(Scalable GNN训练的很快)**
### 0、准备工作和数据路径
```bash
cd MAXP_DGL_Graph/
mkdir dataset # 存放所有数据集
mkdir outputs # 存放输出结果
```
### 1、 运行jupyter进行数据预处理
```python
# 生成feature和DGL graph
process-1.ipynb
process-2.ipynb
process-3.ipynb
process-4.ipynb
# 根据test nodes构造sample_submission_for_test.csv
gen_test_submitcsv.ipynb
```
### 2、构造必要的id--index映射关系
```bash
cd gnn/
python3 csv_idx_map.py
```
### 3、运行node2vec得到所有节点的embedding
```bash
cd node2vec/
nohup python main.py > ../outputs/node2vec.log 2>&1 &
```
大约需要12h。
也可以直接下载`node2vec_emb.zip`,放到`./dataset`中并解压。链接: [https://pan.baidu.com/s/1Kg3bLPJ6q8yUNjiPtQUBtA](https://pan.baidu.com/s/1Kg3bLPJ6q8yUNjiPtQUBtA) 密码: dvuw
### 4、训练node2vec特征增强的GAMLP (8-fold)
```bash
cd GAMLP/scripts/
nohup bash train_maxp_kfold.sh > ../output/gamlp.log 2>&1 &
```
大约需要16h。
也可以直接下载`gamlp_ckpt.zip`,放到`./dataset`中并解压,**解压后可以不跑第4步以及之前的代码,直接运行第5步**。链接: [https://pan.baidu.com/s/1Q3v0Hlwqu8qI9-SCNBjt4A](https://pan.baidu.com/s/1Q3v0Hlwqu8qI9-SCNBjt4A) 密码: tn8h
每一折的best model模型文件`model.zip`可以从此处下载,解压后放到`./GAMLP/output/maxp`中。链接: [https://pan.baidu.com/s/1JfYz0oUcVexxMoCZzsTqXQ](https://pan.baidu.com/s/1JfYz0oUcVexxMoCZzsTqXQ) 密码: 6e5b
### 5、C&S和模型融合
```bash
cd GAMLP/
nohup python3 ensemble.py --all_train --gpu 1 > ./output/ensem.log 2>&1 &
```
大约需要2h。
### 6、下载submit文件
最终test:`./outputs/submit_test_gamlp_ensem_xxxx-xx-xx_n2v.csv`
最终valid:`./outputs/submit_val_gamlp_ensem_xxxx-xx-xx_n2v.csv`
| Method | Score |
|:-:|:-:|
| GAMLP (leaky-relu, 9 hops, 8-fold) + node2vec + C&S (DAD, AD) + Model Merge (+GAMLP_8fold_seed_{0-2}) | 49.7822086481499 |
| GAMLP (leaky-relu, 9 hops, 8-fold) + C&S (DAD, AD) + Model Merge (+GAMLP_8fold_seed_{0-2}) | 49.7923833548815 |
| GAMLP (leaky-relu, 9 hops, 8-fold) + C&S (DAD, AD) + Model Merge (+GAMLP_8fold_seed_{0}) | 49.7767704428278 |
----
## Valid提交结果
a榜(Valid)结果记录。a榜最终成绩为14。
|Date | Method | Score |
|:-:|:-:|:-:|
| 2021-11-17 | GAMLP (leaky-relu, 9 hops, 8-fold) + node2vec + C&S (DAD, AD) + Model Merge (+GAMLP_8fold_seed_{0-1}) | 55.53829808307 |
| 2021-11-13 | GAMLP (leaky-relu, 9 hops) + node2vec + C&S (DAD, AD) + Model Merge (+GAMLP_seed_{0-9}) + lr adjustment | 55.5081350224647 |
| 2021-11-08 | GAMLP (leaky-relu) + node2vec + C&S + Model Merge (+GAMLP_seed_{0-9}) | 55.3825306357653 |
| 2021-11-06 | GAMLP + node2vec + C&S + Model Merge (+GAMLP_seed_{0-9}) | 55.3694749826675 |
| 2021-11-05| GAMLP + node2vec + C&S + Model Merge (+GAMLP_seed_1, +SAGN_SE_stage_0, +SAGN_SE_stage_2, +SAGE, +GAT) | 55.0993580220235 |
| 2021-11-04| GAMLP + node2vec + C&S + Model Merge (+SAGN-SE, +SAGE, +GAT) | 55.0070680604702 |
| 2021-10-31 | SAGN + node2vec + SE + Model Merge (+GAT, +SAGE) + C&S | 54.5420166932282 |
| 2021-10-24 | GAT + node2vec + FLAG + C&S + Model Merge (+SAGE, +GCN) | 54.2394856973069 |
| 2021-10-22 | GAT + node2vec + FLAG + C&S | 53.9846753644328 |
| ... | ... | ... |
| 2021-10-18 | GAT+res+bn+dropout+train_label的特征增强+FLAG +增加训练epoch(5--10) | 52.95 |
| 2021-10-17 | GAT+res+bn+dropout+train_label的特征增强+FLAG +inception(已注释) | 小于52.53 |
| 2021-10-15 | GAT+res+bn+dropout+train_label的特征增强 +FLAG | 52.53 |
| 2021-10-15 | GAT+res+bn+dropout +train_label的特征增强 | 51.27 |
| 2021-10-14 | GAT+ res+bn+dropout,调整了采样策略 | 50.79 |
| 2021-10-13 | GraphSAGE +一些tricks | 48.48 |
| 2021-10-13 | GraphSAGE(baseline) | 48.14 |
<!-- ## 代码库包括2个部分:
1. 用于数据预处理的4个Jupyter Notebook
2. 用DGL构建的3个GNN模型(GCN,GraphSage和GAT),以及训练模型所用的代码和辅助函数。 -->
## 全部探索如下:
[查看项目的整个目录树.](#Tree)
平均 degree: 16.9152 (加上反向边和self-loop后)
### 运行jupyter进行数据预处理
```bash
cd MAXP_DGL_Graph/
mkdir dataset
mkdir outputs
```
对于4个Jupyter Notebook文件,请使用Jupyter环境运行,并注意把其中的竞赛数据文件所在的文件夹替换为你自己保存数据文件的文件夹。
并记录下你处理完成后的数据文件所在的位置,供下面模型训练使用。
### 运行node2vec并保存Embedding
```bash
cd node2vec/
# run node2vec in backward
nohup python main.py > ../outputs/node2vec.log 2>&1 &
tail -f ../outputs/node2vec.log
```
结果保存在`../dataset/emb.pt`中, 下载链接[emb.pt](https://drive.google.com/u/0/uc?id=1gvJQBTbl8sIaJND_tBVA3Ua2TcU-4Kfy&export=download) (1.7GB)。
### 运行SGC并保存Embedding
```bash
cd sgc/
python3 main.py
```
结果保存在`../dataset/sgc_emb.pt`中。
### 运行GNN模型并保存test结果
对于GNN的模型,需要先cd到gnn目录,然后运行:
```bash
cd gnn/
# generate index map
python csv_idx_map.py
# then run gnn in backward
nohup python3 model_train.py --GPU 1 --use_emb node2vec --use_label --flag --all_train > ../outputs/train1.log 2>&1 &
# check the result in terminal
tail -f ../outputs/train1.log
# or
python3 model_train.py --data_path ../dataset --gnn_model graphsage --hidden_dim 64 --n_layers 2 --fanout 20,20 --batch_size 4096 --GPU 1 --out_path ./
```
test结果保存在`../outputs/submit_xxxx-xx-xx.csv`中。
### 使用C&S方法并进行模型融合
目前融合GAT, GraphSAGE, GCN, 对logits进行加权求和。
```bash
# pretrain model in backward
cd gnn/
# graphattn
nohup python3 model_train.py --GPU 1 --use_emb node2vec --save_emb --all_train > ../outputs/train1.log 2>&1 &
# graphsage
nohup python3 model_train.py --GPU 0 --use_emb node2vec --save_emb --gnn_model graphsage --flag --all_train > ../outputs/train.log 2>&1 &
# graphconv
nohup python3 model_train.py --GPU 1 --use_emb node2vec --save_emb --gnn_model graphconv --flag --all_train > ../outputs/train1.log 2>&1 &
# run c&s
cd ../correct_and_smooth
python3 main.py --all_train
```
inference logits保存在`../dataset.y_soft.pt` (GAT), `../dataset.y_soft_sage.pt` (GraphSAGE), `../dataset.y_soft_conv.pt` (GCN)中。
test结果保存在`../outputs/submit_cs_xxxx-xx-xx.csv`中。
### SAGN+SE使用方法
进入`SAGN_with_SLE`文件夹,按照指示进行运行。
```bash
cd SAGN_with_SLE/scripts/maxp
nohup bash train_maxp_sagn_use_label.sh > ../../outputs/sagn.log 2>&1 &
# c&s + merge models
cd SAGN_with_SLE/src/
python3 post_process.py
```
inference logits保存在`./SAGN_with_SLE/intermediate_outputs/maxp/sagn/use_labels_False_use_feats_True_K_5_label_K_9_probs_seed_*_stage_*.pt
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于DGL的图机器学习任务.zip (87个子文件)
MAXP_DGL_Graph-main
GAMLP
utils.py 9KB
papers100M_perf.png 103KB
layer.py 5KB
main.py 19KB
heteo_data.py 6KB
model.py 25KB
ensemble.py 11KB
products_perf.png 138KB
requirements.txt 36B
cs.py 11KB
load_dataset.py 12KB
logger.py 2KB
GAMLP.pdf 674KB
README.md 3KB
mag_perf.png 86KB
scripts
train_maxp.sh 524B
train_maxp_kfold.sh 541B
train_maxp_all.sh 524B
sgc
utils.py 2KB
main.py 1KB
correct_and_smooth
utils.py 2KB
__init__.py 0B
main.py 7KB
model.py 7KB
process-3.ipynb 19KB
process-4.ipynb 23KB
title.png 896KB
process-2.ipynb 8KB
result.png 224KB
node2vec
utils.py 3KB
main.py 2KB
model.py 10KB
SAGN_with_SLE
src
utils.py 7KB
post_process.py 11KB
layers.py 16KB
dataset.py 10KB
models.py 26KB
train_process.py 4KB
sagn.py 24KB
pre_process.py 26KB
gen_models.py 2KB
README.md 3KB
scripts
ogbn-mag
train_ogbn_mag_sagn_TransE.sh 497B
train_ogbn_mag_sagn.sh 500B
ppi_large
train_ppi_large_sagn.sh 565B
cora
train_cora_sagn_use_labels.sh 560B
ogbn-papers100M
train_ogbn_papers100M_sagn_no_labels.sh 547B
train_ogbn_papers100M_sagn_use_label.sh 674B
ppi
train_ppi_sagn.sh 592B
maxp
train_maxp_sagn_use_label.sh 540B
flickr
train_flickr_sagn.sh 579B
ogbn-products
train_ogbn_products_simple_sagn_exponent_no_labels.sh 520B
train_ogbn_products_simple_sagn_uniform_use_labels.sh 556B
train_ogbn_products_sign_no_labels.sh 444B
train_ogbn_products_mlp_use_labels.sh 521B
train_ogbn_products_sign_use_labels.sh 482B
train_ogbn_products_mlp_no_labels.sh 485B
train_ogbn_products_simple_sagn_exponent_use_labels.sh 557B
train_ogbn_products_sagn_use_labels_morestages.sh 605B
train_ogbn_products_sagn_no_labels.sh 485B
train_ogbn_products_simple_sagn_uniform_no_labels.sh 519B
train_ogbn_products_sagn_use_labels.sh 572B
postprocess_ogbn_products_sagn_use_labels.sh 483B
train_ogbn_products_sagn_no_features.sh 516B
yelp
train_yelp_sagn.sh 655B
reddit
train_reddit_sagn.sh 593B
MAXP 2021初赛数据探索和处理-3.ipynb 19KB
gnn
utils.py 4KB
__init__.py 0B
model_utils.py 2KB
test.ipynb 6KB
models.py 23KB
csv_idx_map.py 723B
model_train.py 27KB
README 2.md 1KB
2021-MAXP-DGL图机器学习大赛解决方案-8-Graph@ICT.pdf 7.49MB
requirements.txt 518B
gen_test_submitcsv.ipynb 20KB
process-1.ipynb 27KB
ogb
utils.py 4KB
model_utils.py 2KB
models.py 11KB
model_train.py 27KB
MAXP 2021初赛数据探索和处理-1.ipynb 25KB
README.md 31KB
MAXP 2021初赛数据探索和处理-4.ipynb 23KB
MAXP 2021初赛数据探索和处理-2.ipynb 6KB
共 87 条
- 1
资源评论
博士僧小星
- 粉丝: 1931
- 资源: 5897
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Java的本科探索学习项目设计源码 - 本科探索
- 基于Javascript和Python的微商城项目设计源码 - MicroMall
- 基于Java的网上订餐系统设计源码 - online ordering system
- 基于Javascript的超级美眉网络资源管理应用模块设计源码
- 基于Typescript和PHP的编程知识储备库设计源码 - study-php
- Screenshot_2024-05-28-11-40-58-177_com.tencent.mm.jpg
- 基于Dart的Flutter小提琴调音器APP设计源码 - violinhelper
- 基于JavaScript和CSS的随寻订购网页设计源码 - web-order
- 基于MATLAB的声纹识别系统设计源码 - VoiceprintRecognition
- 基于Java的微服务插件集合设计源码 - wsy-plugins
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功