Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

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!

  • A new and powerfull platform is now availiable for general few-shot learning problems!!

  • It fully support current experiments with better interface and flexibility~ (E.g. supoort newer huggingface/transformers)

Try it at:

Get Started


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

Step1: Prepare BERT embedding:

  • Download the pytorch bert model, or convert tensorflow param by yourself as follow:
export BERT_BASE_DIR=/users4/ythou/Projects/Resources/bert-base-uncased/uncased_L-12_H-768_A-12/

pytorch_pretrained_bert convert_tf_checkpoint_to_pytorch
  • Set BERT path in the file ./scripts/ to your setting:

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.

  • Set test, train, dev data file path in ./scripts/ to your setting.

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


Step3: Train and test the main model

  • Build a folder to collect running log
mkdir result
  • Execute cross-evaluation script with two params: -[gpu id] -[dataset name]
Example for 1-shot Snips:
source ./scripts/ 0 snips
Example for 1-shot NER:
source ./scripts/ 0 ner

To run 5-shots experiments, use ./scripts/

Model for Other Setting

We also provide scripts of four model settings as follows:

  • Tap-Net
  • Tap-Net + CDT
  • L-WPZ + CDT
  • L-Tap-Net + CDT

You can find their corresponding scripts in ./scripts/ with the same usage as above.

Project Architecture


  • the project contains three main parts:
    • models: the neural network architectures
    • scripts: running scripts for cross evaluation
    • utils: auxiliary or tool function files
    • the entry file of the whole project


  • Main Model
    • Sequence Labeler ( a framework that integrates modules below to perform sequence labeling.
  • Modules
    • Embedder Module ( modules that provide embeddings.
    • Emission Module ( modules that compute emission scores.
    • Transition Module ( modules that compute transition scores.
    • Similarity Module ( modules that compute similarities for metric learning based emission scorer.
    • Output Module (, output layer with normal mlp or crf.
    • Scale Module ( a toolkit for re-scale and normalize logits.


  • utils contains assistance modules for:
    • data processing (,,
    • constructing model architecture (,
    • controlling training process (,
    • controlling testing process (,
    • controllable parameters definition (,
    • device definition (device_helper)
    • config (

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).


Code for ACL2020 paper: Few-shot Slot Tagging with Collapsed Dependency Transfer and Label-enhanced Task-adaptive Projection Network



No releases published


No packages published