快速配置运行SACN
Published:
快速配置运行SACN
1. 配置环境
1.1. 安装miniconda
参考文章里面的步骤安装miniconda,在Linux命令行界面运行以下代码(Windows参考这里)
wget -c https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
为了确保您在正确的地方开始,让我们验证您是否已成功安装Anaconda。在终端窗口中,输入以下内容:
conda --version
Conda将回复您已安装的版本号,如:conda 4.9.0
1.2. 创建虚拟环境
参考博客,下面是创建python=3.6版本的环境,取名叫py36
conda create -n py36 python=3.6
1.3. 安装Pytorch
建议直接从官网安装,实验室Linux已安装 CUDA 10.1。
conda install pytorch torchvision torchaudio cudatoolkit=10.1 -c pytorch
验证Pytorch安装是否成功
import torch
torch.cuda.is_available()
1.4. 复制环境
由于我之前已经安装Pytorch,这里我直接复制我已有的纯净Pytorch环境,创建一个专门跑SACN模型的虚拟环境。
conda create -n huiling --clone pytorch
1.5. 激活环境
conda activate huiling
1.6. 删除环境
conda remove --name huiling --all
2. 运行SACN开源代码
2.1. 查阅文档
这时跑神经网络的基础虚拟环境已经搭建完毕,打开SACN开源代码仓库。
2.2. Git开源项目
从GitHub上面把项目copy下来,使用Git代码
git clone https://github.com/JD-AI-Research-Silicon-Valley/SACN.git
由于国内网络环境因素,Github访问代码仓库速度缓慢,遇到大型仓库git困难,故可用镜像网站加速访问。
git clone https://gitclone.com/github.com/JD-AI-Research-Silicon-Valley/SACN.git
这时会自动下载项目代码至SACN文件夹下
cd SACN/
2.3. 安装SACN所需环境
一般作者会将项目特需的环境自动化部署,我们只需要运行作者的部署代码,例如此模型作者在readme中写清了安装步骤:
Installation This repo supports Linux and Python installation via Anaconda.
Install PyTorch 1.0 using official website or Anaconda.
Install the requirements:
pip install -r requirements.txt
Download the default English model used by spaCy, which is installed in the previous step
python -m spacy download en
2.4. 数据预处理
Data Preprocessing
Run the preprocessing script for FB15k-237, WN18RR, FB15k-237-attr and kinship:
sh preprocess.sh
2.5. 运行模型
To run a model, you first need to preprocess the data. This can be done by specifying the process parameter.
For ConvTransE model, you can run it using:
CUDA_VISIBLE_DEVICES=0 python main.py model ConvTransE init_emb_size 100 dropout_rate 0.4 channels 50 lr 0.001 kernel_size 3 dataset FB15k-237 process True
For SACN model, you can run it using:
CUDA_VISIBLE_DEVICES=0 python main.py model SACN dataset FB15k-237 process True
You can modify the hyper-parameters from “src.spodernet.spodernet.utils.global_config.py” or specify the hyper-parameters in the command. For different datasets, you need to tune the parameters.