Git Product home page Git Product logo

attention-based-bilstm-relation-extraction's Introduction

Attention-Based Bidirectional Long Short-Term Memory Networks for Relation Classification

Tensorflow Implementation of Deep Learning Approach for Relation Extraction Challenge(SemEval-2010 Task #8: Multi-Way Classification of Semantic Relations Between Pairs of Nominals) via Attention-based BiLSTM.

Usage

Train

  • Train data is located in "SemEval2010_task8_all_data/SemEval2010_task8_training/TRAIN_FILE.TXT".
  • "glove.6B.100d" is used as pre-trained glove model.
  • Performance (accuracy and f1-socre) outputs during training are NOT OFFICIAL SCORE of SemEval 2010 Task 8. To compute the official performance, you should proceed the follow Evaluation step with checkpoints obtained by training.
Display help message:
$ python train.py --help
Train Example:
$ python train.py --embedding_path "glove.6B.100d.txt"

Evaluation

  • You can get an OFFICIAL SCORE of SemEval 2010 Task 8 for test data by following this step. README describes how to evaluate the official score.
  • Test data is located in "SemEval2010_task8_all_data/SemEval2010_task8_testing_keys/TEST_FILE_FULL.TXT".
  • MUST GIVE --checkpoint_dir ARGUMENT, checkpoint directory from training run, like below example.
Evaluation Example:
$ python eval.py --checkpoint_dir "runs/1523902663/checkpoints/"

SemEval-2010 Task #8

  • Given: a pair of nominals
  • Goal: recognize the semantic relation between these nominals.
  • Example:
    • "There were apples, pears and oranges in the bowl."
      CONTENT-CONTAINER(pears, bowl)
    • “The cup contained tea from dried ginseng.”
      ENTITY-ORIGIN(tea, ginseng)

The Inventory of Semantic Relations

  1. Cause-Effect(CE): An event or object leads to an effect(those cancers were caused by radiation exposures)
  2. Instrument-Agency(IA): An agent uses an instrument(phone operator)
  3. Product-Producer(PP): A producer causes a product to exist (a factory manufactures suits)
  4. Content-Container(CC): An object is physically stored in a delineated area of space (a bottle full of honey was weighed) Hendrickx, Kim, Kozareva, Nakov, O S´ eaghdha, Pad ´ o,´ Pennacchiotti, Romano, Szpakowicz Task Overview Data Creation Competition Results and Discussion The Inventory of Semantic Relations (III)
  5. Entity-Origin(EO): An entity is coming or is derived from an origin, e.g., position or material (letters from foreign countries)
  6. Entity-Destination(ED): An entity is moving towards a destination (the boy went to bed)
  7. Component-Whole(CW): An object is a component of a larger whole (my apartment has a large kitchen)
  8. Member-Collection(MC): A member forms a nonfunctional part of a collection (there are many trees in the forest)
  9. Message-Topic(CT): An act of communication, written or spoken, is about a topic (the lecture was about semantics)
  10. OTHER: If none of the above nine relations appears to be suitable.

Distribution for Dataset

  • SemEval-2010 Task #8 Dataset [Download]

    Relation Train Data Test Data Total Data
    Cause-Effect 1,003 (12.54%) 328 (12.07%) 1331 (12.42%)
    Instrument-Agency 504 (6.30%) 156 (5.74%) 660 (6.16%)
    Product-Producer 717 (8.96%) 231 (8.50%) 948 (8.85%)
    Content-Container 540 (6.75%) 192 (7.07%) 732 (6.83%)
    Entity-Origin 716 (8.95%) 258 (9.50%) 974 (9.09%)
    Entity-Destination 845 (10.56%) 292 (10.75%) 1137 (10.61%)
    Component-Whole 941 (11.76%) 312 (11.48%) 1253 (11.69%)
    Member-Collection 690 (8.63%) 233 (8.58%) 923 (8.61%)
    Message-Topic 634 (7.92%) 261 (9.61%) 895 (8.35%)
    Other 1,410 (17.63%) 454 (16.71%) 1864 (17.39%)
    Total 8,000 (100.00%) 2,717 (100.00%) 10,717 (100.00%)

Reference

  • Attention-Based Bidirectional Long Short-Term Memory Networks for Relation Classification (ACL 2016), P Zhou et al. [paper]
  • roomylee's cnn-relation-extraction repository [github]

attention-based-bilstm-relation-extraction's People

Contributors

roomylee avatar seosangwoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

attention-based-bilstm-relation-extraction's Issues

contact information

I am currently studying relationship extraction. Can you leave a contact information ,so i can discuss it with you?

ValueError: not enough values to unpack (expected 7, got 5)

x_dev: (800, 4, 98)!!
x_dev: (4, 800, 98)!!
Train/Dev split: 7200/800

2018-06-02 20:32:13.323599: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
(<tf.Tensor 'bidirectional_rnn/fw/fw/transpose_1:0' shape=(?, 98, 800) dtype=float32>, <tf.Tensor 'ReverseV2:0' shape=(?, 98, 800) dtype=float32>)
pos: (?, 98)
WARNING:tensorflow:From /home/mldl/ub16_prj/Attention-Based-BiLSTM-relation-extraction/lstm_attention.py:69: softmax_cross_entropy_with_logits (from tensorflow.python.ops.nn_ops) is deprecated and will be removed in a future version.
Instructions for updating:

Future major versions of TensorFlow will allow gradients to flow
into the labels input on backprop by default.

See @{tf.nn.softmax_cross_entropy_with_logits_v2}.

Writing to /home/mldl/ub16_prj/Attention-Based-BiLSTM-relation-extraction/runs/1527942734

Traceback (most recent call last):
File "train.py", line 264, in
tf.app.run()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 126, in run
_sys.exit(main(argv))
File "train.py", line 261, in main
train(x_text, dist1, dist2, y, pos)
File "train.py", line 248, in train
train_step(x_batch, y_batch)
File "train.py", line 204, in train_step
feed_dict)
ValueError: not enough values to unpack (expected 7, got 5)
(venv) mldl@mldlUB1604:~/ub16_prj/Attention-Based-BiLSTM-relation-extraction$ /usr/bin/python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

