Skip to content

Commit

Permalink
a nightly update
Browse files Browse the repository at this point in the history
  • Loading branch information
Theheavens committed Jan 7, 2022
1 parent 3fade32 commit 5f218da
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

30 changes: 15 additions & 15 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/) 的开源异质图神经网络工具包集成了异质图神经网络的前沿模型

## 新闻

Expand All @@ -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

## 开始使用

Expand All @@ -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
Expand All @@ -85,23 +85,23 @@ 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`` 从默认检查点加载模型

示例:

```bash
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)

Expand Down Expand Up @@ -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)

9 changes: 4 additions & 5 deletions openhgnn/trainerflow/link_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand Down

0 comments on commit 5f218da

Please sign in to comment.