roomylee/cnn-relation-extraction

Steps to run the model

ShabanGomaa opened this issue · 6 comments

May you send the steps to run the model?

@ShabanGomaa If you want to train model(CNN),

$ git clone https://github.com/roomylee/cnn-relation-extraction.git
$ cd cnn-relation-extraction
$ python train.py

and, you can add options like,

$ python train.py --word2vec "GoogleNews-vectors-negative300.bin"

@ShabanGomaa You want to get,

input: “The burst has been caused by water hammer pressure”
output: Cause-Effect(pressure, burst)

Is that right?

At eval.py: 86 line, all_predictions = np.concatenate([all_predictions, batch_predictions])
the list all_predictions has labels of test data.
My code do not save the labels, just evaluate and print the performance of predictions.

Then, you should fix the code about all_predictions, extract the labels in all_predictions and convert the numerical labels to text labels.
Refer to the code at data_helpers.py: 55 line,

labelsMapping = {'Other': 0,
                 'Message-Topic(e1,e2)': 1, 'Message-Topic(e2,e1)': 2,
                 'Product-Producer(e1,e2)': 3, 'Product-Producer(e2,e1)': 4,
                 'Instrument-Agency(e1,e2)': 5, 'Instrument-Agency(e2,e1)': 6,
                 'Entity-Destination(e1,e2)': 7, 'Entity-Destination(e2,e1)': 8,
                 'Cause-Effect(e1,e2)': 9, 'Cause-Effect(e2,e1)': 10,
                 'Component-Whole(e1,e2)': 11, 'Component-Whole(e2,e1)': 12,
                 'Entity-Origin(e1,e2)': 13, 'Entity-Origin(e2,e1)': 14,
                 'Member-Collection(e1,e2)': 15, 'Member-Collection(e2,e1)': 16,
                 'Content-Container(e1,e2)': 17, 'Content-Container(e2,e1)': 18}

to convert to text labels from numerical labels.

For example, if the sentence "The burst has been caused by water hammer pressure" in test data is classified as label 10, then 10 is converted to "Cause-Effect(e2,e1)" and finally you can get a relation label, "Cause-Effect(burst,pressure)".

i am following following steps:
$ python3 ./train.py
$ python3 ./train.py --word2vec "GoogleNews-vectors-negative300.bin"
then
$python3 ./eval.py --checkpoint_dir "runs/1523902790/checkpoints"

following error arises:
Traceback (most recent call last):
File "/home/srinath/RE/cnn-relation-extraction-master/eval.py", line 122, in
tf.app.run()
File "/home/srinath/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "/home/srinath/RE/cnn-relation-extraction-master/eval.py", line 118, in main
eval()
File "/home/srinath/RE/cnn-relation-extraction-master/eval.py", line 80, in eval
batches = data_helpers.batch_iter(list(x_eval), FLAGS.batch_size, 1, shuffle=False)
File "/home/srinath/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/flags.py", line 50, in getattr
raise AttributeError(name)
AttributeError: batch_size
how to resolve it

@srinathdwivedi
OMG! That's my mistake. The code in eval.py is updated now.

tf.flags.DEFINE_integer("batch_size", 64, "Batch Size (Default: 64)")