import tensorflow as tf
tf.version
'1.8.0'
quit()
(venv) mldl@mldlUB1604:

when use python3 train.py I got a problem like this: " ValueError: Input 0 of layer dense_1 is incompatible with the layer: its rank is undefined, but the layer requires a defined rank."

Train/Dev split: 7200/800

Traceback (most recent call last):
File "/Users/wuxikun/Downloads/Attention-Based-BiLSTM-relation-extraction-master/train.py", line 162, in
tf.app.run()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 124, in run
_sys.exit(main(argv))
File "/Users/wuxikun/Downloads/Attention-Based-BiLSTM-relation-extraction-master/train.py", line 158, in main
train()
File "/Users/wuxikun/Downloads/Attention-Based-BiLSTM-relation-extraction-master/train.py", line 61, in train
l2_reg_lambda=FLAGS.l2_reg_lambda)
File "/Users/wuxikun/Downloads/Attention-Based-BiLSTM-relation-extraction-master/att_lstm.py", line 49, in init
self.logits = tf.layers.dense(self.h_drop, num_classes, kernel_initializer=initializer())
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/layers/core.py", line 253, in dense
return layer.apply(inputs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/layers/base.py", line 762, in apply
return self.call(inputs, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/layers/base.py", line 629, in call
self._assert_input_compatibility(inputs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/layers/base.py", line 1122, in _assert_input_compatibility
self.name + ' is incompatible with the layer: '
ValueError: Input 0 of layer dense_1 is incompatible with the layer: its rank is undefined, but the layer requires a defined rank.

Process finished with exit code 1

I guess it cause by the function attention(inputs) which return an output with unknown shape, how can I fix it ? or would you please tell me my mistaken ?

unofficial F1 only 0.694117

Hi SeoSangwoo.I run this code,but the Macro-Average F1 Score (excluding Other) is 0.694117.I noticed that official label range is(1,10),but here is(1,19),does it cause F1 lower than paper(0.84).

which version of tensorflow it should be?

Writing to /Users//Attention-Based-BiLSTM-relation-extraction/runs/1526525946

Traceback (most recent call last):
File "train.py", line 262, in
tf.app.run()
File "/usr/local/Cellar/python3/3.6.0_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "train.py", line 259, in main
train(x_text, dist1, dist2, y, pos)
File "train.py", line 246, in train
train_step(x_batch, y_batch)
File "train.py", line 202, in train_step
feed_dict)

How to run?

How would you go about running this so one could input a given text of choice to determine the semantic relations within?

I've looked through and can't seem to identify any way in which to do this.

Thanks in advance.

tf.keras.initializers.glorot_normal()

in train.py and attention.py have function:tf.keras.initializers.glorot_normal()
but my tensorflow do not have attribute keras
could i do some to replace this function?
thanks a lot

relation2id

thank you very much,
Can you share the complete data set?And explain the order in which the codes runs?

train.py 参数问题求解答

train.py 文件中,第200行有7个参数,201行为什么只有5个参数了,运行时报错,能解释一下为什么吗?谢谢

glorot_normal() got an unexpected keyword argument

i use tensenflow 1.8.0 but the tf.keras.initializers.glorot_normal is not good
TypeError: glorot_normal() got an unexpected keyword argument 'dtype'
TypeError: glorot_normal() got an unexpected keyword argument 'partition_info'

i want to know the cause
thanks a lot

can`t reach the F1 80.4

hi , SeoSangwoo, when i run your code , the result of f1 is 81.56, but the paper of f1 is 84 , how about your socre finally?

Questions to ask

Hello,SeoSangwoo!Thank you for sharing such valuable code. I would like to ask you a question about the code,why did you use tf.reduce_sum here to reduce dimensions?is it the beat way?
I would appreciate it if you could answer my questions.

output = tf.reduce_sum(inputs * tf.expand_dims(alphas, -1), 1)

the best official score?

Please,how many F1 (the official score) do you obtain with the provided code?0.84?how to set the Hyperparameter?

请问spos[pos1] = spos[pos2] = 2的作用是啥

spos = np.zeros(MAX_SENTENCE_LENGTH)#一个向量
spos[pos1] = spos[pos2] = 2; pos.append(spos)

这个pos在Attention里用到,却只是
if vu.shape == pos.shape: vu = tf.add(vu, pos)
之后却没有使用,这个对应论文里面的哪一点,哪一个变量呢

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.