• Stars
    star
    952
  • Rank 46,448 (Top 1.0 %)
  • Language
    HTML
  • License
    Apache License 2.0
  • Created about 1 year ago
  • Updated 6 months ago

Reviews

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

Repository Details

Official codes for ACL 2023 paper "WebCPM: Interactive Web Search for Chinese Long-form Question Answering"

WebCPM

This is the implementation of ACL 2023 paper Interactive Web Search for Chinese Long-form Question Answering

paper

Read this in 中文.


Quick links

Overview

platform

In this work we present WebCPM, a project for interactive Web search using Chinese Pre-trained Models. We develop a web search interface which both humans and collect human web search behaviors. Then we fine-tune PLMs with up to 10B parameters to imitate human behaviors of web search and to generate answers based on the collected facts. We open source the web search interface, dataset, implementation, and model parameters.

Requirements

To run our code, please install all the dependency packages by using the following command:

pip install -r requirements.txt

NOTE: Different versions of packages (e.g., pytorch) may lead to different results from the paper. However, the trend should still hold no matter what versions of packages you use.

Preparation

Prepare the Data

First download the data from Google Drive, and put the files interactive_data and pipeline_data to ./data, or run the following commands:

The downloaded files contain the following:

interactive_data/data.json is the dataset used in the experiments of the paper (5500 instances in total). interactive_data/data_zhihu.json is additional dataset collected alongside this paper (~900 instances), with the question sourcing from Zhihu, you can use this for data augmentation.

Please use the following codes to split the above data into train, dev, and test set (setting --add_zhihu will add data_zhihu.json).

cd data/interactive_data
python split.py --add_zhihu

