JointBERT-paddle

November 7, 2021 ยท View on GitHub

(Unofficial) Paddle implementation of JointBERT: BERT for Joint Intent Classification and Slot Filling

Model Architecture

  • Predict intent and slot at the same time from one BERT model (=Joint model)
  • total_loss = intent_loss + coef * slot_loss (Change coef with --slot_loss_coef option)
  • If you want to use CRF layer, give --use_crf option

Dependencies

  • python>=3.6
  • paddle == 2.1.3
  • paddlenlp == 2.0.0

Dataset

TrainDevTestIntent LabelsSlot Labels
ATIS4,47850089321120
Snips13,084700700772
  • The number of labels are based on the train dataset.
  • Add UNK for labels (For intent and slot labels which are only shown in dev and test dataset)
  • Add PAD for slot label

Training & Evaluation

Style one

  • Gitting clone the repo and using the following scripts:

If you want to evaluate our models directly, you can download our trained model parameters from Google Cloud, and change --model_name_or_path in evaluating scripts.

# Train
$ python main.py --task {task_name} \
                  --model_type {model_type} \
                  --model_dir {model_dir_name} \
                  --do_train --do_eval \
                  --use_crf \
                  --model_name_or_path {model_name in the training stage}

# Train For ATIS
$ python main.py --task atis \
                --model_type bert \
                --model_dir atis_model \
                --do_train --do_eval \
                --use_crf \
                --data_dir ../data \
                --model_name_or_path bert-base-uncased \
                --num_train_epochs 30.0
# Train For Snips
$ python main.py --task snips \
                --model_type bert \
                --model_dir snips_model \
                --do_train --do_eval \
                --data_dir ../data \
                --model_name_or_path bert-base-uncased \
                --num_train_epochs 30.0
              
              
# Evaluation For ATIS
$ python main.py --task atis \
                --model_type bert \
                --model_dir atis_model \
                --do_eval \
                --use_crf \
                --data_dir ../data \
                --model_name_or_path bert-base-uncased \
                --num_train_epochs 30.0

# Evaluation For Snips
$ python main.py --task snips \
                --model_type bert \
                --model_dir snips_model \
                --do_eval \
                --data_dir ../data \
                --model_name_or_path bert-base-uncased \
                --num_train_epochs 30.0
                
# Example for evaluation
$ python main.py --task snips \
                --model_type bert \
                --model_dir trained_models/snips_model_nocrf \
                --do_eval \
                --data_dir ../data \
                --model_name_or_path  bert-base-uncased \
                
                

Style two

  • Using BaiDu AI Studio and choosing JoingBERT-paddle edition to run our program in here.

Results

Intent acc (%)Slot F1 (%)Sentence acc (%)
SnipsBERT (paper)98.697.092.8
BERT (pytorch)98.796.191.1
BERT (paddle)98.696.191.4
BERT + CRF (paper)98.496.792.6
BERT + CRF (pytorch)98.696.893.1
BERT + CRF (paddle)98.596.892.7
ATISBERT (paper)97.596.188.2
BERT (pytorch)97.595.988.2
BERT (paddle)97.595.687.6
BERT + CRF (paper)97.996.088.6
BERT + CRF (pytorch)97.695.988.7
BERT + CRF (paddle)97.495.888.0