本文介紹如何運行圖神經網路類論文的代碼,
《EMNLP 2019開源論文:針對短文本分類的異質圖注意力網路》
論文介紹:https://mp.weixin.qq.com/s/eCmvUaM4Vg5KCFQJcRO-TQ
論文地址:https://www.paperweekly.site/papers/3211
GitHub代碼實作地址:https://github.com/ytc272098215/HGAT
一、需要的環境:
Anaconda3 (Python 3.6或3.7)、Pytorch、gensim
二、環境配置簡要指南:
1. Anaconda下載地址https://www.anaconda.com/download/,根據自己的平臺選擇下載安裝包,并完成安裝,Anaconda是很常用的平臺,安裝程序不再贅述,
2. Pytorch安裝官網https://pytorch.org/get-started/locally/,在Anaconda Prompt執行以下命令:
conda install pytorch torchvision cudatoolkit=10.2 -c pytorch
由于Pytorch較大,如果Pytorch安裝緩慢,可以添加清華大學鏡像站至Anaconda,在終端中輸入以下命令:
conda config --add channels http://mirror.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels http://mirror.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
以及:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
然后要注意將官網提供的命令列中的-c pytorch去除,即運行
conda install pytorch torchvision cudatoolkit=10.2
等待一段時間即可安裝成功,
3. gensim安裝官網https://pypi.org/project/gensim/,在Anaconda Prompt執行以下命令:
pip install --upgrade gensim
4. 檢查環境
利用 import xxx 或者 pip list 檢查是否正確安裝,
可能出現的錯誤:
a.無法定位程式輸入點于……元件

找到anaconda安裝路徑,進入 \DLLS 檔案夾,查看 libcrypto-1_1-x64.dll 檔案的修改日期,進入 \Library\bin 檔案夾,查看 libcrypto-1_1-x64.dll 檔案修改日期,如果兩檔案修改日期不同,用 DLLS檔案夾下的 libcrypto-1_1-x64.dll 替換 bin檔案夾下的libcrypto-1_1-x64.dll,重新嘗試安裝
b.The environment is inconsistent, please check the package plan carefully.
解決方法:
conda install anaconda
三、運行代碼
在Anaconda Prompt執行命令
cd ./model/code/
python train.py
cd ./model/code/ 是說要定位到代碼所在檔案夾,例如:

程式將開始運行,初始資料集是example

四、更換資料集
https://github.com/ytc272098215/HGAT提供了更多的資料集,可以通過Google Drive下載,解壓后如下:

以運行agnews資料集為例,需要將agnews檔案夾放到 .\model\data 檔案夾,更改 .\model\code 中 train.py 的一句代碼,
將
dataset = 'example'
改為
dataset = 'agnews'
保存后運行即可,
可能出現的錯誤:
No such file or director

解決方法:注意檔案是否正確放在.\model\data 檔案夾,檢查之前 cd 進入的根目錄是否正確,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/155931.html
標籤:其他
上一篇:關于jupyter notebook 使用tensorflow-gpu 2.0版本 安裝及測驗 關于cuda以及chdnn的pip安裝
下一篇:Pytorch入門之張量
