• Stars
    star
    108
  • Rank 321,259 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created over 5 years ago
  • Updated about 3 years ago

Reviews

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

Repository Details

[AKBC 19] Improving Relation Extraction by Pre-trained Language Representations

Improving Relation Extraction by Pre-trained Language Representations

This repository contains the code of our paper:
Improving Relation Extraction by Pre-trained Language Representations.
Christoph Alt*, Marc Hübner*, Leonhard Hennig

We fine-tune the pre-trained OpenAI GPT [1] to the task of relation extraction and show that it achieves state-of-the-art results on SemEval 2010 Task 8 and TACRED relation extraction datasets.

Our code depends on huggingface's PyTorch reimplementation of the OpenAI GPT [2] - so thanks to them.

Installation

First, clone the repository to your machine and install the requirements with the following command:

pip install -r requirements.txt

We also need the weights of the pre-trained Transformer, which can be downloaded with the following command:

./download-model.sh

The english spacy model is required for sentence segmentation:

python -m spacy download en

Prepare the data

We evaluate our model on SemEval 2010 Task 8 and TACRED, which is available through LDC.

Our model expects the input dataset to be in JSONL format. To convert a dataset run the following command:

python dataset_converter.py <DATASET DIR> <CONVERTED DATASET DIR> --dataset=<DATASET NAME>

Training

E.g. for training on the TACRED dataset, run the following command:

CUDA_VISIBLE_DEVICES=0 python relation_extraction.py train \
  --write-model True \
  --masking-mode grammar_and_ner \
  --batch-size 8 \
  --max-epochs 3 \
  --lm-coef 0.5 \
  --learning-rate 5.25e-5 \
  --learning-rate-warmup 0.002 \
  --clf-pdrop 0.1 \
  --attn-pdrop 0.1 \
  --word-pdrop 0.0 \
  --dataset tacred \
  --data-dir <CONVERTED DATASET DIR> \
  --seed=0 \
  --log-dir ./logs/

Evaluation

CUDA_VISIBLE_DEVICES=0 python relation_extraction.py evaluate \
  --dataset tacred \
  --masking_mode grammar_and_ner \
  --test_file ./data/tacred/test.jsonl \
  --save_dir ./logs/ \
  --model_file <MODEL FILE (e.g. model_epoch...)> \
  --batch_size 8 \
  --log_dir ./logs/

Trained Models

The models we trained on SemEval and TACRED to produce our paper results can be found here:

Dataset Masking Mode P R F1 Download
TACRED grammar_and_ner 70.0 65.0 67.4 Link
SemEval None 87.6 86.8 87.1 Link

Download and extract model files

First, download the archive corresponding to the model you want to evaluate (links in the table above).

wget --content-disposition <DOWNLOAD URL>

Extract the model archive containing model.pt, text_encoder.pkl, and label_encoder.pkl.

tar -xvzf <MODEL ARCHIVE>

Run evaluation

  • dataset: dataset to evaluate, can be one of "semeval" or "tacred".
  • test-file: path to the JSONL test file used during evaluation
  • log-dir: directory to store the evaluation results and predictions
  • save-dir: directory containing the downloaded model files (model.pt, text_encoder.pkl, and label_encoder.pkl)
  • masking-mode: masking mode to use during evaluation, can be one of "None", "grammar_and_ner", "grammar", "ner" or "unk" (caution: must match the mode for training)

For example, to evaluate the TACRED model with "grammar_and_ner" masking, run the following command:

CUDA_VISIBLE_DEVICES=0 python relation_extraction.py evaluate \
      --dataset tacred \
      --test-file ./<CONVERTED DATASET DIR>/test.jsonl \
      --log-dir <RESULTS DIR> \
      --save-dir <MODEL DIR> \
      --masking_mode grammar_and_ner

Citations

If you use our code in your research or find our repository useful, please consider citing our work.

