项目作者: wang-h

项目描述 :
A pytorch implementation of BERT-based relation classification
高级语言: Python
项目地址: git://github.com/wang-h/bert-relation-classification.git
创建时间: 2019-09-11T08:47:30Z
项目社区:https://github.com/wang-h/bert-relation-classification

开源协议:

下载


A Pytorch Implementation of BERT-based Relation Classification

This is a stable pytorch implementation of Enriching Pre-trained Language Model with Entity Information for Relation Classification https://arxiv.org/abs/1905.08284.

Requirements:

Python version >= 3.6 (recommended)

Pytorch version >= 1.1 (recommended)

pytorch-transformers: https://github.com/huggingface/pytorch-transformers
!!! pytorch-transformers = 1.1

Tutorial of the code

  1. Download the project and prepare the data
  1. > git clone https://github.com/wang-h/bert-relation-classification
  2. > cd bert-relation-classification
  1. Train the bert-based classification model
  1. > python bert.py --config config.ini
  1. ...
  2. 09/11/2019 16:36:31 - INFO - pytorch_transformers.modeling_utils - loading weights file /tmp/semeval/pytorch_model.bin
  3. 09/11/2019 16:36:33 - INFO - __main__ - Loading features from cached file ./dataset/cached_dev_bert-large-uncased_128_semeval
  4. 09/11/2019 16:36:33 - INFO - __main__ - Saving features into cached file ./dataset/cached_dev_bert-large-uncased_128_semeval
  5. 09/11/2019 16:36:34 - INFO - __main__ - ***** Running evaluation *****
  6. 09/11/2019 16:36:34 - INFO - __main__ - Num examples = 2717
  7. 09/11/2019 16:36:34 - INFO - __main__ - Batch size = 8
  8. Evaluating: 100%|████████████████████████████████████████████████████| 340/340 [00:46<00:00, 7.24it/s]
  9. 09/11/2019 16:37:21 - INFO - __main__ - ***** Eval results *****
  10. 10/07/2019 10:02:23 - INFO - __main__ - acc = 0.8579315421420685
  11. 10/07/2019 10:02:23 - INFO - __main__ - acc_and_f1 = 0.8579315421420685
  12. 10/07/2019 10:02:23 - INFO - __main__ - f1 = 0.8579315421420685
  1. Evaluate using the official script for SemEval task-8
  1. > cd eval
  2. > bash test.sh
  3. > cat res.txt
  1. (the result reported in the paper, tensorflow) MACRO-averaged result (excluding Other, uncased-large-model): 89.25
  2. (this pytorch implementation) MACRO-averaged result (excluding Other, uncased-large-model): 89.25 (same)

I also have the source code written in tensorflow. Feel free to contact me if you need it.

We also appreciate if you could cite our recent paper with the best result (90.36).

Enhancing Relation Extraction Using Syntactic Indicators and Sentential Contexts

https://arxiv.org/abs/1912.01858

or

An Extensible Framework of Leveraging Syntactic Skeleton for Semantic Relation Classification, ACM TALLIP, September 2020

https://dl.acm.org/doi/10.1145/3402885