This is the implementation of our paper RAPS: A Novel Few-Shot Relation Extraction Pipeline with Query-Information Guided Attention and Adaptive Prototype Fusion.
python 3.7.13PyTorch 1.9.1transformers 4.6.0numpy 1.21.6
We experiment our model on two few-shot relation extraction datasets,
Please download data from the official links and put it under ./data/.
- Download pretrained bert-base-uncased model from HuggingFace (https://huggingface.co/bert-base-uncased) and put the corresponding config files under
./bert-base-uncased/. - Download the CP pretrained model from https://github.com/thunlp/RE-Context-or-Names/tree/master/pretrain and put the checkpoint under
./CP/.
FewRel 1.0 If you want to train a 5-way 1-shot model on FewRel 1.0, run
cd scripts
bash run_train_5_1.shIn run_train_5_1.sh, you can specify BERT as backend model by export BACKEND="bert", or CP as backend model by export BACKEND="cp".
FewRel 2.0 If you want to train a 5-way 1-shot model on FewRel 2.0, run
cd scripts
bash run_train_5_1_da.shIn run_train_5_1_da.sh, you can specify BERT as backend model by export BACKEND="bert", or CP as backend model by export BACKEND="cp".
FewRel 1.0 If you want to evaluate a 5-way 1-shot model on FewRel 1.0, run
cd scripts
bash run_eval_5_1.shIn run_eval_5_1.sh, you can specify BERT as backend model by export BACKEND="bert", or CP as backend model by export BACKEND="cp".
FewRel 2.0 If you want to evaluate a 5-way 1-shot model on FewRel 2.0, run
cd scripts
bash run_eval_5_1_da.shIn run_eval_5_1_da.sh, you can specify BERT as backend model by export BACKEND="bert", or CP as backend model by export BACKEND="cp".