@InProceedings{alt_improving_2019,
  author = {Alt, Christoph and H\"{u}bner, Marc and Hennig, Leonhard},
  title = {Improving Relation Extraction by Pre-trained Language Representations},
  booktitle = {Proceedings of AKBC 2019},
  year = {2019},
  url = {https://openreview.net/forum?id=BJgrxbqp67},
}

License

lm-transformer-re is released under the MIT license. See LICENSE for additional details.

References

  1. Improving language understanding by generative pre-training. Alec Radford, Karthik Narasimhan, Tim Salimans, and Ilya Sutskever.
  2. PyTorch implementation of OpenAI's Finetuned Transformer Language Model

More Repositories

1

thermostat

Collection of NLP model explanations and accompanying analysis tools
Jsonnet
143
star
2

DISTRE

[ACL 19] Fine-tuning Pre-Trained Transformer Language Models to Distantly Supervised Relation Extraction
Python
85
star
3

tacrev

[ACL 20] TACRED Revisited: A Thorough Evaluation of the TACRED Relation Extraction Task
Jupyter Notebook
69
star
4

RelEx

RelEx - A simple framework for Relation Extraction built on AllenNLP
Jsonnet
16
star
5

REval

[ACL 20] Probing Linguistic Features of Sentence-level Representations in Neural Relation Extraction
Python
13
star
6

lrv

Layerwise Relevance Visualization in Convolutional Text Graph Classifiers
Python
12
star
7

product-corpus

This repository contains the DFKI Product Corpus, a dataset of 174 documents annotated for product and company named entities, and the relation CompanyProvidesProduct.
12
star
8

MobIE

[Konvens21] This repository contains the DFKI MobIE Corpus, a dataset of 3,232 German-language documents that have been annotated with fine-grained geo-entities, such as streets, stops and routes, as well as standard named entity types (organization, date, number, etc).
Python
11
star
9

fewie

Few-shot named entity recognition
Python
11
star
10

meffi-prompt

[EMNLP 2022] Multilingual Relation Classification via Efficient and Effective Prompting
Python
10
star
11

LLMCheckup

Code for the NAACL 2024 HCI+NLP Workshop paper "LLMCheckup: Conversational Examination of Large Language Models via Interpretability Tools and Self-explanation" (Wang et al. 2024)
Python
10
star
12

nvc

Neural Vector Conceptualization
Jupyter Notebook
9
star
13

OLM

Explanation Method for Neural Models in NLP
Jupyter Notebook
8
star
14

MultiTACRED

[ACL23] This repository contains the code for our paper "MultiTACRED: A Multilingual Version of the TAC Relation Extraction Dataset"
Python
8
star
15

SMV

Code and data for the ACL 2023 NLReasoning Workshop paper "Saliency Map Verbalization: Comparing Feature Importance Representations from Model-free and Instruction-based Methods" (Feldhus et al., 2023)
Python
8
star
16

smartdata-corpus

A dataset of almost 2600 German-language documents which has been annotated with fine-grained geo-entities, standard named entity types, and a set of 15 traffic- and industry-related relations.
8
star
17

marian-docker

Dockerfiles for providing a compiled version of the Marian neural machine translation toolkit
Dockerfile
7
star
18

defx

[SemEval 2020] Defx at SemEval-2020 Task 6: Joint Extraction of Concepts and Relations for Definition Extraction
Jupyter Notebook
7
star
19

emp-exp

Jsonnet
7
star
20

gevalm

Code and data for the paper "Evaluating German Transformer Language Models with Syntactic Agreement Tests" (Zaczynska et al., 2020)
Python
7
star
21

language-attributions

Learning Explanations from Language Data
Python
6
star
22

pgig

Jupyter Notebook
6
star
23

diamat

Machine Translation Diagnostics Tool
Python
6
star
24

TQ_AutoTest

5
star
25

InterroLang

InterroLang: Exploring NLP Models and Datasets through Dialogue-based Explanations [EMNLP 2023 Findings]
Python
5
star
26

pegasus-bridle

Ease your training experience on the DFKI GPU cluster 🦄
Shell
5
star
27

xai-shift-detection

Python
5
star
28

cross-nvc

Crosslingual Neural Vector Conceptualization
Jupyter Notebook
4
star
29

sherlock

State-of-the-art Information Extraction
Python
3
star
30

mEx-Docker-Deployment

Python
3
star
31

covid19-law-matching

Claim retrieval and matching with laws for COVID-19 related legislation (LREC 2022).
HTML
3
star
32

weighting-schemes-report

Extend the scikit-learn classification report with custom weighting schemes.
Python
3
star
33

mtb-bert-em

Replication of the BERT-EM relation extraction models from the "Matching the Blanks" paper with additional evaluation.
Python
3
star
34

mt-testsuite

Test Suite for linguistically-motivated fine grained evaluation of machine translation
TeX
3
star
35

dfki-nlp.github.io

https://dfki-nlp.github.io
TeX
2
star
36

mEx_medical_information_extraction

Python
2
star
37

discrete-ehr

ICU predictions on MIMIC-III with discrete and distributed event representations.
Jupyter Notebook
2
star
38

Ex4CDS

The repository for our annotated corpus of textual explanations for clinical decision support.
2
star
39

sim3s-corpus

Corpus MobASA: a German-language corpus of tweets annotated with their relevance for public transportation, and with sentiment towards aspects related to barrier-free travel.
Python
2
star
40

CoXQL

Code for the paper accepted to EMNLP 2024 Findings: "CoXQL: A Dataset for Parsing Explanation Requests in Conversational XAI Systems" (Wang et al., 2024)
Python
2
star
41

low-resource

[ACL-ECNLP 2020] Bootstrapping Named Entity Recognition in E-Commerce with Positive Unlabeled Learning
Jupyter Notebook
1
star
42

cross-ling-adr

[LREC 2022] Cross-lingual Approaches for the Detection of Adverse Drug Reactions
Python
1
star
43

tohyve-services

Python
1
star
44

pynegex

PyNegEx pypi modular package for negex
Python
1
star
45

CockrACE-corpus

The “CockrACE” corpus consists of 140 news articles annotated with mentions of entities and their coreference links, as well as relation mentions for the evaluation of relation extraction (RE) experiments. Three semantic relations have been annotated, each of them dealing with people's family relationships (marriages, brother/sister, parent/child).
XML
1
star
46

recon

Recon is a Java-based tool for the annotation of relations among textual elements and semantic concepts.
1
star
47

sam

Python
1
star
48

ADE_templates

This project contains templates and evaluation of models with these templates for the task of Adverse Drug Effect (ADE) detection.
Jupyter Notebook
1
star
49

weak-supervision-rlhf

Bachelor Thesis: Language Modeling with Reinforcement Learning from Human Feedback with Weak Supervision
Jupyter Notebook
1
star
50

semisupervised-mt-qe

Scripts and data to reproduce the experiments of the paper Bhatia et. al 2023, " Semi-supervised learning for Quality Estimation of Machine Translation" - MT Summit 2023
Jupyter Notebook
1
star
51

nfdi4ds-forc

Repository for constructing a dataset for the Field of Research Classification task.
Jupyter Notebook
1
star
52

for-classifier

📚 Code for my master's thesis "Investigating Knowledge Injection Approaches for Research Field Classification of Scholarly Articles".
Python
1
star
53

semantic-storytelling

Jupyter Notebook
1
star
54

keepha_annotation_guidelines

TeX
1
star
55

Taxonomy4CL

Taxonomy for Computational Linguistics topics
Python
1
star