In addition to the interactive web search data, we also provide the dataset needed for training the pipeline-based web search: pipeline_data (110k instances in total). All the data is created by prompting text-davinci-003 (Bing search engine is also involved) and then manually filtered by human annotators. (Note This part is not included in the paper, and you don't need to split it into train / dev / test.)

Prepare the model

WebCPM is based on CPM-bee with up to 10 billion parameters, which is one of the largest Chinese pre-trained language model in the community. We use an early version of CPM-bee, which is denoted as cpm_10b_webcpm_exp.pt. The latest version of CPM-bee is hosted at New-CPM-bee. You may need to replace the cpm-live package for the new version. Note the model checkpoint has not been fine-tuned towards any downstream task. To access cpm_10b_webcpm_exp.pt, you can download the model parameters at Tsinghua Cloud, or run the following script:

cd models
bash download_model_initial_model.sh

The above codes will download the 10B (non-finetuned) model at models, for the finetuned pipeline model, please refer to download_model_pipeline_finetuned.sh, or download it manually from Tsinghua Cloud.

Train WebCPM

platform

We provide two versions of WebCPM: (1) interactive web search (the method proposed in the ACL paper) and (2) pipeline-based web search, which is easier to deploy (this method is not reported in the paper). Both versions use different scripts for training data generation and the same codes for model training.

A brief Introduction of Pipeline-based Web Search

The workflow follows four stages: (1) first, generate possible search queries based on the original question; (2) then for each search query, call Bing search and visit top-K web pages; (3) for each web page, extract the important information; (4) based on all the recorded information, generate a coherent and nuanced answer. All these things are trained in a multi-task way, please refer to run_web_browsing/run_pipeline.py. For details of the interactive web search, please refer to our original paper.

Data Preprocessing

Before you start, run the following codes:

export PYTHONPATH=/**your-base-path**/webcpm

The training data generation is as follows (we differentiate between interactive web search and pipeline-based method). The following codes will generate train_data, dev_data, and test_data in the corresponding folder, which will be loaded during training.

Training Data Generation of Interactive Web Search

First, construct the data for the synthesis model using the following codes:

cd dataset_interactive
python make_data_synthesis_model.py --data_path ../../data/interactive_data  --augment_qa_data --augment_data_path ../../data/pipeline_data

We explain some of the arguments as follows:

  • data_path: The source data path.
  • augment_qa_data: Whether to augment the training data with qa data automatically generated by text-davinci. (To replicate the results in our paper, do not add this argument)
  • augment_data_path: The data path to the augmented training data.

The training data generation of the search model is as follows:

python make_data_search_model.py --add_query --add_action --add_abstract --abstract_all_tokens

We explain some of the arguments as follows:

  • data_path: The source data path.
  • add_query: If True, will add the query generation data.
  • add_abstract: If True, will add the generate supporting fact extraction data.
  • abstract_all_tokens: If True, supporting fact extraction module will generate all the tokens, instead of only the first / last few tokens.
  • add_action: If True, will add the action prediction data.
  • add_synthesis: If True, will load local data for the synthesis model. Note You must first run python make_data_synthesis_model.py to obtain the synthesis data then add this argument here.

If you want to train all sub-tasks in a multi-task way, just add all the above arguments; otherwise only add one argument (e.g., --add_query) for single-task testing.

Training Data Generation of Pipeline-based Web Search

Please run the following codes:

cd dataset_pipeline
python make_data.py

Training

To train WebCPM, run the following codes:

cd training
export PYTHONPATH=/**your-base-path**/webcpm
export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
GPUS_PER_NODE=$(echo $CUDA_VISIBLE_DEVICES | tr ',' '\n' | wc -l | xargs)
echo "Number of visible devices: $GPUS_PER_NODE, should be the same as visible devices"

set -ex

MASTER_ADDR=localhost
MASTER_PORT=3239
NNODES=1
NODE_RANK=0

OPTS=""
OPTS+=" --model-config config/cpm-bee-10b.json"
OPTS+=" --dataset ../data/dataset_interactive/train_data"
OPTS+=" --dataseteval ../data/dataset_interactive/dev_data"
OPTS+=" --epoch 5"
OPTS+=" --batch-size 8"
OPTS+=" --train-iters 100"
OPTS+=" --save-name webcpm_finetuned"
OPTS+=" --max-length 2560"
OPTS+=" --save ../models/"
OPTS+=" --lr 0.0001"
OPTS+=" --inspect-iters 100"
OPTS+=" --warmup-iters 1"
OPTS+=" --save-epochs 1"
OPTS+=" --lr-decay-style noam"
OPTS+=" --weight-decay 0.01"
OPTS+=" --clip-grad 1.0"
OPTS+=" --loss-scale 32768"
OPTS+=" --start-step 0"
OPTS+=" --load ../models/cpm_10b_webcpm_exp.pt"

CMD="torchrun --nnodes=${NNODES} --nproc_per_node=${GPUS_PER_NODE} --rdzv_id=1 --rdzv_backend=c10d --rdzv_endpoint=${MASTER_ADDR}:${MASTER_PORT} finetune_cpm_bee.py ${OPTS}"

echo ${CMD}
$CMD

We explain some of the arguments as follows:

  • dataset and dataseteval: The path to the processed file. For interactive web search, it is dataset_interactive, while for pipeline-based method, it is dataset_pipeline.
  • batch-size: The batch size of a single GPU, the real batch size will be #GPUs x batch-size per GPU.
  • max-length: The maximum sequence length of the data (not the model), those longer training instances will be dropped.
  • save-name and save: The path to save the fine-tuned model and the name of the saved model checkpoint.
  • epoch: The number of training epochs.
  • load: The path to the pre-trained model checkpoint (cpmb in this case).

Note no matter which module you are training (or the multi-task setting), you can use the above codes. We are training on 8x80G A100, you can change the batch size according to your GPU devices, the performance is not sensitive to the hyper-parameters.

Single-task Evaluation

To evaluate different sub-tasks, you can first run the following codes to get the prediction of your fine-tuned model on the test data:

cd inference
python inference.py --test_file ../training/dataset_interactive/test.txt --output_file output/test_predictions.json --ckpt_path **your_finetuned_checkpoint.pt

We explain some of the arguments as follows:

  • test_file: The path to the test file, it should have been generated during data preprocessing.
  • output_file: The path you want to write your predictions.
  • ckpt_path: The path to your fine-tuned model.

After obtaining the predictions on the test file, you can run the following codes for single-task evaluation:

python evaluate.py --input_file output/test_predictions.txt --evaluate_action

We explain some of the arguments as follows:

  • input_file: The path you write your predictions of the test file.
  • evaluate_action: Whether you want to evaluate the action prediction task (F1).
  • evaluate_query: Whether you want to evaluate the search query generation task (Rougel-L).
  • evaluate_abstract: Whether you want to evaluate the supporting fact extraction task (Rougel-L).
  • abstract_all_tokens: Which mode do you train your model for supporting fact extraction, if you generate all the tokens, add this argument (Rougel-L).
  • evaluate_answer: Whether you want to evaluate the answer synthesis task (Rougel-L).
  • beam_size: Setting beam size to 1 would significantly accelerate inference, but hurt the performance a little bit.

Run WebCPM for New Questions

This is the implementation for the whole pipeline evaluation. You can use the following codes to generate answers for new questions. Note this requires you to first get a Bing search API key from here and run the following codes:

cd run_web_browsing
export PYTHONPATH=/**base-path**/webcpm
export BING_SEARCH_KEY="**Your Bing Search API Key**"

Interactive Web Search

python run_interactive.py --data_path predictions/test_interactive.json --ckpt_path **your-checkpoint**

Pipeline-based Web Search

python run_pipeline.py --data_path predictions/test.json --ckpt_path **your-checkpoint**

We explain some of the arguments as follows:

  • data_path: The path you write your predictions.
  • ckpt_path: The path to the checkpoint where you have trained using the pipeline-based method.

Platform Building for Data Annotation

platform

We open source our web search interface, you can use it for data annotation. Please refer to Annotation. The codes are a bit messy currently, we will soon upload a cleaner version.

Bugs or questions?

If you have any questions related to the codes or the paper, please contact Yujia ([email protected]) or open an issue.

Resources of Tool Learning

With the powerful capabilities of foundation models, we are eager to see their applications in manipulating various tools. WebCPM is one typical research attempts. For more resources, please refer to the following:

Citation

If you find our WebCPM useful, please use the following citation:

@inproceedings{qin2023webcpm,
    title = "WebCPM: Interactive Web Search for Chinese Long-form Question Answering",
    author={Yujia Qin and Zihan Cai and Dian Jin and Lan Yan and Shihao Liang and Kunlun Zhu and Yankai Lin and Xu Han and Ning Ding and Huadong Wang and Ruobing Xie and Fanchao Qi and Zhiyuan Liu and Maosong Sun and Jie Zhou},
    booktitle = "Proceedings of ACL 2023",
    year = "2023",
    publisher = "Association for Computational Linguistics",
    url = "https://arxiv.org/abs/2305.06849",
}

More Repositories

1

GNNPapers

Must-read papers on graph neural networks (GNN)
15,490
star
2

WantWords

An open-source online reverse dictionary.
JavaScript
6,933
star
3

OpenNRE

An Open-Source Package for Neural Relation Extraction (NRE)
Python
4,232
star
4

OpenPrompt

An Open-Source Framework for Prompt-Learning.
Python
4,145
star
5

PromptPapers

Must-read papers on prompt-based tuning for pre-trained language models.
3,912
star
6

OpenKE

An Open-Source Package for Knowledge Embedding (KE)
Python
3,725
star
7

PLMpapers

Must-read Papers on pre-trained language models.
3,161
star
8

NRLPapers

Must-read papers on network representation learning (NRL) / network embedding (NE)
TeX
2,520
star
9

UltraChat

Large-scale, Informative, and Diverse Multi-round Chat Data (and Models)
Python
2,118
star
10

THULAC-Python

An Efficient Lexical Analyzer for Chinese
Python
1,972
star
11

OpenNE

An Open-Source Package for Network Embedding (NE)
Python
1,672
star
12

KRLPapers

Must-read papers on knowledge representation learning (KRL) / knowledge embedding (KE)
TeX
1,528
star
13

TAADpapers

Must-read Papers on Textual Adversarial Attack and Defense
Python
1,459
star
14

ERNIE

Source code and dataset for ACL 2019 paper "ERNIE: Enhanced Language Representation with Informative Entities"
Python
1,403
star
15

KB2E

Knowledge Graph Embeddings including TransE, TransH, TransR and PTransE
C++
1,360
star
16

NREPapers

Must-read papers on neural relation extraction (NRE)
TeX
1,023
star
17

OpenCLaP

Open Chinese Language Pre-trained Model Zoo
971
star
18

OpenDelta

A plug-and-play library for parameter-efficient-tuning (Delta Tuning)
Python
938
star
19

RCPapers

Must-read papers on Machine Reading Comprehension
890
star
20

NRE

Neural Relation Extraction, including CNN, PCNN, CNN+ATT, PCNN+ATT
C++
812
star
21

ToolLearningPapers

777
star
22

THULAC

An Efficient Lexical Analyzer for Chinese
C++
772
star
23

FewRel

A Large-Scale Few-Shot Relation Extraction Dataset
Python
716
star
24

THUOCL

THUOCL(THU Open Chinese Lexicon)中文词库
697
star
25

Chinese_Rumor_Dataset

中文谣言数据
672
star
26

OpenAttack

An Open-Source Package for Textual Adversarial Attack.
Python
652
star
27

DocRED

Dataset and codes for ACL 2019 DocRED: A Large-Scale Document-Level Relation Extraction Dataset.
Python
605
star
28

OpenHowNet

Core Data of HowNet and OpenHowNet Python API
Python
592
star
29

TensorFlow-TransX

An implementation of TransE and its extended models for Knowledge Representation Learning on TensorFlow
Python
511
star
30

LegalPapers

Must-read Papers on Legal Intelligence
450
star
31

OpenMatch

An Open-Source Package for Information Retrieval.
Python
444
star
32

CAIL

Chinese AI & Law Challenge
439
star
33

BERT-KPE

Python
437
star
34

Fast-TransX

An Efficient implementation of TransE and its extended models for Knowledge Representation Learning
C++
396
star
35

TensorFlow-Summarization

Python
390
star
36

Few-NERD

Code and data of ACL 2021 paper "Few-NERD: A Few-shot Named Entity Recognition Dataset"
Python
376
star
37

SOS4NLP

Survey of Surveys for Natural Language Processing (SOS4NLP)
327
star
38

THULAC-Java

An Efficient Lexical Analyzer for Chinese
Java
325
star
39

NSC

Neural Sentiment Classification
Python
287
star
40

BMCourse

The repo for Tsinghua summer course: Interdisciplinary Seminar on Big Models
Python
269
star
41

Chinese_NRE

Source code for ACL 2019 paper "Chinese Relation Extraction with Multi-Grained Information and External Linguistic Knowledge"
Python
264
star
42

DeltaPapers

Must-read Papers of Parameter-Efficient Tuning (Delta Tuning) Methods on Pre-trained Models.
259
star
43

PL-Marker

Source code for "Packed Levitated Marker for Entity and Relation Extraction"
Python
252
star
44

SE-WRL

Improved Word Representation Learning with Sememes
C
197
star
45

THUCTC

An Efficient Chinese Text Classifier
Java
196
star
46

InfLLM

The code of our paper "InfLLM: Unveiling the Intrinsic Capacity of LLMs for Understanding Extremely Long Sequences with Training-Free Memory"
Python
196
star
47

SCPapers

Must-read Papers on Sememe Computation
193
star
48

KnowledgeablePromptTuning

kpt code
Python
192
star
49

CANE

Source code and datasets of "CANE: Context-Aware Network Embedding for Relation Modeling"
Python
190
star
50

JointNRE

Joint Neural Relation Extraction with Text and KGs
Python
185
star
51

HATT-Proto

Code and dataset of AAAI2019 paper Hybrid Attention-Based Prototypical Networks for Noisy Few-Shot Relation Classification
Python
180
star
52

LLaVA-UHD

LLaVA-UHD: an LMM Perceiving Any Aspect Ratio and High-Resolution Images
Python
169
star
53

NLP-THU

NLP Course Material & QA
164
star
54

KernelGAT

The source codes for Fine-grained Fact Verification with Kernel Graph Attention Network.
Python
161
star
55

LegalPLMs

Source code and checkpoints for legal pre-trained language models.
Python
158
star
56

EntityDuetNeuralRanking

Entity-Duet Neural Ranking Model
Python
153
star
57

PTR

Prompt Tuning with Rules
Python
151
star
58

OOP-THU

OOP Course Material & QA
149
star
59

Auto_CLIWC

Code for Chinese LIWC Lexicon Expansion via Hierarchical Classification of Word Embeddings with Sememe Attention (AAAI18)
Python
136
star
60

OpenBackdoor

An open-source toolkit for textual backdoor attack and defense (NeurIPS 2022 D&B, Spotlight)
Python
135
star
61

attribute_charge

The source code of our COLING'18 paper "Few-Shot Charge Prediction with Discriminative Legal Attributes".
Python
126
star
62

ConceptFlow

Python
119
star
63

THUCKE

THU Chinese Keyphrase Extraction Toolkit
C++
118
star
64

CAIL2018

Python
111
star
65

KR-EAR

Knowledge Representation Learning with Entities, Attributes and Relations
C++
111
star
66

Neural-Snowball

Code and dataset of AAAI2020 Paper Neural Snowball for Few-Shot Relation Learning
Python
111
star
67

ChatEval

Codes for our paper "ChatEval: Towards Better LLM-based Evaluators through Multi-Agent Debate"
Python
109
star
68

MultiRD

Code and data of the AAAI-20 paper "Multi-channel Reverse Dictionary Model"
Python
106
star
69

TransNet

Source code and datasets of IJCAI2017 paper "TransNet: Translation-Based Network Representation Learning for Social Relation Extraction".
Jupyter Notebook
103
star
70

RE-Context-or-Names

Bert-based models(BERT, MTB, CP) for relation extraction.
Python
100
star
71

AGE

Source code and dataset for KDD 2020 paper "Adaptive Graph Encoder for Attributed Graph Embedding"
Python
99
star
72

GEAR

Source code for ACL 2019 paper "GEAR: Graph-based Evidence Aggregating and Reasoning for Fact Verification"
Python
95
star
73

HNRE

Hierarchical Neural Relation Extraction
Python
95
star
74

LEVEN

Source code and dataset for ACL2022 Findings Paper "LEVEN: A Large-Scale Chinese Legal Event Detection dataset"
Python
94
star
75

TopJudge

Python
93
star
76

Prompt-Transferability

On Transferability of Prompt Tuning for Natural Language Processing
Python
85
star
77

SememePSO-Attack

Code and data of the ACL 2020 paper "Word-level Textual Adversarial Attacking as Combinatorial Optimization"
Python
85
star
78

XQA

Dataset and baseline for ACL 2019 paper "XQA: A Cross-lingual Open-domain Question Answering Dataset"
Python
84
star
79

HMEAE

Source code for EMNLP-IJCNLP 2019 paper "HMEAE: Hierarchical Modular Event Argument Extraction".
Python
84
star
80

ERICA

Source code for ACL 2021 paper "ERICA: Improving Entity and Relation Understanding for Pre-trained Language Models via Contrastive Learning"
Python
82
star
81

CLAIM

77
star
82

TKRL

Representation Learning of Knowledge Graphs with Hierarchical Types (IJCAI-2016)
C++
76
star
83

TLNN

Source code for EMNLP-IJCNLP 2019 paper "Event Detection with Trigger-Aware Lattice Neural Network".
Python
75
star
84

MMDW

Max-margin DeepWalk
Java
71
star
85

KV-PLM

Source code for "A Deep-learning System Bridging Molecule Structure and Biomedical Text with Comprehension Comparable to Human Professionals"
Python
71
star
86

KNET

Neural Entity Typing with Knowledge Attention
Python
69
star
87

SelectiveMasking

Source code for "Train No Evil: Selective Masking for Task-Guided Pre-Training"
Python
68
star
88

NeuIRPapers

Must-read Papers on Neural Information Retrieval
68
star
89

MoEfication

Python
66
star
90

Adv-ED

Source code and dataset for NAACL 2019 paper "Adversarial Training for Weakly Supervised Event Detection".
Python
66
star
91

CorefBERT

Source code for EMNLP 2020 paper "Coreferential Reasoning Learning for Language Representation"
Python
65
star
92

ConversationQueryRewriter

Code and Data for SIGIR 2020 Paper "Few-Shot Generative Conversational Query Rewriting"
Roff
63
star
93

MuGNN

Source code for ACL2019 paper "Multi-Channel Graph Neural Network for Entity Alignment".
Python
62
star
94

sememe_prediction

Codes for Lexical Sememe Prediction via Word Embeddings and Matrix Factorization (IJCAI 2017).
Python
60
star
95

DIAG-NRE

Source code for ACL 2019 paper "DIAG-NRE: A Neural Pattern Diagnosis Framework for Distantly Supervised Neural Relation Extraction".
Python
59
star
96

topical_word_embeddings

Topical Word Embeddings
Python
57
star
97

QuoteR

Official code and data of the ACL 2022 paper "QuoteR: A Benchmark of Quote Recommendation for Writing"
Python
57
star
98

paragraph2vec

Paragraph Vector Implementation
Python
56
star
99

DKRL

Representation Learning of Knowledge Graphs with Entity Descriptions (AAAI-2016)
C++
54
star
100

Ouroboros

Ouroboros: Speculative Decoding with Large Model Enhanced Drafting
Python
51
star