Git Product home page Git Product logo

r-bert's Introduction

R-BERT

PWC

(Unofficial) Pytorch implementation of R-BERT: Enriching Pre-trained Language Model with Entity Information for Relation Classification

Model Architecture

Method

  1. Get three vectors from BERT.
    • [CLS] token vector
    • averaged entity_1 vector
    • averaged entity_2 vector
  2. Pass each vector to the fully-connected layers.
    • dropout -> tanh -> fc-layer
  3. Concatenate three vectors.
  4. Pass the concatenated vector to fully-connect layer.
    • dropout -> fc-layer
  • Exactly the SAME conditions as written in paper.
    • Averaging on entity_1 and entity_2 hidden state vectors, respectively. (including $, # tokens)
    • Dropout and Tanh before Fully-connected layer.
    • No [SEP] token at the end of sequence. (If you want add [SEP] token, give --add_sep_token option)

Dependencies

  • perl (For evaluating official f1 score)
  • python>=3.6
  • torch==1.6.0
  • transformers==3.3.1

How to run

$ python3 main.py --do_train --do_eval
  • Prediction will be written on proposed_answers.txt in eval directory.

Official Evaluation

$ python3 official_eval.py
# macro-averaged F1 = 88.29%
  • Evaluate based on the official evaluation perl script.
    • MACRO-averaged f1 score (except Other relation)
  • You can see the detailed result on result.txt in eval directory.

Prediction

$ python3 predict.py --input_file {INPUT_FILE_PATH} --output_file {OUTPUT_FILE_PATH} --model_dir {SAVED_CKPT_PATH}

References

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.