• Stars
    star
    443
  • Rank 98,504 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created about 5 years ago
  • Updated about 2 years ago

Reviews

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

Repository Details

BERT for Keyphrase Extraction (PyTorch)

This repository provides the code of the paper Capturing Global Informativeness in Open Domain Keyphrase Extraction.

In this paper, we conduct an empirical study of 5 keyphrase extraction models with 3 BERT variants, and then propose a multi-task model BERT-JointKPE. Experiments on two KPE benchmarks, OpenKP with Bing web pages and KP20K demonstrate JointKPE’s state-of-the-art and robust effectiveness. Our further analyses also show that JointKPE has advantages in predicting long keyphrases and non-entity keyphrases, which were challenging for previous KPE techniques.

Please cite our paper if our experimental results, analysis conclusions or the code are helpful to you ~ 😊

@article{sun2020joint,
    title={Joint Keyphrase Chunking and Salience Ranking with BERT},
    author={Si Sun, Zhenghao Liu, Chenyan Xiong, Zhiyuan Liu and Jie Bao},
    year={2020},
    eprint={2004.13639},
    archivePrefix={arXiv},
    primaryClass={cs.CL}
}

CONTACT

For any question, feel free to create an issue, and we will try our best to solve.
If the problem is more urgent, you can send an email to me at the same time (I check email almost everyday 😉).

NAME: Si Sun
EMAIL: [email protected]

🤠 What's New ?

  • 2020/9/5

    Compared with the OpenKP dataset we downloaded from MS MARCO in October of 2019 (all our experiments are based on this version of the dataset), we found that the dataset has been updated. We remind you to download the latest data from the official website. For comparison, we also provide the data version we use. (The dataset version issue was raised by Yansen Wang et al from CMU, thank them ! )

    ~DownLoad from Here or ~Email [email protected] for Data

  • 2021/12/7

    Our repo now adds Multilingual-KPE and FP16 Training Mode. Thanks, Amit Chaulwar! Amit also shared their zero-shot results on the Wikinews (French), Cacic (Spanish), Pak2018 (Polish), wicc (spanish), 110-PT-BN-KP (Portugese).

Spported Model Classes

Index Model Descriptions
1 BERT-JointKPE (Bert2Joint) A multi-task model is trained jointly on the chunking task and the ranking task, balancing the estimation of keyphrase quality and salience.
2 BERT-RankKPE (Bert2Rank) Learn the salience phrases in the documents using a ranking network.
3 BERT-ChunkKPE (Bert2Chunk) Classify high quality keyphrases using a chunking network.
4 BERT-TagKPE (Bert2Tag) We modified the sequence tagging model to generate enough candidate keyphrases for a document.
5 BERT-SpanKPE (Bert2Span) We modified the span extraction model to extract multiple keyphrases from a document.
6 DistilBERT-JointKPE (DistilBert2Joint) A multi-task model is trained jointly on the chunking task and the ranking task, balancing the estimation of keyphrase quality and salience.

BERT Variants Tested

Requirements

python 3.8
pytorch 1.9.0
pip install -r pip-requirements.txt

QUICKSTART

1/ Download

  • First download and decompress our data folder to this repo, the folder includes benchmark datasets and pre-trained BERT variants.

  • We also provide 15 checkpoints (5 KPE models * 3 BERT variants) trained on OpenKP training dataset.

