|
1 | | -# ConceptLM: Graph REASoning Enhanced Language Models for Question Answering |
2 | | - |
3 | | -This repo provides the source code & data of our paper [ConceptLM: Graph REASoning Enhanced Language Models for Question Answering](https://arxiv.org/abs/2201.08860) (ICLR 2022 spotlight). If you use any of our code, processed data or pretrained models, please cite: |
4 | | -```bib |
5 | | -@inproceedings{zhang2021conceptlm, |
6 | | - title={ConceptLM: Graph REASoning Enhanced Language Models}, |
7 | | - author={Zhang, Xikun and Bosselut, Antoine and Yasunaga, Michihiro and Ren, Hongyu and Liang, Percy and Manning, Christopher D and Leskovec, Jure}, |
8 | | - booktitle={International Conference on Learning Representations}, |
9 | | - year={2021} |
10 | | -} |
11 | | -``` |
12 | | - |
13 | | -<p align="center"> |
14 | | - <img src="./figs/conceptlm.png" width="600" title="ConceptLM model architecture" alt=""> |
15 | | -</p> |
| 1 | +# ConceptLM |
16 | 2 |
|
17 | 3 | ## 1. Dependencies |
18 | 4 |
|
@@ -66,92 +52,52 @@ The script to download and preprocess the [MedQA-USMLE](https://github.com/jind1 |
66 | 52 | ### Directly download preprocessed data |
67 | 53 | For your convenience, if you don't want to preprocess the data yourself, you can download all the preprocessed data [here](https://drive.google.com/drive/folders/1T6B4nou5P3u-6jr0z6e3IkitO8fNVM6f?usp=sharing). Download them into the top-level directory of this repo and unzip them. Move the `medqa_usmle` and `ddb` folders into the `data/` directory. |
68 | 54 |
|
69 | | -### Resulting file structure |
70 | 55 |
|
71 | | -The resulting file structure should look like this: |
72 | | - |
73 | | -```plain |
74 | | -. |
75 | | -├── README.md |
76 | | -├── data/ |
77 | | - ├── cpnet/ (prerocessed ConceptNet) |
78 | | - ├── csqa/ |
79 | | - ├── train_rand_split.jsonl |
80 | | - ├── dev_rand_split.jsonl |
81 | | - ├── test_rand_split_no_answers.jsonl |
82 | | - ├── statement/ (converted statements) |
83 | | - ├── grounded/ (grounded entities) |
84 | | - ├── graphs/ (extracted subgraphs) |
85 | | - ├── ... |
86 | | - ├── obqa/ |
87 | | - ├── medqa_usmle/ |
88 | | - └── ddb/ |
89 | | -``` |
90 | 56 |
|
91 | 57 | ## 3. Training ConceptLM |
92 | 58 | To train ConceptLM on CommonsenseQA, run |
93 | 59 | ``` |
94 | 60 | CUDA_VISIBLE_DEVICES=0 ./run_conceptlm.sh csqa --data_dir data/ |
95 | 61 | ``` |
96 | | -CSQA with pool |
97 | | -``` |
98 | | -CUDA_VISIBLE_DEVICES=3 ./run_conceptlm.sh csqa --data_dir data/ --use_wandb True --emp False -mbs 4 |
99 | | -``` |
100 | | -You can specify up to 2 GPUs you want to use in the beginning of the command `CUDA_VISIBLE_DEVICES=...`. |
101 | 62 |
|
102 | | -Similarly, to train ConceptLM on OpenbookQA, run |
| 63 | +Debug on OBQA |
103 | 64 | ``` |
104 | | -CUDA_VISIBLE_DEVICES=0 ./run_conceptlm.sh obqa --data_dir data/ |
| 65 | +CUDA_VISIBLE_DEVICES=0 ./run_conceptlm.sh obqa --data_dir data/ --emp True --debug True |
105 | 66 | ``` |
106 | 67 |
|
107 | | -Embedding pool experiment test |
108 | | -``` |
109 | | -CUDA_VISIBLE_DEVICES=1 ./run_conceptlm.sh obqa --data_dir data/ --use_wandb True --emp False |
110 | | -``` |
111 | 68 |
|
112 | | -Debug |
| 69 | +## 4. Experimental expansion |
| 70 | +### BASE MODEL |
113 | 71 | ``` |
114 | | -CUDA_VISIBLE_DEVICES=0 ./run_conceptlm.sh obqa --data_dir data/ --emp True --debug True |
| 72 | +./run_conceptlm.sh obqa --data_dir data/ --emp False --use_wandb True |
| 73 | +./run_conceptlm.sh csqa --data_dir data/ --emp False --use_wandb True |
115 | 74 | ``` |
116 | 75 |
|
117 | | -To train ConceptLM on MedQA-USMLE, run |
| 76 | +### Different number of mixed coding layers |
118 | 77 | ``` |
119 | | -CUDA_VISIBLE_DEVICES=0 ./run_conceptlm__medqa_usmle.sh |
| 78 | +./run_conceptlm.sh obqa --data_dir data/ --emp False --use_wandb True -k 1 |
| 79 | +./run_conceptlm.sh obqa --data_dir data/ --emp False --use_wandb True -k 3 |
| 80 | +./run_conceptlm.sh obqa --data_dir data/ --emp False --use_wandb True -k 7 |
120 | 81 | ``` |
121 | | - |
122 | | -## 4. Pretrained model checkpoints |
123 | | -You can download a pretrained ConceptLM model on CommonsenseQA [here](https://drive.google.com/file/d/1QPwLZFA6AQ-pFfDR6TWLdBAvm3c_HOUr/view?usp=sharing), which achieves an IH-dev acc. of `79.0` and an IH-test acc. of `74.0`. |
124 | | - |
125 | | -You can also download a pretrained ConceptLM model on OpenbookQA [here](https://drive.google.com/file/d/1-QqyiQuU9xlN20vwfIaqYQ_uJMP8d7Pv/view?usp=sharing), which achieves an test acc. of `84.8`. |
126 | | - |
127 | | -You can also download a pretrained ConceptLM model on MedQA-USMLE [here](https://drive.google.com/file/d/1j0QxiBiGbv0s9PhseSly6V6uiHWU5IEt/view?usp=sharing), which achieves an test acc. of `38.5`. |
128 | | - |
129 | | -## 5. Evaluating a pretrained model checkpoint |
130 | | -To evaluate a pretrained ConceptLM model checkpoint on CommonsenseQA, run |
| 82 | +### Entity encoding node |
131 | 83 | ``` |
132 | | -CUDA_VISIBLE_DEVICES=0 ./eval_conceptlm.sh csqa --data_dir data/ --load_model_path /path/to/checkpoint |
| 84 | +./run_conceptlm.sh obqa --data_dir data/ --emp True --use_wandb True -k 1 |
| 85 | +./run_conceptlm.sh obqa --data_dir data/ --emp True --use_wandb True -k 3 |
| 86 | +./run_conceptlm.sh obqa --data_dir data/ --emp True --use_wandb True -k 5 |
| 87 | +./run_conceptlm.sh obqa --data_dir data/ --emp True --use_wandb True -k 7 |
| 88 | +./run_conceptlm.sh csqa --data_dir data/ --emp True --use_wandb True -k 5 |
133 | 89 | ``` |
134 | | -Again you can specify up to 2 GPUs you want to use in the beginning of the command `CUDA_VISIBLE_DEVICES=...`. |
135 | | - |
136 | | -Similarly, to evaluate a pretrained ConceptLM model checkpoint on OpenbookQA, run |
| 90 | +### Different number of interaction nodes |
137 | 91 | ``` |
138 | | -CUDA_VISIBLE_DEVICES=0 ./eval_conceptlm.sh obqa --data_dir data/ --load_model_path /path/to/checkpoint |
| 92 | +./run_conceptlm.sh obqa --data_dir data/ --emp False --use_wandb True --mix_number 2 |
| 93 | +./run_conceptlm.sh obqa --data_dir data/ --emp False --use_wandb True --mix_number 3 |
| 94 | +./run_conceptlm.sh obqa --data_dir data/ --emp False --use_wandb True --mix_number 5 |
| 95 | +./run_conceptlm.sh obqa --data_dir data/ --emp False --use_wandb True --mix_number 10 |
| 96 | +./run_conceptlm.sh obqa --data_dir data/ --emp False --use_wandb True --mix_number 20 |
139 | 97 | ``` |
140 | | -To evaluate a pretrained ConceptLM model checkpoint on MedQA-USMLE, run |
| 98 | +### Subgraphs of different number of nodes |
141 | 99 | ``` |
142 | | -INHERIT_BERT=1 CUDA_VISIBLE_DEVICES=0 ./eval_conceptlm.sh medqa_usmle --data_dir data/ --load_model_path /path/to/checkpoint |
| 100 | +./run_conceptlm.sh obqa --data_dir data/ --emp False --use_wandb True --gnn_dim 100 |
| 101 | +./run_conceptlm.sh obqa --data_dir data/ --emp False --use_wandb True --gnn_dim 300 |
143 | 102 | ``` |
144 | 103 |
|
145 | | -## 6. Use your own dataset |
146 | | -- Convert your dataset to `{train,dev,test}.statement.jsonl` in .jsonl format (see `data/csqa/statement/train.statement.jsonl`) |
147 | | -- Create a directory in `data/{yourdataset}/` to store the .jsonl files |
148 | | -- Modify `preprocess.py` and perform subgraph extraction for your data |
149 | | -- Modify `utils/parser_utils.py` to support your own dataset |
150 | | - |
151 | | -## 7. Acknowledgment |
152 | | -This repo is built upon the following work: |
153 | | -``` |
154 | | -QA-GNN: Question Answering using Language Models and Knowledge Graphs |
155 | | -https://github.com/michiyasunaga/qagnn |
156 | | -``` |
157 | | -Many thanks to the authors and developers! |
0 commit comments