domain-knowledge-injection
domain-knowledge-injection copied to clipboard
Injecting domain knowledge in language models for task-oriented dialogue systems
This project contains the code to reproduce the results in:
[EMNLP 2022] Injecting domain knowledge in language models for task-oriented dialogue systems
By Denis Emelin, Daniele Bonadiman, Sawsan Alqahtani, Yi Zhang, Saab Mansour
@Inproceedings{Emelin2022,
author = {Denis Emelin and Daniele Bonadiman and Sawsan Alqahtani and Yi Zhang and Saab Mansour},
title = {Injecting domain knowledge in language models for task-oriented dialogue systems},
year = {2022},
url = {https://www.amazon.science/publications/injecting-domain-knowledge-in-language-models-for-task-oriented-dialogue-systems},
booktitle = {EMNLP 2022},
}
Abstract
Pre-trained language models (PLM) have advanced the state-of-the-art across NLP applications, but lack domain-specific knowledge that does not naturally occur in pre-training data. Previous studies augmented PLMs with symbolic knowledge for different downstream NLP tasks. However, knowledge bases (KBs) utilized in these studies are usually large-scale and static, in contrast to small, domain-specific, and modifiable knowledge bases that are prominent in real-world task-oriented dialogue (TOD) systems. In this paper, we showcase the advantages of injecting domain-specific knowledge prior to fine-tuning on TOD tasks. To this end, we utilize light-weight adapters that can be easily integrated with PLMs and serve as a repository for facts learned from different KBs. To measure the efficacy of proposed knowledge injection methods, we introduce Knowledge Probing using Response Selection (KPRS) – a probe designed specifically for TOD models. Experiments1 on KPRS and the response generation task show improvements of knowledge injection with adapters over strong baselines.
Required libraries
- nltk
- numpy
- sacrebleu
- tensorboardX
- torch
- transformers
- tqdm
- word2number
Codebase
create_kprs_benchmarkcontains python scripts used to construct the KPRS benchmark files, as well as their perturbed variant for the planned knowledge-update experimentsdata_handlingcontains python scripts used to create and modify data used across all performed experiments (excluding the KPRS benchmark)experimentscontains python scripts relevant to the experiments performed as part of the projecttraining_scripts_eccontains bash scripts used to run experiments on the EC2 instancememory_adaptercontains code relevant to the memory-network adapter variant that we decided not to pursue further
create_kprs_benchmark
combine_training_dialogueshelper script used to aggregate all MultiWoZ 2.2 training files into a single file for conveniencecollect_contextscollects dialogue contexts and system responses from the MultiWoZ 2.2 train / test / dev data used to construct the KPRS samplescreate_samplesgenerates KPRS samples based on the collected dialogue contexts and system responses, by identifying sets of high-likelihood distractor items in the MultiWoZ 2.2 databasesfilter_trainfilters the KPRS training data by removing samples that contain entities mentioned in dev / test samplesperturb_databasescreates perturbed variants of MultiWoZ 2.2 databases by reassigning entity names across all database entries (used in the knowledge-update experiments)create_perturbed_samplescreates perturbed KPRS samples, where positive responses are consistent with the perturbed databases, while the negative responses are consistent with the original databases (used in the knowledge-update experiments)sample_for_manual_evalhelper script used to sample KPRS samples for manual quality controlutil: a collection of utility functions, primarily for managing MultiWoZ databases
data_handling
prepare_db_factsderives atomic and composite facts for the adapter training / knowledge injection step from the MultiWoZ 2.2 databasescreate_dialogue_state_tracking_dataderives dialogue state tracking samples from the MultiWoZ 2.2 train / dev / test datacreate_response_generation_dataderives response generation samples from the MultiWoZ 2.2 train / dev / test dataannotate_response_generation_samplesannotates response generation targets with sets of entities that are supported by the databases and appropriate given the dialogue contextmerge_samplescombines single-domain and multi-domain samples into a single file (used in the multi-domain experiments)utila collection of utility functions, primarily for managing MultiWoZ databases
experiments
adapter_modelimplements the adapter-enhanced language model as well as the various methods for combining adapter and language model representationsadapter_generation_utilsa modified variant of the HuggingFace Transformers generation adjusted to support the adapter modelpretrain_adaptertrains adapters on facts derived from database contents; also used to train the sequentially fine-tuned baselinesfinetune_on_downstream_taskfine-tunes adapter models and baselines on down-stream tasksevaluate_kprsdefines the evaluation methods for the KPRS taskevaluate_dialogue_state_trackingdefines the evaluation methods for dialogue state trackingevaluate_response_generationdefines the evaluation methods for response generationutila collection of utility functions used primarily for data preparation and serving
training_scripts
Script names are meant to be self-explanatory. X_multidomain scripts are used to run multi-domain experiments.
Running experiments
To run experiments, execute the corresponding bash script in the training_scripts_ec directory
- Specify the target domain in the
--active_domainsargument- Supported domains are
restaurant,hotel,attraction,trainfor single-domain experiments andmixedfor multi-domain experiments
- Supported domains are
- For pretraining adapters, specify the fact format in the
--fact_formatargument- Supported formats are
atomic,composite, andatomic_and_composite
- Supported formats are
- For fine-tuning, add the
--plm_onlyargument to fine-tune the LM without adapters - To specifiy the combination function, use the
--adapter_combo_methodargument - Supported methods are
mean,gate,gate_hidden,concatenate,expert,attention, andgrufor use with single adapters, andmean_multi,gate_multiandgate_hidden_multifor use with multiple active adapters - To load-in pre-trained adapter models, specify the relevant checkpoint in the
--adapter_model_checkpointargument- When using multiple adapters, provide paths to all pre-trained models (only the adapter parameters will be loaded in)
Security
See CONTRIBUTING for more information.
License
This project is licensed under the Apache-2.0 License.