• Stars
    star
    480
  • Rank 91,562 (Top 2 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created almost 3 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[EMNLP 2022] A Unified Framework and Analysis for Structured Knowledge Grounding with Text-to-Text Language Models

UnifiedSKG๐Ÿ“š: Unifying and Multi-Tasking Structured Knowledge Grounding with Text-to-Text Language Models

Open In Colab

Code for EMNLP 2022 (oral) paper UnifiedSKG: Unifying and Multi-Tasking Structured Knowledge Grounding with Text-to-Text Language Models. Please refer to our project page for up-to-date related resources (e.g., papers, code, tools, tutorials) for Structured Knowledge Grounding. Load our checkpoints from HuggingFace Model Hub.

Structured knowledge grounding (SKG) leverages structured knowledge to complete user requests, such as semantic parsing over databases and question answering over knowledge bases. Since the inputs and outputs of SKG tasks are heterogeneous, they were historically studied in separate by different communities, which limits systematic and compatible research on SKG. In this paper, we overcome this limitation by proposing the UnifiedSKG framework, which unifies 21 SKG tasks into the text-to-text format, aiming to promote systematic SKG research, instead of being exclusive to a single task, domain, or dataset. We show that large language models like T5, with simple modification when necessary, achieve state-of-the-art performance on nearly all 21 tasks. UnifiedSKG facilitates multi-task learning. We show that multi-task prefix-tuning benefits most tasks, largely improving the overall performance. UnifiedSKG is a challenging testbed for zero-shot and few-shot learning, which T0, GPT-3, and Codex struggle in. UnifiedSKG also enables a series of controlled experiments on structured knowledge encoding variants across SKG tasks. We find that T5โ€™s sensitivity to structured knowledge encoding variations varies across tasks.

UnifiedSKG is easily extensible. Your pull requests to add datasets, settings, metrics, models, and new features to UnifiedSKG are highly welcome!

Updates

  • 2022-03-12: Check out the seq2seq data we processed for you here by UnifiedSKG if you want to make your own attempts instead of using the huggingface loaders in our framework.
  • 2022-01-12: We released our code, colab demo, weights and project page. Check it out!

Content

Cloning this repo

In order to include third-party dependencies in this repository, make sure to clone recursively, e.g.:

git clone --recurse-submodules [email protected]:HKUNLP/UnifiedSKG.git

Dependencies

To establish the environment run this code in the shell (the third line is for CUDA11.1):

conda env create -f py3.7pytorch1.8.yaml
conda activate py3.7pytorch1.8new
pip install datasets==1.14.0
# The following line to be replaced depending on your cuda version.
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html

That will create the environment py3.7pytorch1.8new we used.

Usage

Environment setup

Activate the environment by running

conda activate py3.7pytorch1.8new

WandB setup

Setup WandB for logging (registration needed):

export WANDB_API_KEY=YOUR_WANDB_API_KEY
export WANDB_PROJECT=YOUR_PROJECT_NAME
export WANDB_ENTITY=YOUR_TEAM_NAME

Training

T5-base finetuning on WikiTQ (4 GPUs, 128 effective batch size)

python -m torch.distributed.launch --nproc_per_node 4 --master_port 1234 train.py --seed 2 --cfg Salesforce/T5_base_finetune_wikitq.cfg --run_name T5_base_finetune_wikitq --logging_strategy steps --logging_first_step true --logging_steps 4 --evaluation_strategy steps --eval_steps 500 --metric_for_best_model avr --greater_is_better true --save_strategy steps --save_steps 500 --save_total_limit 1 --load_best_model_at_end --gradient_accumulation_steps 8 --num_train_epochs 400 --adafactor true --learning_rate 5e-5 --do_train --do_eval --do_predict --predict_with_generate --output_dir output/T5_base_finetune_wikitq --overwrite_output_dir --per_device_train_batch_size 4 --per_device_eval_batch_size 16 --generation_num_beams 4 --generation_max_length 128 --input_max_length 1024 --ddp_find_unused_parameters true

If you want to resume training, remove the --overwrite_output_dir flag from the above command:

python -m torch.distributed.launch --nproc_per_node 4 --master_port 1234 train.py --seed 2 --cfg Salesforce/T5_base_finetune_wikitq.cfg --run_name T5_base_finetune_wikitq --logging_strategy steps --logging_first_step true --logging_steps 4 --evaluation_strategy steps --eval_steps 500 --metric_for_best_model avr --greater_is_better true --save_strategy steps --save_steps 500 --save_total_limit 1 --load_best_model_at_end --gradient_accumulation_steps 8 --num_train_epochs 400 --adafactor true --learning_rate 5e-5 --do_train --do_eval --do_predict --predict_with_generate --output_dir output/T5_base_finetune_wikitq --per_device_train_batch_size 4 --per_device_eval_batch_size 16 --generation_num_beams 4 --generation_max_length 128 --input_max_length 1024 --ddp_find_unused_parameters true

T5-base prefix-tuning on WikiTQ (4 GPUs, 128 effective batch size)

python -m torch.distributed.launch --nproc_per_node 4 --master_port 1234 train.py --seed 2 --cfg Salesforce/T5_base_prefix_wikitq.cfg --run_name T5_base_prefix_wikitq --logging_strategy steps --logging_first_step true --logging_steps 4 --evaluation_strategy steps --eval_steps 500 --metric_for_best_model avr --greater_is_better true --save_strategy steps --save_steps 500 --save_total_limit 1 --load_best_model_at_end --gradient_accumulation_steps 8 --num_train_epochs 400 --adafactor true --learning_rate 5e-5 --do_train --do_eval --do_predict --predict_with_generate --output_dir output/T5_base_prefix_wikitq --overwrite_output_dir --per_device_train_batch_size 4 --per_device_eval_batch_size 16 --generation_num_beams 4 --generation_max_length 128 --input_max_length 1024 --ddp_find_unused_parameters true

T5-3b finetuning on WikiTQ (8 GPUs, 128 effective batch size)

deepspeed train.py --deepspeed deepspeed/ds_config_zero2.json --seed 2 --cfg Salesforce/T5_3b_finetune_wikitq.cfg --run_name T5_3b_finetune_wikitq --logging_strategy steps --logging_first_step true --logging_steps 4 --evaluation_strategy steps --eval_steps 500 --metric_for_best_model avr --greater_is_better true --save_strategy steps --save_steps 500 --save_total_limit 1 --load_best_model_at_end --gradient_accumulation_steps 16 --num_train_epochs 50 --adafactor false --learning_rate 5e-5 --do_train --do_eval --do_predict --predict_with_generate --output_dir output/T5_3b_finetune_wikitq --overwrite_output_dir --per_device_train_batch_size 1 --per_device_eval_batch_size 1 --generation_num_beams 4 --generation_max_length 128 --input_max_length 1024 --ddp_find_unused_parameters true

Load weights

See Open In Colab

Code structure overview of UnifiedSKG

.
โ”œโ”€โ”€ configure                              # Config files for experiments, tasks, and settings
โ”‚   โ”œโ”€โ”€ META_TUNING                        # Config files for tasks and settings
โ”‚   โ””โ”€โ”€ Salesforce                         # Config files for experiments (see Misc)
โ”‚
โ”œโ”€โ”€ metrics                                # Code for evaluation
โ”‚   โ””โ”€โ”€ ...                                # Please check the README of the ./seq2seq_construction.
โ”œโ”€โ”€ models                                 # Code for models
โ”‚   โ”œโ”€โ”€ adapter                            # Code for T5 and BART with adapters (based on HuggingFace Transformers)
โ”‚   โ”œโ”€โ”€ prompt                             # Code for T5 and BART with prefix-tuning (based on HuggingFace Transformers)
โ”‚   โ””โ”€โ”€ unified
โ”‚           โ”œโ”€โ”€ base.py                    # Code for the base model that enables an arbitrary model to be pushed to HuggingFace Model Hub (namely, PushToHubFriendlyModel)
โ”‚           โ”œโ”€โ”€ finetune.py                # Code for finetuning
โ”‚           โ”œโ”€โ”€ adaptertuning.py           # Code for adapter-tuning
โ”‚           โ”œโ”€โ”€ prefixtuning.py            # Code for prefix-tuning
โ”‚           โ””โ”€โ”€ combined_prefixtuning.py   # Code for combined prefix-tuning (not used in our paper, see Misc)
โ”‚
โ”œโ”€โ”€ seq2seq_construction                   # Code for converting raw data into sequences
โ”‚    โ””โ”€โ”€  ...                              # Please check the README in this directory.
โ”‚
โ”œโ”€โ”€ tasks                                  # Code for loading raw data
โ”‚    โ””โ”€โ”€  ...                              # Please check the README in this directory.
โ”‚
โ”œโ”€โ”€ third_party                            # Packages from third parties
โ”‚    โ””โ”€โ”€  ...                              # Please check the README in this directory.
โ”‚
โ”œโ”€โ”€ utils                                  # Code for some (probably) useful stuff
โ”‚       โ”œโ”€โ”€ processor                      # Adopted from Tapex: the processor that handles table truncation and linearization
        โ”‚        โ””โ”€โ”€  ...            
โ”‚       โ”œโ”€โ”€ configure.py                   # Code for parsing config files in ./configure
โ”‚       โ”œโ”€โ”€ dataset.py                     # Code for converting input and output sequences into Datasets for training
โ”‚       โ”œโ”€โ”€ tool.py                        # Code for loading models, seq2seq constructors, and evaluators
โ”‚       โ”œโ”€โ”€ trainer.py                     # Code for EvaluationFriendlyTrainer. If you want make training-specific modifications, you may want to change something here.
โ”‚       โ””โ”€โ”€ training_arguments.py          # Code for seq2seq training arguments
โ”‚
โ”œโ”€โ”€ .gitignore                 
โ”œโ”€โ”€ .gitmodules                    
โ”œโ”€โ”€ py3.7pytorch1.8.yaml                   # Anaconda environment config file
โ”œโ”€โ”€ README.md                              # The README file you are looking at :)
โ””โ”€โ”€ train.py                               # Entry code, which controls train, eval, test, storage, and logging

Add a new task into UnifiedSKG

(READMEs in ./tasks, ./seq2seq_construction, ./metrics, ./configure can also be helpful)

  1. Add a "Loader" of raw data under ./tasks. You can search HuggingFace Datasets for possibly useful scripts. If not, you can be the contributor of both this project and the HuggingFace community.
  2. Add a "Sequence Wrapper" under ./seq2seq_construction to construct sequence inputs (user request and structured knowledge) and sequene outputs from raw data for the unification.
  3. Add an "Evaluator" for your task under ./metrics. If a third-party repository is used, remember to add it into .gitmodules.
  4. (optional) You can add a new "Model" under ./models for a new model architecture or a new learning algorithm.
  5. Add a config file for your task under ./configure/META_TUNING.
  6. Add a config file for each of your experiment under ./configure/Salesforce.

Misc

  • We name the diretory for experimental config files as Salesforce because we would like to thank Salesforce Research for providing a large number of GPUs. We would also like to thank Amazon Research Awards, ServiceNow Research, and Yale NLP for providing computing resources generously.
  • ./models/unified/combined_prefixtuning.py is not used in our paper. This file contains code for the interaction between multiple prefixes in a single training loop. We tried some variants of such interaction but did not find any of them to outperform the (extremely simple) transfer learning-based approach used in our paper. However, we open-source our failed attempts and call for potential future exploration.

That's all for it :D

Citation

If you find our work helpful, please cite as

@article{UnifiedSKG,
      title={UnifiedSKG: Unifying and Multi-Tasking Structured Knowledge Grounding with Text-to-Text Language Models}, 
      author={Tianbao Xie and Chen Henry Wu and Peng Shi and Ruiqi Zhong and Torsten Scholak and Michihiro Yasunaga and Chien-Sheng Wu and Ming Zhong and Pengcheng Yin and Sida I. Wang and Victor Zhong and Bailin Wang and Chengzu Li and Connor Boyle and Ansong Ni and Ziyu Yao and Dragomir Radev and Caiming Xiong and Lingpeng Kong and Rui Zhang and Noah A. Smith and Luke Zettlemoyer and Tao Yu},
      journal={EMNLP},
      year={2022},
}

Contributors

More Repositories

1

instructor-embedding

One Embedder, Any Task: Instruction-Finetuned Text Embeddings
Python
270
star
2

Binder

[ICLR 2023] Code for the paper "Binding Language Models in Symbolic Languages"
Python
161
star
3

DS-1000

[ICML 2023] Official data and code release for the paper "DS-1000: A Natural and Reliable Benchmark for Data Science Code Generation".
Python
119
star
4

HumanPrompt

A framework for human-readable prompt-based method with large language models. Specially designed for researchers. (In progress)
Python
103
star
5

diffusion-of-thoughts

Code for the paper "Diffusion of Thoughts: Chain-of-Thought Reasoning in Diffusion Language Models"
Python
61
star
6

icl-selective-annotation

[ICLR 2023] Code for our paper "Selective Annotation Makes Language Models Better Few-Shot Learners"
Python
57
star
7

efficient-attention

[EVA ICLR'23; LARA ICML'22] Efficient attention mechanisms via control variates, random features, and importance sampling
Python
39
star
8

icl-ceil

Code for our paper โ€œCompositional Exemplars for In-context Learningโ€.
Python
34
star
9

reparam-discrete-diffusion

Reparameterized Discrete Diffusion Models for Text Generation
Python
30
star
10

STRING

Data and code for our paper "Why Does the Effective Context Length of LLMs Fall Short?"
Python
28
star
11

batch-prompting

A simple prompting approach that enables the LLMs to run inference in batches.
Python
24
star
12

subgoal-theorem-prover

Code for the paper "Decomposing the Enigma: Subgoal-based Demonstration Learning for Formal Theorem Proving"
16
star
13

ProGen

[EMNLP-2022 Findings] Code for paper โ€œProGen: Progressive Zero-shot Dataset Generation via In-context Feedbackโ€.
Python
12
star
14

hkunlp.github.io

Website for HKU NLP group (under construction)
JavaScript
9
star
15

diagrams_toolkit

Source code for diagrams in the paper of NLPers from HKU.
Python
4
star
16

ChunkLlama

Data and code for our paper "Training-Free Long-Context Scaling of Large Language Models"
4
star
17

SymGen

Code for Generating Data for Symbolic Language with Large Language Models
2
star
18

.github

2
star
19

diffusion-vs-ar

1
star