GithubHelp home page GithubHelp logo

syzykf02 / casrelpytorch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from onion12138/casrelpytorch

0.0 1.0 0.0 10.56 MB

Reimplement CasRel model in PyTorch.使用PyTorch对吉林大学CasRel模型进行复现,并在百度关系抽取数据集上训练测试。

Python 100.00%

casrelpytorch's Introduction

CasRel Model Pytorch reimplement 3

The code is the PyTorch reimplement of the paper "A Novel Cascade Binary Tagging Framework for Relational Triple Extraction" ACL2020. The official code was written in keras.

I have encountered a lot of troubles with the keras version, so I decided to rewrite the code in PyTorch.

Introduction

I followed the previous work of longlongman and JuliaSun623.

So I have to express sincere thanks to them.

I made some changes in order to better apply to the Chinese Dataset. The changes I have made are listed:

  • I changed the tokenizer from HBTokenizer to BertTokenizer, so Chinese sentences are tokenized by single character. (Note that you don't need to worry about keras)
  • I substituted the original pretrained model with 'bert-base-chinese'.
  • I used fastNLP to build the datasets.
  • I changed the encoding and decoding methods in order to fit the Chinese Dataset.
  • I reconstruct the structure for readability.

Requirements

  • torch==1.8.0+cu111
  • transformers==4.3.3
  • fastNLP==0.6.0
  • tqdm==4.59.0
  • numpy==1.20.1

Dataset

I preprocessed the open-source dataset from Baidu. I did some cleaning, so the data given have 18 relation types. Some noisy data are eliminated.

The data are in form of json. Take one as an example:

{
    "text": "陶喆的一首《好好说再见》推荐给大家,希望你们能够喜欢",
    "spo_list": [
        {
            "predicate": "歌手",
            "object_type": "人物",
            "subject_type": "歌曲",
            "object": "陶喆",
            "subject": "好好说再见"
        }
    ]
}

In fact the field object_type and subject_type are not used.

If you have your own data, you can organize your data in the same format.

Usage

python run.py

I have already set the default value of the model, but you can still set your own configuration in model/config.py

Results

The best F1 score on test data is 0.78 with a precision of 0.80 and recall of 0.76.

It is to my expectation although it may not reach its utmost.

I have also trained the SpERT model, and CasRel turns out to perform better. More experiments need to be carried out since there are slight differences in both criterion and datasets.

Experiences

  • Learning rate 1e-5 seems a good choice. If you change the learning rate, the model will be dramatically affected.
  • It shows little improvement when I substitute BERT with RoBERTa.
  • It is crucial to shuffle the datasets in order to avoid overfitting.

casrelpytorch's People

Contributors

onion12138 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.