该存储库提供了我们论文GreaseLM的源代码和数据:用于问答的图推理增强语言模型(ICLR 2022 聚焦)。如果您使用我们的任何代码、处理后的数据或预训练模型,请引用:
@inproceedings { zhang2021 GreaseLM ,
title = { GreaseLM : Graph REASoning Enhanced Language Models } ,
author = { Zhang, Xikun and Bosselut, Antoine and Yasunaga, Michihiro and Ren, Hongyu and Liang, Percy and Manning, Christopher D and Leskovec, Jure } ,
booktitle = { International Conference on Learning Representations } ,
year = { 2021 }
}
GreaseLM 模型架构" alt="" style="max-width: 100%;">
运行以下命令创建conda环境(假设CUDA 10.1):
conda create -y -n GreaseLM python=3.8
conda activate GreaseLM
pip install numpy==1.18.3 tqdm
pip install torch==1.8.0+cu101 torchvision -f https://download.pytorch.org/whl/torch_stable.html
pip install transformers==3.4.0 nltk spacy
pip install wandb
conda install -y -c conda-forge tensorboardx
conda install -y -c conda-forge tensorboard
# for torch-geometric
pip install torch-scatter==2.0.7 -f https://pytorch-geometric.com/whl/torch-1.8.0+cu101.html
pip install torch-cluster==1.5.9 -f https://pytorch-geometric.com/whl/torch-1.8.0+cu101.html
pip install torch-sparse==0.6.9 -f https://pytorch-geometric.com/whl/torch-1.8.0+cu101.html
pip install torch-spline-conv==1.2.1 -f https://pytorch-geometric.com/whl/torch-1.8.0+cu101.html
pip install torch-geometric==1.7.0 -f https://pytorch-geometric.com/whl/torch-1.8.0+cu101.html
自行预处理数据可能需要很长时间,因此如果您想直接下载预处理后的数据,请跳至下一小节。
使用以下命令下载原始 ConceptNet、CommonsenseQA、OpenBookQA 数据
./download_raw_data.sh
您可以通过运行来预处理这些原始数据
CUDA_VISIBLE_DEVICES=0 python preprocess.py -p <num_processes>
您可以在命令CUDA_VISIBLE_DEVICES=...
的开头指定要使用的 GPU。该脚本将:
data/csqa/statement/
中)utils_biomed/
中提供了下载和预处理 MedQA-USMLE 数据以及基于疾病数据库和 DrugBank 的生物医学知识图的脚本。
为了您的方便,如果您不想自己预处理数据,可以在这里下载所有预处理的数据。将它们下载到此存储库的顶级目录中并解压缩。将medqa_usmle
和ddb
文件夹移动到data/
目录中。
生成的文件结构应如下所示:
.
├── README.md
├── data/
├── cpnet/ (prerocessed ConceptNet)
├── csqa/
├── train_rand_split.jsonl
├── dev_rand_split.jsonl
├── test_rand_split_no_answers.jsonl
├── statement/ (converted statements)
├── grounded/ (grounded entities)
├── graphs/ (extracted subgraphs)
├── ...
├── obqa/
├── medqa_usmle/
└── ddb/
要在 CommonsenseQA 上训练GreaseLM ,请运行
CUDA_VISIBLE_DEVICES=0 ./run_ GreaseLM .sh csqa --data_dir data/
您可以在命令CUDA_VISIBLE_DEVICES=...
的开头指定最多 2 个要使用的 GPU。
同样,要在 OpenbookQA 上训练GreaseLM ,请运行
CUDA_VISIBLE_DEVICES=0 ./run_ GreaseLM .sh obqa --data_dir data/
要在 MedQA-USMLE 上训练GreaseLM ,请运行
CUDA_VISIBLE_DEVICES=0 ./run_ GreaseLM __medqa_usmle.sh
您可以在此处下载 CommonsenseQA 上预训练的GreaseLM模型,该模型获得了 IH-dev acc。 79.0
和 IH 测试 acc。 74.0
。
您还可以在此处下载 OpenbookQA 上预训练的GreaseLM模型,该模型获得了测试 acc。 84.8
。
您还可以在此处下载 MedQA-USMLE 上预训练的GreaseLM模型,该模型获得了测试 acc。 38.5
。
要评估 CommonsenseQA 上预训练的GreaseLM模型检查点,请运行
CUDA_VISIBLE_DEVICES=0 ./eval_ GreaseLM .sh csqa --data_dir data/ --load_model_path /path/to/checkpoint
同样,您可以在命令CUDA_VISIBLE_DEVICES=...
的开头指定最多 2 个要使用的 GPU。
同样,要评估 OpenbookQA 上预训练的GreaseLM模型检查点,请运行
CUDA_VISIBLE_DEVICES=0 ./eval_ GreaseLM .sh obqa --data_dir data/ --load_model_path /path/to/checkpoint
要评估 MedQA-USMLE 上预训练的GreaseLM模型检查点,请运行
INHERIT_BERT=1 CUDA_VISIBLE_DEVICES=0 ./eval_ GreaseLM .sh medqa_usmle --data_dir data/ --load_model_path /path/to/checkpoint
{train,dev,test}.statement.jsonl
(请参阅data/csqa/statement/train.statement.jsonl
)data/{yourdataset}/
中创建一个目录来存储 .jsonl 文件preprocess.py
并对数据执行子图提取utils/parser_utils.py
以支持您自己的数据集该存储库基于以下工作构建:
QA-GNN: Question Answering using Language Models and Knowledge Graphs
https://github.com/michiyasunaga/qagnn
非常感谢作者和开发者!