T5 models
By converting NLP tasks into a text-to-text format, we can use one single model to solve various tasks. Here we use T5 as backbone model and provide a unified training script run_seq2seq.py
for many tasks. See *.sh
under each task directory for usage.
Create Data
Currently we support natural language understanding (NLU), dialog state tracking (DST), natural language generation (NLG), response generation (RG), and generating a dialog from a user goal (Goal2Dialogue). We provide serialization and deserialization methods for dialog acts and state in the unified data format (user goals are already natural language instruction). An example of serialized dialog acts and state:
User: I am looking for a cheap restaurant.
System: Is there a particular area of town you prefer?
User: In the centre of town.
User dialog acts: [inform][restaurant]([area][centre])
State: [restaurant]([area][centre],[price range][cheap])
System dialog acts: [recommend][restaurant]([name][Zizzi Cambridge])
System: I would recommend Zizzi Cambridge.
Dialogue acts are in the form of [intent][domain]([slot][value],...);...
. State is in the form of [domain]([slot][value],...);...
. Multiple items will be concatenated by a semicolon ;
.
To create data for a specific task, run create_data.py
with corresponding arguments. For example, create data for single turn NLU on MultiWOZ 2.1:
python create_data.py --tasks nlu --datasets multiwoz21 --speaker user
Note that the script only supported datasets in the unified format.
Training
To train the model, specify the arguments like data path, learning rate, epochs, etc., and then run run_seq2seq.py
. See nlu/run_nlu.sh
for an example.
Evaluation
The standard evaluation scripts of NLU, DST, and NLG task are located under ../../$task/evaluate_unified_datasets.py
directories. See nlu/run_nlu.sh
for an example.
Trained Models
Trained models and their performance are available in Hugging Face Hub. You can try some example with hosted inference API.
Interface
To use trained models in a dialog system, import them through:
from convlab.base_models.t5.nlu import T5NLU
from convlab.base_models.t5.dst import T5DST
from convlab.base_models.t5.nlg import T5NLG
# example instantiation
# model_name_or_path could be model in hugging face hub or local path
nlu = T5NLU(speaker='user', context_window_size=0, model_name_or_path='ConvLab/t5-small-nlu-multiwoz21')
See nlu/nlu.py
, dst/dst.py
, nlg/nlg.py
for example usage.
Support a New Task
To support a new task, you can first serialize model input and output like create_data.py
, and then train the model with run_seq2seq.py
. Finally, write a evaluation script for the task or pass the metric_name_or_path
for an existing metric to run_seq2seq.py
.
Author
Qi Zhu(zhuq96 at gmail dot com)