• Stars
    star
    727
  • Rank 62,329 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 2 years ago

Reviews

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

Repository Details

A Large-Scale Few-Shot Relation Extraction Dataset

FewRel Dataset, Toolkits and Baseline Models

Our benchmark website: https://thunlp.github.io/fewrel.html

FewRel is a large-scale few-shot relation extraction dataset, which contains more than one hundred relations and tens of thousands of annotated instances cross different domains. Our dataset is presented in our EMNLP 2018 paper FewRel: A Large-Scale Few-Shot Relation Classification Dataset with State-of-the-Art Evaluation and a following-up version is presented in our EMNLP 2019 paper FewRel 2.0: Towards More Challenging Few-Shot Relation Classification.

Based on our dataset and designed few-shot settings, we have two different benchmarks:

  • FewRel 1.0: This is the first one to incorporate few-shot learning with relation extraction, where your model need to handle both the few-shot challenge and extracting entity relations from plain text. This benchmark provides a training dataset with 64 relations and a validation set with 16 relations. Once you submit your code to our benchmark website, it will be evaluated on a hidden test set with 20 relations. Each relation has 100 human-annotated instances.

  • FewRel 2.0: We found out that there are two long-neglected aspects in previous few-shot research: (1) How well models can transfer across different domains. (2) Can few-shot models detect instances belonging to none of the given few-shot classes. To dig deeper in these two aspects, we propose the 2.0 version of our dataset, with newly-added domain adaptation (DA) and none-of-the-above (NOTA) detection challenges. Find our more in our paper and evaluation websites FewRel 2.0 domain adaptation / FewRel 2.0 none-of-the-above detection

Citing

If you used our data, toolkits or baseline models, please kindly cite our paper:

@inproceedings{han-etal-2018-fewrel,
    title = "{F}ew{R}el: A Large-Scale Supervised Few-Shot Relation Classification Dataset with State-of-the-Art Evaluation",
    author = "Han, Xu and Zhu, Hao and Yu, Pengfei and Wang, Ziyun and Yao, Yuan and Liu, Zhiyuan and Sun, Maosong",
    booktitle = "Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing",
    month = oct # "-" # nov,
    year = "2018",
    address = "Brussels, Belgium",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/D18-1514",
    doi = "10.18653/v1/D18-1514",
    pages = "4803--4809"
}

@inproceedings{gao-etal-2019-fewrel,
    title = "{F}ew{R}el 2.0: Towards More Challenging Few-Shot Relation Classification",
    author = "Gao, Tianyu and Han, Xu and Zhu, Hao and Liu, Zhiyuan and Li, Peng and Sun, Maosong and Zhou, Jie",
    booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP)",
    month = nov,
    year = "2019",
    address = "Hong Kong, China",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/D19-1649",
    doi = "10.18653/v1/D19-1649",
    pages = "6251--6256"
}

If you have questions about any part of the paper, submission, leaderboard, codes, data, please e-mail [email protected].

Contributions

For FewRel 1.0, Hao Zhu first proposed this problem and proposed the way to build the dataset and the baseline system; Ziyuan Wang built and maintained the crowdsourcing website; Yuan Yao helped download the original data and conducted preprocess; Xu Han, Hao Zhu, Pengfei Yu and Ziyun Wang implemented baselines and wrote the paper together; Zhiyuan Liu provided thoughtful advice and funds through the whole project. The order of the first four authors are determined by dice rolling.

Dataset and Pretrain files

The dataset has already be contained in the github repo. However, due to the large size, glove files (pre-trained word embeddings) and BERT pretrain checkpoint are not included. Please use the script download_pretrain.sh to download these pretrain files.

We also provide pid2name.json to show the Wikidata PID, name and description for each relation.

Note: We did not release the test dataset for both FewRel 1.0 and 2.0 for fair comparison. We recommend you to evaluate your models on the validation set first, and then submit it to our evaluation websites (which you can find above).

Training a Model

To run our baseline models, use command

python train_demo.py

