From 5f218dad4ed1415aa6d842bc20785c61e74e5405 Mon Sep 17 00:00:00 2001 From: Theheavens <34649403+Theheavens@users.noreply.github.com> Date: Fri, 7 Jan 2022 15:06:08 +0800 Subject: [PATCH] a nightly update --- CONTRIBUTING.md | 3 +++ README.md | 2 +- README_ZH.md | 30 ++++++++++++------------- openhgnn/trainerflow/link_prediction.py | 9 ++++---- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b84a8261..f1850dda 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,4 +26,7 @@ Contribution is always welcomed. Please feel free to open an issue or email to t - Quan Gan - Minjie Wang - [Jian Zhang](https://github.com/zhjwy9343) +- **Peng Cheng Laboratory** + - Fangqing Jiang + - Hui Wang diff --git a/README.md b/README.md index c8a62d3c..b5b98995 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ The link will give some basic usage. ## Contributors -OpenHGNN Team[GAMMA LAB] & DGL Team. +OpenHGNN Team[GAMMA LAB], DGL Team and Peng Cheng Laboratory. See more in [CONTRIBUTING](./CONTRIBUTING.md). diff --git a/README_ZH.md b/README_ZH.md index d0774bb6..e4adb1c7 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -6,7 +6,7 @@ [**启智社区(中文版)**](https://git.openi.org.cn/GAMMALab/OpenHGNN)| [**Github Community (English)**](https://github.com/BUPT-GAMMA/OpenHGNN) -OpenHGNN是一个基于 [DGL [Deep Graph Library]](https://github.com/dmlc/dgl) 和 [PyTorch](https://pytorch.org/) 的开源异质图神经网络工具包, 集成了异质图神经网络的前沿模型. +OpenHGNN是一个基于 [DGL [Deep Graph Library]](https://github.com/dmlc/dgl) 和 [PyTorch](https://pytorch.org/) 的开源异质图神经网络工具包,集成了异质图神经网络的前沿模型。 ## 新闻 @@ -23,9 +23,9 @@ OpenHGNN是一个基于 [DGL [Deep Graph Library]](https://github.com/dmlc/dgl) ## 关键特性 -- 易用: OpenHGNN提供了了易用的接口在给定的模型和数据集上运行实验, 且集成了 [optuna](https://optuna.org/) 进行超参数优化. -- 可扩展: 用户可以定义定制化的任务/模型/数据集来对新的场景应用新的模型. -- 高效: 底层的DGL框架提供了提供了高效的API. +- 易用:OpenHGNN提供了了易用的接口在给定的模型和数据集上运行实验,且集成了 [optuna](https://optuna.org/) 进行超参数优化。 +- 可扩展:用户可以定义定制化的任务/模型/数据集来对新的场景应用新的模型。 +- 高效:底层的DGL框架提供了提供了高效的API。 ## 开始使用 @@ -44,21 +44,21 @@ conda create -n openhgnn python=3.7 source activate openhgnn ``` -**2. Pytorch:** 安装Pytorch, 参考[PyTorch安装文档](https://pytorch.org/get-started/locally/). +**2. Pytorch:** 安装Pytorch,参考[PyTorch安装文档](https://pytorch.org/get-started/locally/)。 ```bash # CUDA versions: cpu, cu92, cu101, cu102, cu101, cu111 pip install torch==1.8.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html ``` -**3. DGL:** 安装 DGL, 参考[DGL安装文档](https://www.dgl.ai/pages/start.html). +**3. DGL:**安装 DGL,参考[DGL安装文档](https://www.dgl.ai/pages/start.html)。 ```bash # CUDA versions: cpu, cu101, cu102, cu110, cu111 pip install --pre dgl-cu101 -f https://data.dgl.ai/wheels-test/repo.html ``` -**4. 下载OpenHGNN, 安装依赖:** +**4. 下载OpenHGNN,安装依赖:** ```bash git clone https://github.com/BUPT-GAMMA/OpenHGNN @@ -85,13 +85,13 @@ python main.py -m model_name -d dataset_name -t task_name -g 0 --use_best_config ``--dataset -d`` 数据集名 -``--gpu -g`` 控制你使用哪一个GPU, 如果没有GPU, 设定 -g -1. +``--gpu -g`` 控制你使用哪一个GPU,如果没有GPU,设定 -g -1。 -``--use_best_config`` use_best_config 意味着你使用该模型在该数据集下最优的配置, 如果你想要设定不同的超参数,请手动修改 [配置文件](./openhgnn/config.ini) . 使用最佳配置会覆盖配置文件中的参数。 +``--use_best_config`` use_best_config 意味着你使用该模型在该数据集下最优的配置,如果你想要设定不同的超参数,请手动修改 [配置文件](./openhgnn/config.ini)。使用最佳配置会覆盖配置文件中的参数。 -``--use_hpo`` 除了 use_best_config, 我们还提供了一个超参数的 [样例](./openhgnn/auto) 来自动查找最佳超参数. +``--use_hpo`` 除了 use_best_config,我们还提供了一个超参数的 [样例](./openhgnn/auto) 来自动查找最佳超参数。 -``--load_from_pretrained`` 从默认检查点加载模型. +``--load_from_pretrained`` 从默认检查点加载模型。 示例: @@ -99,9 +99,9 @@ python main.py -m model_name -d dataset_name -t task_name -g 0 --use_best_config python main.py -m GTN -d imdb4GTN -t node_classification -g 0 --use_best_config ``` -**提示**: 如果你对某个模型感兴趣,你可以参考下列的模型列表. +**提示**: 如果你对某个模型感兴趣,你可以参考下列的模型列表。 -请参考 [文档](https://openhgnn.readthedocs.io/en/latest/index.html) 了解更多的基础和进阶的使用方法. +请参考 [文档](https://openhgnn.readthedocs.io/en/latest/index.html) 了解更多的基础和进阶的使用方法。 ## [模型](./openhgnn/models/#Model) @@ -142,7 +142,7 @@ python main.py -m GTN -d imdb4GTN -t node_classification -g 0 --use_best_config ## 贡献者 -OpenHGNN 团队 [北邮 GAMMA 实验室] 和 DGL 团队. +OpenHGNN团队[北邮 GAMMA 实验室]、DGL 团队和鹏城实验室。 -[贡献者名单](./CONTRIBUTING.md). +[贡献者名单](./CONTRIBUTING.md) diff --git a/openhgnn/trainerflow/link_prediction.py b/openhgnn/trainerflow/link_prediction.py index 49dc9f74..311907af 100644 --- a/openhgnn/trainerflow/link_prediction.py +++ b/openhgnn/trainerflow/link_prediction.py @@ -52,7 +52,7 @@ def __init__(self, args): self.target_link = self.task.dataset.target_link self.args.out_node_type = self.task.get_out_ntype() self.train_hg = self.task.get_train().to(self.device) - if hasattr(self.args, 'flag_add_reverse_edges'): + if hasattr(self.args, 'flag_add_reverse_edges') or self.args.dataset == 'MTWM': self.train_hg = add_reverse_edges(self.train_hg) if not hasattr(self.args, 'out_dim'): self.args.out_dim = self.args.hidden_dim @@ -89,7 +89,7 @@ def preprocess(self): The positive graph and the negative graph will contain the same set of nodes as the original graph. """ super(LinkPrediction, self).preprocess() - + def train(self): self.preprocess() stopper = EarlyStopping(self.patience, self._checkpoint) @@ -101,19 +101,18 @@ def train(self): if epoch % self.evaluate_interval == 0: val_metric = self._test_step('valid') self.logger.train_info(f"Epoch: {epoch:03d}, train loss: {loss:.4f}. " + self.logger.metric2str(val_metric)) - early_stop = stopper.step_score(val_metric['valid']['loss'], self.model) + early_stop = stopper.loss_step(val_metric['valid']['loss'], self.model) if early_stop: self.logger.train_info(f'Early Stop!\tEpoch:{epoch:03d}.') break - self.logger.train_info(f"Valid score = {stopper.best_score: .4f}") stopper.load_model(self.model) - # Test if self.args.dataset in ['HGBl-amazon', 'HGBl-LastFM', 'HGBl-PubMed']: # Test in HGB datasets. self.model.eval() with torch.no_grad(): val_metric = self._test_step('valid') + self.logger.train_info(self.logger.metric2str(val_metric)) h_dict = self.model.input_feature() embedding = self.model(self.hg, h_dict) score = th.sigmoid(self.task.ScorePredictor(self.task.test_hg, embedding, self.r_embedding))