2/ Preprocess

  • To preprocess the source datasets using preprocess.sh in the preprocess folder:

    source preprocess.sh
    
  • Optional arguments:

    --dataset_class         choices=['openkp', 'kp20k', 'multidata]
    --source_dataset_dir    The path to the source dataset
    --output_path           The dir to save preprocess data; default: ../data/prepro_dataset
    
  • To preprocess the multilingual dataset, download respective datasets from https://github.com/LIAAD/KeywordExtractor-Datasets and use scripts jsonify_multidata.py to preprocess the datasets. The dataset can be split into train, dev, and test sets using split_json.py.

3/ Train Models

  • To train a new model from scratch using train.sh in the scripts folder:

    source train.sh
    

    PS. Running the training script for the first time will take some time to perform preprocess such as tokenization, and by default, the processed features will be saved under ../data/cached_features, which can be directly loaded next time.

  • Optional arguments:

    --dataset_class         choices=['openkp', 'kp20k', 'multidata']
    --model_class           choices=['bert2span', 'bert2tag', 'bert2chunk', 'bert2rank', 'bert2joint']
    --pretrain_model_type   choices=['bert-base-cased', 'spanbert-base-cased', 'roberta-base', 'distilbert-base-cased']
    

    Complete optional arguments can be seen in config.py in the scripts folder.

  • Training Parameters:

    We always keep the following settings in all our experiments:

    args.warmup_proportion = 0.1
    args.max_train_steps = 20810 (openkp) , 73430 (kp20k)
    args.per_gpu_train_batch_size * max(1, args.n_gpu) * args.gradient_accumulation_steps = 64
    
  • Distributed Training

    We recommend using DistributedDataParallel to train models on multiple GPUs (It's faster than DataParallel, but it will take up more memory)

    CUDA_VISIBLE_DEVICES=0,1 OMP_NUM_THREADS=2 python -m torch.distributed.launch --nproc_per_node=2 --master_port=1234 train.py
    # if you use DataParallel rather than DistributedDataParallel, remember to set --local_rank=-1
    

4/ Inference

  • To evaluate models using trained checkpoints using test.sh in the scripts folder:

    source test.sh
    
  • Optional arguments:

    --dataset_class         choices=['openkp', 'kp20k', 'multidata']
    --model_class           choices=['bert2span', 'bert2tag', 'bert2chunk', 'bert2rank', 'bert2joint']
    --pretrain_model_type   choices=['bert-base-cased', 'spanbert-base-cased', 'roberta-base', 'distilbert-base-cased']
    --eval_checkpoint       The checkpoint file to be evaluated
    

5/ Re-produce evaluation results using our checkpoints

  • Run test.sh, and change the eval_checkpoint to the checkpoint files we provided to reproduce the following results.

    --dataset_class         openkp
    --eval_checkpoint       The filepath of our provided checkpoint
    

* RESULTS

The following results are ranked by F1@3 on OpenKP Dev dataset, the eval results can be seen in the OpenKP Leaderboard.

* BERT (Base)

Rank Method F1 @1,@3,@5 Precision @1,@3,@5 Recall @1,@3,@5
1 Bert2Joint 0.371, 0.384, 0.326 0.504, 0.313, 0.227 0.315, 0.555, 0.657
2 Bert2Rank 0.369, 0.381, 0.325 0.502, 0.311, 0.227 0.315, 0.551, 0.655
3 Bert2Tag 0.370, 0.374, 0.318 0.502, 0.305, 0.222 0.315, 0.541, 0.642
4 Bert2Chunk 0.370, 0.370, 0.311 0.504, 0.302, 0.217 0.314, 0.533, 0.627
5 Bert2Span 0.341, 0.340, 0.293 0.466, 0.277, 0.203 0.289, 0.492, 0.593

* SpanBERT (Base)

Rank Method F1 @1,@3,@5 Precision @1,@3,@5 Recall @1,@3,@5
1 Bert2Joint 0.388, 0.393, 0.333 0.527, 0.321, 0.232 0.331, 0.567, 0.671
2 Bert2Rank 0.385, 0.390, 0.332 0.521, 0.319, 0.232 0.328, 0.564, 0.666
3 Bert2Tag 0.384, 0.385, 0.327 0.520, 0.315, 0.228 0.327, 0.555, 0.657
4 Bert2Chunk 0.378, 0.385, 0.326 0.514, 0.314, 0.228 0.322, 0.555, 0.656
5 Bert2Span 0.347, 0.359, 0.304 0.477, 0.294, 0.212 0.293, 0.518, 0.613

* RoBERTa (Base)

Rank Method F1 @1,@3,@5 Precision @1,@3,@5 Recall @1,@3,@5
1 Bert2Joint 0.391, 0.398, 0.338 0.532, 0.325, 0.235 0.334, 0.577, 0.681
2 Bert2Rank 0.388, 0.395, 0.335 0.526, 0.322, 0.233 0.330, 0.570, 0.677
3 Bert2Tag 0.387, 0.389, 0.330 0.525, 0.318, 0.230 0.329, 0.562, 0.666
4 Bert2Chunk 0.380, 0.382, 0.327 0.518, 0.312, 0.228 0.324, 0.551, 0.660
5 Bert2Span 0.358, 0.355, 0.306 0.487, 0.289, 0.213 0.304, 0.513, 0.619

MODEL OVERVIEW

* BERT-JointKPE, RankKPE, ChunkKPE (See Paper)

* BERT-TagKPE (See Code)

  • Word-Level Representations : We encode an input document into a sequence of WordPiece tokens' vectors with a pretrained BERT (or its variants), and then we pick up the first sub-token vector of each word to represent the input in word-level.

  • Phrase-Level Representations : We perform a soft-select method to decode phrase from word-level vector instead of hard-select used in the standard sequence tagging task .

    The word-level representation is feed into an classification layer to obtain the tag probabilities of each word on 5 classes (O, B, I, E, U) , and then we employ different tag patterns for extracting different n-grams ( 1 ≤ n ≤ 5 ) over the whole sequence.

    Last there are a collect of n-gram candidates, each word of the n-gram just has one score.

    Soft-select Example : considering all 3-grams (B I E) on the L-length document, we can extract (L-3+1) 3-grams sequentially like sliding window. In each 3-gram, we only keep B score for the first word, I score for the middle word, and E score for the last word, etc.

    O : Non Keyphrase ; B : Begin word of the keyprase ; I : Middle word of the keyphrase ; E : End word of keyprhase ; U : Uni-word keyphrase

  • Document-Level Keyphrase : At the Last stage, the recovering from phrase-level n-grams to document-level keyphrases can be naturally formulated as a ranking task.

    Incorporating with term frequency, we employ Min Pooling to get the final score of each n-gram (we called it Buckets Effect: No matter how high a bucket, it depends on the height of the water in which the lowest piece of wood) . Based on the final scores, we extract 5 top ranked keyprhase candidates for each document.

* BERT-SpanKPE (See Code)

  • Word-Level Representations : Same as BERT-TagKPE

  • Phrase-Level Representations : Traditional span extraction model could not extract multiple important keyphrase spans for the same document. Therefore, we propose an self-attention span extraction model.

    Given the token representations {t1, t2, ..., tn}, we first calculate the probability that the token is the starting word Ps(ti), and then apply the single-head self-attention layer to calculate the ending word probability of all j>=i tokens Pe(tj).

  • Document-Level Keyphrase : We select the spans with the highest probability P = Ps(ti) * Pe(tj) as the keyphrase spans.

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

OpenPrompt

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

OpenNRE

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

PromptPapers

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

OpenKE

An Open-Source Package for Knowledge Embedding (KE)
Python
3,813
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,524
star
9

UltraChat

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

THULAC-Python

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

OpenNE

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

KRLPapers

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

TAADpapers

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

ERNIE

Source code and dataset for ACL 2019 paper "ERNIE: Enhanced Language Representation with Informative Entities"
Python
1,408
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,028
star
17

OpenDelta

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

WebCPM

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

OpenCLaP

Open Chinese Language Pre-trained Model Zoo
977
star
20

RCPapers

Must-read papers on Machine Reading Comprehension
890
star
21

ToolLearningPapers

865
star
22

NRE

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

THULAC

An Efficient Lexical Analyzer for Chinese
C++
790
star
24

FewRel

A Large-Scale Few-Shot Relation Extraction Dataset
Python
727
star
25

THUOCL

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

Chinese_Rumor_Dataset

中文谣言数据
693
star
27

OpenAttack

An Open-Source Package for Textual Adversarial Attack.
Python
682
star
28

DocRED

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

OpenHowNet

Core Data of HowNet and OpenHowNet Python API
Python
608
star
30

TensorFlow-TransX

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

LegalPapers

Must-read Papers on Legal Intelligence
465
star
32

CAIL

Chinese AI & Law Challenge
449
star
33

OpenMatch

An Open-Source Package for Information Retrieval.
Python
447
star
34

Fast-TransX

An Efficient implementation of TransE and its extended models for Knowledge Representation Learning
C++
401
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
385
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

BMCourse

The repo for Tsinghua summer course: Interdisciplinary Seminar on Big Models
Python
321
star
40

InfLLM

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

NSC

Neural Sentiment Classification
Python
286
star
42

LLaVA-UHD

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

DeltaPapers

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

Chinese_NRE

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

PL-Marker

Source code for "Packed Levitated Marker for Entity and Relation Extraction"
Python
255
star
46

LEGENT

Open Platform for Embodied Agents
Python
250
star
47

SE-WRL

Improved Word Representation Learning with Sememes
C
197
star
48

SCPapers

Must-read Papers on Sememe Computation
196
star
49

THUCTC

An Efficient Chinese Text Classifier
Java
196
star
50

KnowledgeablePromptTuning

kpt code
Python
192
star
51

CANE

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

JointNRE

Joint Neural Relation Extraction with Text and KGs
Python
187
star
53

HATT-Proto

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

LegalPLMs

Source code and checkpoints for legal pre-trained language models.
Python
169
star
55

NLP-THU

NLP Course Material & QA
168
star
56

KernelGAT

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

PTR

Prompt Tuning with Rules
Python
155
star
58

EntityDuetNeuralRanking

Entity-Duet Neural Ranking Model
Python
153
star
59

OOP-THU

OOP Course Material & QA
149
star
60

OpenBackdoor

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

Auto_CLIWC

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

attribute_charge

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

ConceptFlow

Python
119
star
64

THUCKE

THU Chinese Keyphrase Extraction Toolkit
C++
118
star
65

CAIL2018

Python
112
star
66

Neural-Snowball

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

KR-EAR

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

ChatEval

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

MultiRD

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

TransNet

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

RE-Context-or-Names

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

AGE

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

TopJudge

Python
97
star
74

Prompt-Transferability

On Transferability of Prompt Tuning for Natural Language Processing
Python
97
star
75

GEAR

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

HNRE

Hierarchical Neural Relation Extraction
Python
95
star
77

LEVEN

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

SememePSO-Attack

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

HMEAE

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

XQA

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

ERICA

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

CLAIM

78
star
83

TKRL

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

TLNN

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

NeuIRPapers

Must-read Papers on Neural Information Retrieval
72
star
86

MMDW

Max-margin DeepWalk
Java
71
star
87

KV-PLM

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

KNET

Neural Entity Typing with Knowledge Attention
Python
69
star
89

SelectiveMasking

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

MoEfication

Python
66
star
91

Adv-ED

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

CorefBERT

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

ConversationQueryRewriter

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

Ouroboros

Ouroboros: Speculative Decoding with Large Model Enhanced Drafting (EMNLP 2024 main)
Python
62
star
95

MuGNN

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

sememe_prediction

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

DIAG-NRE

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

topical_word_embeddings

Topical Word Embeddings
Python
57
star
99

QuoteR

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

paragraph2vec

Paragraph Vector Implementation
Python
56
star