This will start the training and evaluating process of Prototypical Networks in a 5-way 5-shot setting. You can also use different args to start different process. Some of them are here:

  • train / val / test: Specify the training / validation / test set. For example, if you use train_wiki for train, the program will load data/train_wiki.json for training. You should always use train_wiki for training and val_wiki (FewRel 1.0 and FewRel 2.0 NOTA challenge) or val_pubmed (FewRel 2.0 DA challenge) for validation.
  • trainN: N in N-way K-shot. trainN is the specific N in training process.
  • N: N in N-way K-shot.
  • K: K in N-way K-shot.
  • Q: Sample Q query instances for each relation.
  • model: Which model to use. The default one is proto, standing for Prototypical Networks. Note that if you use the PAIR model from our paper FewRel 2.0, you should also use --encoder bert --pair.
  • encoder: Which encoder to use. You can choose cnn or bert.
  • na_rate: NA rate for FewRel 2.0 none-of-the-above (NOTA) detection. Note that here na_rate specifies the rate between Q for NOTA and Q for positive. For example, na_rate=0 means the normal setting, na_rate=1,2,5 corresponds to NA rate = 15%, 30% and 50% in 5-way settings.

There are also many args for training (like batch_size and lr) and you can find more details in our codes.

Inference

You can evaluate an existing checkpoint by

python train_demo.py --only_test --load_ckpt {CHECKPOINT_PATH} {OTHER_ARGS}

Here we provide a BERT-PAIR checkpoint (trained on FewRel 1.0 dataset, 5 way 1 shot).

Reproduction

BERT-PAIR for FewRel 1.0

python train_demo.py \
    --trainN 5 --N 5 --K 1 --Q 1 \
    --model pair --encoder bert --pair --hidden_size 768 --val_step 1000 \
    --batch_size 4  --fp16 \

Note that --fp16 requires Nvidia's apex.

5 way 1 shot 5 way 5 shot 10 way 1 shot 10 way 5 shot
Val 85.66 89.48 76.84 81.76
Test 88.32 93.22 80.63 87.02

BERT-PAIR for Domain Adaptation (FewRel 2.0)

python train_demo.py \
    --trainN 5 --N 5 --K 1 --Q 1 \
    --model pair --encoder bert --pair --hidden_size 768 --val_step 1000 \
    --batch_size 4  --fp16 --val val_pubmed --test val_pubmed \
5 way 1 shot 5 way 5 shot 10 way 1 shot 10 way 5 shot
Val 70.70 80.59 59.52 70.30
Test 67.41 78.57 54.89 66.85

BERT-PAIR for None-of-the-Above (FewRel 2.0)

python train_demo.py \
    --trainN 5 --N 5 --K 1 --Q 1 \
    --model pair --encoder bert --pair --hidden_size 768 --val_step 1000 \
    --batch_size 4  --fp16 --na_rate 5 \
5 way 1 shot (0% NOTA) 5 way 1 shot (50% NOTA) 5 way 5 shot (0% NOTA) 5 way 5 shot (50% NOTA)
Val 74.56 73.09 75.01 75.38
Test 76.73 80.31 83.32 84.64

Proto-CNN + Adversarial Training for Domain Adaptation (FewRel 2.0)

python train_demo.py \
    --val val_pubmed --adv pubmed_unsupervised --trainN 10 --N {} --K {} \ 
    --model proto --encoder cnn --val_step 1000 \
5 way 1 shot 5 way 5 shot 10 way 1 shot 10 way 5 shot
Val 48.73 64.38 34.82 50.39
Test 42.21 58.71 28.91 44.35

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

THUOCL

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

Chinese_Rumor_Dataset

中文谣言数据
693
star
26

OpenAttack

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

DocRED

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

OpenHowNet

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

TensorFlow-TransX

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

LegalPapers

Must-read Papers on Legal Intelligence
465
star
31

CAIL

Chinese AI & Law Challenge
449
star
32

OpenMatch

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

BERT-KPE

Python
443
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