AtmaHou / FewShotTagging

Code for ACL2020 paper: Few-shot Slot Tagging with Collapsed Dependency Transfer and Label-enhanced Task-adaptive Projection Network
153 stars 29 forks source link

Few-shot Slot Tagging

This is the code of the ACL 2020 paper: Few-shot Slot Tagging with Collapsed Dependency Transfer and Label-enhanced Task-adaptive Projection Network.

Notice: Better implementation availiable now!

Try it at: https://github.com/AtmaHou/MetaDialog

Get Started

Requirement

python >= 3.6
pytorch >= 0.4.1
pytorch_pretrained_bert >= 0.6.1
allennlp >= 0.8.2
pytorch-nlp

Step1: Prepare BERT embedding:

pytorch_pretrained_bert convert_tf_checkpoint_to_pytorch $BERT_BASE_DIR/bert_model.ckpt $BERT_BASE_DIR/bert_config.json $BERT_BASE_DIR/pytorch_model.bin

- Set BERT path in the file `./scripts/run_L-Tapnet+CDT.sh` to your setting:
```bash
bert_base_uncased=/your_dir/uncased_L-12_H-768_A-12/
bert_base_uncased_vocab=/your_dir/uncased_L-12_H-768_A-12/vocab.txt

Step2: Prepare data

Tips: The numbers in file name denote cross-evaluation id, you can run a complete experiment by only using data of id=1.

For simplicity, your only need to set the root path for data as follow:

base_data_dir=/your_dir/ACL2020data/

Step3: Train and test the main model

Example for 1-shot Snips:
source ./scripts/run_L-Tapnet+CDT.sh 0 snips
Example for 1-shot NER:
source ./scripts/run_L-Tapnet+CDT.sh 0 ner

To run 5-shots experiments, use ./scripts/run_L-Tapnet+CDT_5.sh

Model for Other Setting

We also provide scripts of four model settings as follows:

Project Architecture

Root

models

utils

Updates - New branch: fix_TapNet_svd_issue

Thanks Wangpeiyi9979 for pointing out the problem of TapNet implementation (issue), which is caused by port differences of cupy.linalg.svd and svd() in pytorch.

The corrected codes are included in new branch named fix_TapNet_svd_issue, because we found correction of TapNet will slightly degrade performance (still the best).

License for code and data

Apache License 2.0