Code Monkey home page Code Monkey logo

opennre's Introduction

OpenNRE (sub-project of OpenSKL)

OpenNRE is a sub-project of OpenSKL, providing an Open-source Neural Relation Extraction toolkit for extracting structured knowledge from plain text, with ATT as key features to consider relation-associated text information.

Overview

OpenNRE is an open-source and extensible toolkit that provides a unified framework to implement relation extraction models. We unify the input and output interfaces of different relation extraction models and provide scalable options for each model. The toolkit covers both supervised and distant supervised settings, and is compatible with both conventional neural networks and pre-trained language models.

Relation extraction is a natural language processing (NLP) task aiming at extracting relations (e.g., founder of) between entities (e.g., Bill Gates and Microsoft). For example, from the sentence Bill Gates founded Microsoft, we can extract the relation triple (Bill Gates, founder of, Microsoft).

Relation extraction is a crucial technique in automatic knowledge graph construction. By using relation extraction, we can accumulatively extract new relation facts and expand the knowledge graph, which, as a way for machines to understand the human world, has many downstream applications like question answering, recommender system and search engine. If you want to learn more about neural relation extraction, visit another project of ours (NREPapers).

It's our honor to help you better explore relation extraction with our OpenNRE toolkit! You can refer to our document for more details about this project.

Models

In this toolkit, we support CNN-based relation extraction models including standard CNN and our proposed CNN+ATT. We also implement methods based on pre-trained language models (BERT).

Evaluation

To validate the effectiveness of this toolkit, we employ the Bag-Level Relation Extraction task for evaluation.

Settings

We utilize the NYT10 dataset, which is a distantly supervised collection derived from the New York Times corpus and FreeBase. We mainly experiment on CNN-ATT model, which employs instance-level attention and shows superior performance compared with vanilla CNN.

Results

We report AUC and F1 scores of two models. The right two columns marked with (*) indicates the results sourced from Gao et al.(2021) and Lin et al.(2016). The results show that our implementation of CNN-ATT model is slighly better than the original paper, and also confirm the better performance of CNN-ATT over standard CNN model.

Model AUC F1 AUC(Paper *) F1(Paper *)
CNN - - 0.212 0.318
CNN-ATT 0.333 0.397 0.318 0.380

Usage

Installation

Install as A Python Package

We are now working on deploy OpenNRE as a Python package. Coming soon!

Using Git Repository

Clone the repository from our github page (don't forget to star us!)

git clone https://github.com/thunlp/OpenNRE.git

If it is too slow, you can try

git clone https://github.com/thunlp/OpenNRE.git --depth 1

Then install all the requirements:

pip install -r requirements.txt

Note: Please choose appropriate PyTorch version based on your machine (related to your CUDA version). For details, refer to https://pytorch.org/.

Then install the package with

python setup.py install 

If you also want to modify the code, run this:

python setup.py develop

Note that we have excluded all data and pretrain files for fast deployment. You can manually download them by running scripts in the benchmark and pretrain folders. For example, if you want to download FewRel dataset, you can run

bash benchmark/download_fewrel.sh

Data

You can go into the benchmark folder and download datasets using our scripts. We also list some of the information about the datasets in this document. We provide two distantly-supervised datasets with human-annotated test sets, NYT10m and Wiki20m. Check the datasets section for details.

Easy Start

Make sure you have installed OpenNRE as instructed above. Then import our package and load pre-trained models.

>>> import opennre
>>> model = opennre.get_model('wiki80_cnn_softmax')

Note that it may take a few minutes to download checkpoint and data for the first time. Then use infer to do sentence-level relation extraction

>>> model.infer({'text': 'He was the son of Máel Dúin mac Máele Fithrich, and grandson of the high king Áed Uaridnach (died 612).', 'h': {'pos': (18, 46)}, 't': {'pos': (78, 91)}})
('father', 0.5108704566955566)

You will get the relation result and its confidence score.

If you want to use the model on your GPU, just run

>>> model = model.cuda()

before calling the inference function.

For now, we have the following available models:

  • wiki80_cnn_softmax: trained on wiki80 dataset with a CNN encoder.
  • wiki80_bert_softmax: trained on wiki80 dataset with a BERT encoder.
  • wiki80_bertentity_softmax: trained on wiki80 dataset with a BERT encoder (using entity representation concatenation).
  • tacred_bert_softmax: trained on TACRED dataset with a BERT encoder.
  • tacred_bertentity_softmax: trained on TACRED dataset with a BERT encoder (using entity representation concatenation).

Training

You can train your own models on your own data with OpenNRE. In example folder we give example training codes for supervised RE models and bag-level RE models. You can either use our provided datasets or your own datasets. For example, you can use the following script to train a PCNN-ATT bag-level model on the NYT10 dataset with manual test set. The ATT algorithm is a typical method to combine a bag of sentences for extracting relations between entities.

python example/train_bag_cnn.py \
    --metric auc \
    --dataset nyt10m \
    --batch_size 160 \
    --lr 0.1 \
    --weight_decay 1e-5 \
    --max_epoch 100 \
    --max_length 128 \
    --seed 42 \
    --encoder pcnn \
    --aggr att

Or use the following script to train a BERT model on the Wiki80 dataset:

python example/train_supervised_bert.py \
    --pretrain_path bert-base-uncased \
    --dataset wiki80

We provide many options in the example training code and you can check them out for detailed instructions.

Citation

If you find OpenNRE is useful for your research, please consider citing the following papers:

@inproceedings{han-etal-2019-opennre,
    title = "{O}pen{NRE}: An Open and Extensible Toolkit for Neural Relation Extraction",
    author = "Han, Xu and Gao, Tianyu and Yao, Yuan and Ye, Deming and Liu, Zhiyuan and Sun, Maosong",
    booktitle = "Proceedings of EMNLP-IJCNLP: System Demonstrations",
    year = "2019",
    url = "https://www.aclweb.org/anthology/D19-3029",
    doi = "10.18653/v1/D19-3029",
    pages = "169--174"
}

This package is mainly contributed by Tianyu Gao, Xu Han, Shulian Cao, Lumin Tang, Yankai Lin, Zhiyuan Liu


About OpenSKL

OpenSKL project aims to harness the power of both structured knowledge and natural languages via representation learning. All sub-projects of OpenSKL, under the categories of Algorithm, Resource and Application, are as follows.

  • Algorithm:
    • OpenKE
      • An effective and efficient toolkit for representing structured knowledge in large-scale knowledge graphs as embeddings, with TransR and PTransE as key features to handle complex relations and relational paths.
      • This toolkit also includes three repositories:
    • ERNIE
      • An effective and efficient toolkit for augmenting pre-trained language models with knowledge graph representations.
    • OpenNE
      • An effective and efficient toolkit for representing nodes in large-scale graphs as embeddings, with TADW as key features to incorporate text attributes of nodes.
    • OpenNRE
      • An effective and efficient toolkit for implementing neural networks for extracting structured knowledge from text, with ATT as key features to consider relation-associated text information.
      • This toolkit also includes two repositories:
  • Resource:
    • The embeddings of large-scale knowledge graphs pre-trained by OpenKE, covering three typical large-scale knowledge graphs: Wikidata, Freebase, and XLORE. The embeddings are free to use under the MIT license, and please click the following link to submit download requests.
    • OpenKE-Wikidata
      • Wikidata is a free and collaborative database, collecting structured data to provide support for Wikipedia. The original Wikidata contains 20,982,733 entities, 594 relations and 68,904,773 triplets. In particular, Wikidata-5M is the core subgraph of Wikidata, containing 5,040,986 high-frequency entities from Wikidata with their corresponding 927 relations and 24,267,796 triplets.
      • TransE version: Knowledge embeddings of Wikidata pre-trained by OpenKE.
      • TransR version of Wikidata-5M: Knowledge embeddings of Wikidata-5M pre-trained by OpenKE.
    • OpenKE-Freebase
      • Freebase was a large collaborative knowledge base consisting of data composed mainly by its community members. It was an online collection of structured data harvested from many sources. Freebase contains 86,054,151 entities, 14,824 relations and 338,586,276 triplets.
      • TransE version: Knowledge embeddings of Freebase pre-trained by OpenKE.
    • OpenKE-XLORE
      • XLORE is one of the most popular Chinese knowledge graphs developed by THUKEG. XLORE contains 10,572,209 entities, 138,581 relations and 35,954,249 triplets.
      • TransE version: Knowledge embeddings of XLORE pre-trained by OpenKE.
  • Application:
    • Knowledge-Plugin
      • An effective and efficient toolkit of plug-and-play knowledge injection for pre-trained language models. Knowledge-Plugin is general for all kinds of knowledge graph embeddings mentioned above. In the toolkit, we plug the TransR version of Wikidata-5M into BERT as an example of applications. With the TransR embedding, we enhance the knowledge ability of BERT without fine-tuning the original model, e.g., up to 8% improvement on question answering.

opennre's People

Contributors

albertyang33 avatar antct avatar demerzel-iv avatar dependabot[bot] avatar gaotianyu1350 avatar helloxcq avatar icmpnorequest avatar jacen789 avatar qiaoziqing avatar thucsthanxu13 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  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

opennre's Issues

num_classes = 53 or 58?

hello!
running test.py on my own computer, i got the error below:

tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [58] rhs shape= [53]

Seems like you just set the num_classes = 53, but there are 58 kinds of relationship. ???
And when i used the model trained by myself and changed 53 into 58, i can run test.py successfully.
would u please tell me why "num_classes = 53"?

TypeError: Expected int32, got list containing Tensors of type '_Message' instead.

I meet the error below.

Traceback (most recent call last):
  File "train_GRU.py", line 164, in <module>
    tf.app.run() 
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 44, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "train_GRU.py", line 49, in main
    m = network.GRU(is_training=True, word_embeddings = wordembedding, settings = settings)
  File "/home/xxx/TensorFlow-NRE/network.py", line 71, in __init__
    inputs_forward = tf.concat(2,[tf.nn.embedding_lookup(word_embedding,self.input_word),tf.nn.embedding_lookup(pos1_embedding,self.input_pos1),tf.nn.embedding_lookup(pos2_embedding,self.input_pos2)])
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 1047, in concat
    dtype=dtypes.int32).get_shape(
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 651, in convert_to_tensor
    as_ref=False)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 716, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/constant_op.py", line 176, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/constant_op.py", line 165, in constant
    tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_util.py", line 367, in make_tensor_proto
    _AssertCompatible(values, dtype)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_util.py", line 302, in _AssertCompatible
    (dtype.name, repr(mismatch), type(mismatch).__name__))
TypeError: Expected int32, got list containing Tensors of type '_Message' instead.

I am using tenforflow r1.0. I have also changed some unmatched parts between r1.0 and r0.1 in network.py. But not sure if this error is still a version problem or anything else.

Thanks!

About the data

It's different count of relation in train.txt and test.txt.
How did you preprocess data from Riedel's data
The relation distribution in train.txt is bellow,the total number of relation in train.txt is 56.

[('NA', 413424),
 ('/location/location/contains', 75969),
 ('/people/person/nationality', 11446),
 ('/location/country/capital', 11216),
 ('/people/person/place_lived', 9829),
 ('/location/neighborhood/neighborhood_of', 9472),
 ('/location/administrative_division/country', 8860),
 ('/location/country/administrative_divisions', 8860),
 ('/business/person/company', 7987),
 ('/people/person/place_of_birth', 4265),
 ('/people/deceased_person/place_of_death', 2541),
 ('/business/company/founders', 1061),
 ('/location/us_state/capital', 798),
 ('/business/company/place_founded', 677),
 ('/people/person/children', 677),
 ('/people/ethnicity/geographic_distribution', 630),
 ('/business/company/major_shareholders', 439),
 ('/sports/sports_team/location', 311),
 ('/business/company_shareholder/major_shareholder_of', 309),
 ('/sports/sports_team_location/teams', 247),
 ('/people/person/religion', 206),
 ('/people/person/ethnicity', 190),
 ('/people/ethnicity/people', 169),
 ('/location/us_county/county_seat', 110),
 ('/broadcast/producer/location', 71),
 ('/business/company/advisors', 51),
 ('/location/province/capital', 39),
 ('/people/deceased_person/place_of_burial', 24),
 ('/people/place_of_interment/interred_here', 24),
 ('/location/it_region/capital', 22),
 ('/business/business_location/parent_company', 19),
 ('/business/company/locations', 19),
 ('/film/film/featured_film_locations', 18),
 ('/film/film_location/featured_in_films', 18),
 ('/people/person/profession', 10),
 ('/broadcast/content/location', 8),
 ('/people/ethnicity/included_in_group', 7),
 ('/location/de_state/capital', 7),
 ('/people/ethnicity/includes_groups', 7),
 ('/people/family/country', 6),
 ('/business/company/industry', 6),
 ('/location/in_state/administrative_capital', 4),
 ('/people/family/members', 4),
 ('/location/br_state/capital', 4),
 ('/location/in_state/legislative_capital', 4),
 ('/time/event/locations', 4),
 ('/film/film_festival/location', 4),
 ('/location/in_state/judicial_capital', 3),
 ('/location/cn_province/capital', 2),
 ('/people/profession/people_with_this_profession', 2),
 ('/business/company_advisor/companies_advised', 2),
 ('/location/jp_prefecture/capital', 2),
 ('/location/fr_region/capital', 1),
 ('/location/mx_state/capital', 1),
 ('/business/shopping_center_owner/shopping_centers_owned', 1),
 ('/business/shopping_center/owner', 1)]

The relation distribution in text.txt is bellow,the total number of relation in test.txt is 32.

[('NA', 166004),
 ('/location/location/contains', 2793),
 ('/people/person/nationality', 723),
 ('/location/country/capital', 553),
 ('/people/person/place_lived', 450),
 ('/location/administrative_division/country', 424),
 ('/location/country/administrative_divisions', 424),
 ('/business/person/company', 302),
 ('/people/person/place_of_birth', 162),
 ('/people/ethnicity/geographic_distribution', 136),
 ('/business/company/founders', 95),
 ('/people/deceased_person/place_of_death', 68),
 ('/location/neighborhood/neighborhood_of', 68),
 ('/business/company/major_shareholders', 46),
 ('/location/us_state/capital', 39),
 ('/people/person/children', 30),
 ('/location/us_county/county_seat', 23),
 ('/business/company/place_founded', 20),
 ('/people/person/ethnicity', 13),
 ('/location/province/capital', 11),
 ('/sports/sports_team/location', 10),
 ('/people/deceased_person/place_of_burial', 9),
 ('/people/place_of_interment/interred_here', 9),
 ('/business/company_advisor/companies_advised', 8),
 ('/business/company/advisors', 8),
 ('/people/person/religion', 6),
 ('/time/event/locations', 4),
 ('/location/country/languages_spoken', 3),
 ('/location/br_state/capital', 2),
 ('/film/film/featured_film_locations', 2),
 ('/film/film_location/featured_in_films', 2),
 ('/base/locations/countries/states_provinces_within', 1)]

有以下问题想咨询一下

1.训练语料和测试语料 类别数目不平衡问题
对论文中用的语料进行了统计,统计数目如下:
训练 :共53个类别,语料大小 55w+,其中,NA类别数目占据 40w+
预测: 共32个类别,语料大小 17w+,其中 NA类别语料数目占据 15w+
发现训练语料中 NA类别的语料 太多,这样直接导致绝大多数被预测为NA类型,严重影响各类别准确率和召回率
对这种情况的语料,你们在训练前有没有做一些预处理,还是直接使用的是这种类别数目不平衡的语料进行训练的?

2.准确率评估方式
论文中,会对分值较高的前100,200,300类别进行准确率评估,这种评估是否是剔除NA这种类别后得到的?

3.准确率不一致问题
按照论文提供的origin_data中的语料进行训练和测试的,由于类别数目的不平衡,导致预测只预测出了两个类别,
剔除掉NA类别,P@100 p@200 p@300的准确率 分别为0.09、0.07和0.067,导致这个结果的原因有哪些呢?

Python 3 compatibility

Code written in the files is in python 2. Do we have to manually change everything to make it compatible with python 3?

Confused about the results

I ran the the commands in sequence:
python train.py --model_name MODEL_NAME
python test.py --model_name MODEL_NAME
python draw_plot.py --model_name MODEL_NAME

I got:
cnn_max-auc=0.3929
cnn_att-auc=0.3801
pcnn_att-auc=0.4008
birnn_att-auc=0.3771

The results shows that ATT is worse than MAX, which is wired.
BIRNN is worse than PCNN and about the same as CNN, which contradicts previous claim and graph in the old version of this repository.

The results of PCNN seems to be significantly better than (Zeng et al.,2015) reported in the paper.
Is this because this program is directly picking the best epoch on the test set?
The paper does not specify how they select the final model for prediction. (Lin et al. 2016) used epoch-25.

I'm not familiar with the dataset. I hope someone with knowledge can explain this.
Thanks.

What is the true usage of settings.big_num?

Shall i understand the settings.big_num in the training part as the batchsize that controls how many samples are feed until an optimization is executed?
and why in test_GRU.py, it is set by test_settings.big_num = 262 * 9.
I'm a little confused about why it is 262*9

Thank you

结果与发布的不匹配

你好,我所跑出的结果跟发布的准确率不太匹配,有以下几个问题
(1)在评价准确时是不是不包含对 NA的评价,我看代码是略过NA的。
(2)训练语料中53个类别,共55w条句子,但NA类型的句子站30w+ ,这种不平衡的语料会不会影响结果结果,(测试的语料**有15w+ NA类型占14w+ ,且只有30左右的类型)因为在测试的时候发现,如果包含NA,准确率可以达到98%,如果不算NA的准确率,前100,200及300的准确率在1%左右。语料是否存在不平衡问题?

network.py has a little bug

Thank you for your open source codes!
When using your codes, I found a little bug in network.py.

Line72: inputs_backward = tf.concat(2,[tf.nn.embedding_lookup(word_embedding,tf.reverse(self.input_word,[False,True])), tf.nn.embedding_lookup(pos1_embedding,tf.reverse(self.input_pos1,[False,True])), tf.nn.embedding_lookup(pos1_embedding,tf.reverse(self.input_pos2,[False,True]))])

last embedding_lookup, I think it might be pos2_embedding,tf.reverse(self.input_pos2,[False,True])

test have a question

017-08-12 10:20:51.722116: W tensorflow/core/framework/op_kernel.cc:1150] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/pzhang/code/TensorFlow-NRE/model/ATT_GRU_model-ATT_GRU_model-10900
2017-08-12 10:20:51.724366: W tensorflow/core/framework/op_kernel.cc:1150] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/pzhang/code/TensorFlow-NRE/model/ATT_GRU_model-ATT_GRU_model-10900
2017-08-12 10:20:51.725448: W tensorflow/core/framework/op_kernel.cc:1150] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/pzhang/code/TensorFlow-NRE/model/ATT_GRU_model-ATT_GRU_model-10900
2017-08-12 10:20:51.727151: W tensorflow/core/framework/op_kernel.cc:1150] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/pzhang/code/TensorFlow-NRE/model/ATT_GRU_model-ATT_GRU_model-10900
2017-08-12 10:20:51.728789: W tensorflow/core/framework/op_kernel.cc:1150] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/pzhang/code/TensorFlow-NRE/model/ATT_GRU_model-ATT_GRU_model-10900
2017-08-12 10:20:51.729654: W tensorflow/core/framework/op_kernel.cc:1150] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/pzhang/code/TensorFlow-NRE/model/ATT_GRU_model-ATT_GRU_model-10900
2017-08-12 10:20:51.731067: W tensorflow/core/framework/op_kernel.cc:1150] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/pzhang/code/TensorFlow-NRE/model/ATT_GRU_model-ATT_GRU_model-10900
2017-08-12 10:20:51.732226: W tensorflow/core/framework/op_kernel.cc:1150] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/pzhang/code/TensorFlow-NRE/model/ATT_GRU_model-ATT_GRU_model-10900
2017-08-12 10:20:51.733384: W tensorflow/core/framework/op_kernel.cc:1150] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/pzhang/code/TensorFlow-NRE/model/ATT_GRU_model-ATT_GRU_model-10900
2017-08-12 10:20:51.734453: W tensorflow/core/framework/op_kernel.cc:1150] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/pzhang/code/TensorFlow-NRE/model/ATT_GRU_model-ATT_GRU_model-10900
2017-08-12 10:20:51.735550: W tensorflow/core/framework/op_kernel.cc:1150] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/pzhang/code/TensorFlow-NRE/model/ATT_GRU_model-ATT_GRU_model-10900
2017-08-12 10:20:51.736596: W tensorflow/core/framework/op_kernel.cc:1150] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/pzhang/code/TensorFlow-NRE/model/ATT_GRU_model-ATT_GRU_model-10900
2017-08-12 10:20:51.737509: W tensorflow/core/framework/op_kernel.cc:1150] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/pzhang/code/TensorFlow-NRE/model/ATT_GRU_model-ATT_GRU_model-10900
2017-08-12 10:20:51.738414: W tensorflow/core/framework/op_kernel.cc:1150] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/pzhang/code/TensorFlow-NRE/model/ATT_GRU_model-ATT_GRU_model-10900
2017-08-12 10:20:51.739293: W tensorflow/core/framework/op_kernel.cc:1150] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/pzhang/code/TensorFlow-NRE/model/ATT_GRU_model-ATT_GRU_model-10900
2017-08-12 10:20:51.740008: W tensorflow/core/framework/op_kernel.cc:1150] Not found: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /home/pzhang/code/TensorFlow-NRE/model/ATT_GRU_model-ATT_GRU_model-10900

AttributeError: 'module' object has no attribute 'rnn_cell'

Hi! Thanks for sharing the code
When I try to run the code python train_GPU.py
I met

Traceback (most recent call last):
File "train_GRU.py", line 243, in
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 44, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "train_GRU.py", line 159, in main
m = GRU(is_training=True, word_embeddings = wordembedding, settings = settings)
File "train_GRU.py", line 49, in init
gru_cell_forward = tf.nn.rnn_cell.GRUCell(gru_size)
AttributeError: 'module' object has no attribute 'rnn_cell'

my tensorflow verison is

>>> print(tf.__version__)
1.0.0-rc1

I was wondering which tensor flow version is used in your code?

Thanks!

FileNotFoundError

I can not find these files: './data/small_word.npy', './data/small_y.npy', etc.
Please could you upload these files?

About word level attention

Why is there the word-level attention in your code?
Did the author also use the word-level attention in the ACL paper?

Feedback -- little bugs / user-friendliness...

Hi, just trying it out:

Some feedback to make it more smooth for users:

  1. please automatically create the 'data' directory .. else users get an exception when calling "gen_data.py"
  2. in the README.md is says on should move the NYT dataset to 'origin-data', but it has to be 'origin_data'
  3. please list requirements for the tool (a requirements.txt)
  4. Little bug:
    python train.py --model_name pcnn_att
    Traceback (most recent call last):
    File "train.py", line 40, in
    from framework import Framework
    File "/home/wohlg/itmo/OpenNRE/framework.py", line 58
    self.encoder = Encoder(is_training, FLAGS.drop_prob)
    ^
    TabError: inconsistent use of tabs and spaces in indentation

---> please replace the tab with spaces

Question

[Excuse me,my python version is 3.5 and tensorflow version is 1.2.1,But I had some trouble when debug it.Here is the error I encountered:

C:\Users\Administrator\AppData\Local\Programs\Python\Python35\python.exe D:/PerfectProject/NRE/train_GRU.py
reading wordembedding
reading training data
2017-07-26 19:16:09.465988: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations.
2017-07-26 19:16:09.465988: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE2 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-26 19:16:09.466988: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-26 19:16:09.466988: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-26 19:16:09.466988: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-26 19:16:09.466988: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-07-26 19:16:09.466988: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-26 19:16:09.466988: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.


Tensor("model/Reshape_1:0", shape=(?, 70, 230), dtype=float32)


WARNING:tensorflow:From C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\util\tf_should_use.py:170: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02.
Instructions for updating:
Use tf.global_variables_initializer instead.
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1139, in _do_call
return fn(*args)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1121, in _run_fn
status, run_metadata)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\contextlib.py", line 66, in exit
next(self.gen)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 466, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: axis 0 specified more than once.
[[Node: model/ReverseV2_3 = ReverseV2[T=DT_FLOAT, Tidx=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](model/Reshape_2, model/ReverseV2_3/axis)]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:/PerfectProject/NRE/train_GRU.py", line 164, in
tf.app.run()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\platform\app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "D:/PerfectProject/NRE/train_GRU.py", line 148, in main
train_step(temp_word,temp_pos1,temp_pos2,temp_y,settings.big_num)
File "D:/PerfectProject/NRE/train_GRU.py", line 103, in train_step
temp, step, loss, accuracy,summary,l2_loss,final_loss= sess.run([train_op, global_step, m.total_loss, m.accuracy,merged_summary,m.l2_loss,m.final_loss], feed_dict)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 789, in run
run_metadata_ptr)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 997, in _run
feed_dict_string, options, run_metadata)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1132, in _do_run
target_list, options, run_metadata)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1152, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: axis 0 specified more than once.
[[Node: model/ReverseV2_3 = ReverseV2[T=DT_FLOAT, Tidx=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](model/Reshape_2, model/ReverseV2_3/axis)]]

Caused by op 'model/ReverseV2_3', defined at:
File "D:/PerfectProject/NRE/train_GRU.py", line 164, in
tf.app.run()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\platform\app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "D:/PerfectProject/NRE/train_GRU.py", line 49, in main
m = network.GRU(is_training=True, word_embeddings = wordembedding, settings = settings)
File "D:\PerfectProject\NRE\network.py", line 111, in init
[False, True, False])

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\ops\array_ops.py", line 2334, in reverse
return gen_array_ops.reverse_v2(tensor, axis, name)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 2699, in reverse_v2
name=name)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 767, in apply_op
op_def=op_def)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 2506, in create_op
original_op=self._default_original_op, op_def=op_def)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 1269, in init
self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): axis 0 specified more than once.
[[Node: model/ReverseV2_3 = ReverseV2[T=DT_FLOAT, Tidx=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](model/Reshape_2, model/ReverseV2_3/axis)]]

Process finished with exit code 1

image

I'm looking forward your reply.Thank you.

运行除pcnn_att以外的模型会报错,希望得到帮助,谢谢。

raceback (most recent call last):
File "train.py", line 83, in
tf.app.run()
File "/home/cyh/.local/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "train.py", line 80, in main
model(is_training=True)
File "/home/cyh/OpenNRE-master/model/rnn.py", line 13, in rnn
x = framework.encoder.rnn(embedding)
TypeError: rnn() missing 2 required positional arguments: 'hidden_size' and 'sequence_length'

Vec.txt

Hello I am very new to this field. I wanted to know how you got the vec.txt file? If I have to train the models on my own data do I need to create my own vec.txt?

MultiRNNCell implementation in Network.py is bugged. Possible solution included.

As mentioned here: https://stackoverflow.com/questions/47371608/cannot-stack-lstm-with-multirnncell-and-dynamic-rnn
If MultiRNNCell is implemented like this:
cell_forward = tf.nn.rnn_cell.MultiRNNCell([gru_cell_forward] * settings.num_layers) cell_backward = tf.nn.rnn_cell.MultiRNNCell([gru_cell_backward] * settings.num_layers)

The RNN cells inside the MultiRNNCell will be exact copies of the first cell. This means that if the size of the input (word_embedding_size + pos_embedding_size*2 in this case) does not match with gru_size, and num_layers>1, TensorFlow will raise an error.

To be specific, TensorFlow will build the first (and all other) GRU Cells to map input into hidden units. Therefore when the second cell tries to map hidden output 1 to hidden units, there will be an error.

We can fix this by making the first GRUCell different from others:
cell_forward = tf.nn.rnn_cell.MultiRNNCell( [tf.nn.rnn_cell.GRUCell(gru_size)] + [gru_cell_forward] * (settings.num_layers - 1))

Or, we can add a dense layer to map input to the size of GRUCells.

question for using python3 and tensorflow r1.x

我用的是python3和tensorflow r1.x,按照您的说明修改代码之后出现错误:
InvalidArgumentError (see above for traceback): axis 0 specified more than once.
[[Node: model/ReverseV2_3 = ReverseV2[T=DT_FLOAT, Tidx=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](model/Reshape_2, model/ReverseV2_3/axis)]]
请问这是什么原因?
非常感谢!

Need speed optimization for GPU

I find that the code seems to be not that friendly to GPU. If a GPU is used, tensorflow will do all the stuff on GPU automatically. But there is a for-loop, which will hurt the speed significantly. In addition, it's better to do the embedding stuff on CPU either, I think.

I rewrite the code for my own task. The speed using GPU is much slower than CPU. Do you plan to optimize the code for GPU? By the way, how long do you train the model and use which device?

citation?

Thanks for uploading the project! If I want to cite your work, how should I do it? Should I reference this Github project or do you have some document/report/paper to be cited?

about attention

I read your code and got confused in the attention you use. In my understanding, the attention should grab the attention for each sentence and each words in a sentence. But I found that you shuffle your train_words, this just doesn't make any sense to me.

Question about relation for each sentence in training/test data.

I have some difficulty figuring out where exactly the relation in each line of train.txt and test.txt

Since each entity pair could have multiple possibilities of relations, how do you label the sentences with the relation of the two entities? From my understanding, the distant supervision would require no exact sentence-level labeled relation. So how are the train.txt and test.txt produced?

Thanks

Getting Wrong result for an example sentence

test_sentence : m.01rvrn m.04gcbp carlos_delgado london 8 carlos_delgado born in london. ###END###

Output probabilities

[ 5.01433460e-05 1.63105437e-06 7.00082546e-06 2.98229952e-06
5.45311934e-07 6.56117190e-05 6.24323206e-07 2.14673369e-03
1.25849142e-03 1.26197783e-05 2.83242643e-05 2.55511759e-06
5.36649859e-05 3.46176557e-06 1.02176155e-05 2.83429472e-06
4.59302333e-04 1.60637079e-03 4.17622778e-06 1.10091867e-06
4.65527728e-06 4.34826734e-06 1.03743444e-03 5.94867879e-06
3.17883896e-05 3.49962011e-06 1.02767524e-06 4.20275348e-04
6.89600594e-04 6.14084138e-06 1.25078814e-05 4.56587122e-06
3.20838328e-04 4.89041558e-05 6.01866523e-05 4.32176981e-03
1.76615795e-05 5.32836020e-06 3.60898866e-06 2.23168536e-05
8.40354733e-06 1.58599651e-05 2.02828651e-05 3.80020742e-06
1.28869924e-05 2.95039372e-05 2.95423979e-05 5.42388123e-04
6.37627591e-06 2.35860600e-04 1.28738247e-05 1.20697114e-05]

Following are the indexes in descending order of probabilities

[35 7 17 8 22 28 47 16 27 32 49 5 34 12 0 33 24 46 45 10 39 42 36 41 44
50 9 30 51 14 40 2 48 29 23 37 20 31 21 18 43 38 25 13 3 15 11 1 19 26
6 4]

From the output it seems we are getting relation /people/person/place_lived 36 , but we should get /people/person/place_of_birth 8

Can anyone help on this

pr_curve 准确率的疑问

您好,这近跑了一下您这边的实验OPEN_NRE(PCNN_att 模型),想进一步了解test.py 得到的准确率代表的含义。即如何判断模型判断正确(这里对于每对(ent1,ent2)都生成52种关系,判断是否有对应(ent1,ent2,rel_?)在测试集中,这种做法意义是什么?)以下是您的部分代码
for rel in range(1, len(pred)):
flag = int(((entity[0], entity[1], rel) in self.data_instance_triple))
total_recall += flag
test_result.append([(entity[0], entity[1], rel), flag, pred[rel]])

Is L72 in network.py a potential error?

https://github.com/thunlp/TensorFlow-NRE/blob/4d6d321c9b369615ca07508705d921d30d8286d4/network.py#L72

Why are 2 pos1_embedding merged ?
Should this be changed to the following codes ?

inputs_backward = tf.concat(values=[
            tf.nn.embedding_lookup(word_embedding, tf.reverse(self.input_word, [False, True])),
            tf.nn.embedding_lookup(pos1_embedding, tf.reverse(self.input_pos1, [False, True])),
            tf.nn.embedding_lookup(pos2_embedding, tf.reverse(self.input_pos2, [False, True]))], axis=2)

predicted labels

Thanks for sharing OpenNRE framework. I am wondering whether I can get predicted labels for test data, instead of precision and recall of the best epoch. Could you please add this feature to the code.
Regards

Not able to reproduce results or make the PR Curve from files that you give

Hi
I am using the file provided by you in out/sample_allprob_iter_10900.npy and the code provided in plot_pr.py and I am unable to reproduce the PR Curve with these files. I am also unable to train the model and reproduce the results of the paper even after using all the hyperparameters as provided in the paper and also those that have been specified in the network.py file.
Any help will be appreciated.
Thanks
Rishabh

Question about plot_pr.py

It seems like this function is computing the AUC for a binary task instead of a multi-class problem. Are you computing the AUC for every class separately then computing the mean AUC? Or, are you concatenating all the classes together then computing the AUC as if it is a two-class problem? If it is the second - could you please explain this design choice or point out a reference that mathematically explains how that result should be interpreted. Thanks!

Test set accuracy does not match with published result

As shown in the home page, test set accuracy should be around 0.8, while it is around 0.50 on my machine for all test tasks. I'm using tensorflow 1.0.0 and fixed some API migration issues before I could successfully train and test the model, and I was evaluating P@N for iter 14000. Below I pasted the training info and testing info. Please let me know where I could get it wrong. Thank you so much:)

have saved model to ./model/ATT_GRU_model-13500
2017-04-02T03:08:14.022144: step 13550, softmax_loss 8.99307, acc 0.94
2017-04-02T03:08:24.764260: step 13600, softmax_loss 11.1679, acc 0.92
2017-04-02T03:08:35.354639: step 13650, softmax_loss 4.43873, acc 0.98
2017-04-02T03:08:45.710377: step 13700, softmax_loss 12.744, acc 0.94
2017-04-02T03:08:55.166245: step 13750, softmax_loss 2.57561, acc 0.98
2017-04-02T03:09:04.721789: step 13800, softmax_loss 2.85167, acc 0.98
2017-04-02T03:09:14.571793: step 13850, softmax_loss 2.9708, acc 0.98
2017-04-02T03:09:23.866147: step 13900, softmax_loss 4.50743, acc 0.98
2017-04-02T03:09:34.195987: step 13950, softmax_loss 5.79872, acc 0.96
2017-04-02T03:09:44.283621: step 14000, softmax_loss 10.5228, acc 0.92
saving model
have saved model to ./model/ATT_GRU_model-14000
out of range
2017-04-02T03:10:17.838734: step 14050, softmax_loss 2.30686, acc 0.98
2017-04-02T03:10:28.560130: step 14100, softmax_loss 5.12479, acc 0.98
2017-04-02T03:10:38.362117: step 14150, softmax_loss 8.63566, acc 0.94
2017-04-02T03:10:48.828123: stepI tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 56277731 get requests, put_count=56277740 evicted_count=17000 eviction_rate=0.000302073 and unsatisfied allocation rate=0.000307226
14200, softmax_loss 5.62947, acc 0.98
2017-04-02T03:10:59.361231: step 14250, softmax_loss 4.52537, acc 0.98
2017-04-02T03:11:08.783026: step 14300, softmax_loss 32.7668, acc 0.84
2017-04-02T03:11:19.310379: step 14350, softmax_loss 10.8961, acc 0.94
2017-04-02T03:11:29.238714: step 14400, softmax_loss 7.69886, acc 0.94
2017-04-02T03:11:38.763790: step 14450, softmax_loss 14.5586, acc 0.92
2017-04-02T03:11:48.848076: step 14500, softmax_loss 14.7915, acc 0.96

============================================================

Evaluating P@N for iter 14000
Evaluating P@N for one
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 7082 get requests, put_count=1102 evicted_count=1000 eviction_rate=0.907441 and unsatisfied allocation rate=0.999718
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:259] Raising pool_size_limit_ from 100 to 110
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 0 get requests, put_count=6011 evicted_count=6000 eviction_rate=0.99817 and unsatisfied allocation rate=0
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 0 get requests, put_count=4013 evicted_count=4000 eviction_rate=0.996761 and unsatisfied allocation rate=0
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 0 get requests, put_count=3016 evicted_count=3000 eviction_rate=0.994695 and unsatisfied allocation rate=0
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 0 get requests, put_count=1019 evicted_count=1000 eviction_rate=0.981354 and unsatisfied allocation rate=0
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 4716 get requests, put_count=5254 evicted_count=5000 eviction_rate=0.951656 and unsatisfied allocation rate=0.950594
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:259] Raising pool_size_limit_ from 233 to 256
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 0 get requests, put_count=3025 evicted_count=3000 eviction_rate=0.991736 and unsatisfied allocation rate=0
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 0 get requests, put_count=2030 evicted_count=2000 eviction_rate=0.985222 and unsatisfied allocation rate=0
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 0 get requests, put_count=1037 evicted_count=1000 eviction_rate=0.96432 and unsatisfied allocation rate=0
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 7082 get requests, put_count=7491 evicted_count=7000 eviction_rate=0.934455 and unsatisfied allocation rate=0.936317
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:259] Raising pool_size_limit_ from 449 to 493
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 0 get requests, put_count=6049 evicted_count=6000 eviction_rate=0.991899 and unsatisfied allocation rate=0
P@100:
0.53
P@200:
0.525
P@300:
0.51
Evaluating P@N for two
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 0 get requests, put_count=5059 evicted_count=5000 eviction_rate=0.988338 and unsatisfied allocation rate=0
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 0 get requests, put_count=5072 evicted_count=5000 eviction_rate=0.985804 and unsatisfied allocation rate=0
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 0 get requests, put_count=5087 evicted_count=5000 eviction_rate=0.982898 and unsatisfied allocation rate=0
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 0 get requests, put_count=5105 evicted_count=5000 eviction_rate=0.979432 and unsatisfied allocation rate=0
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 7082 get requests, put_count=6529 evicted_count=5000 eviction_rate=0.765814 and unsatisfied allocation rate=0.802033
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:259] Raising pool_size_limit_ from 1400 to 1540
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 0 get requests, put_count=1169 evicted_count=1000 eviction_rate=0.855432 and unsatisfied allocation rate=0
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 0 get requests, put_count=1225 evicted_count=1000 eviction_rate=0.816327 and unsatisfied allocation rate=0
P@100:
0.56
P@200:
0.535
P@300:
0.503333333333
Evaluating P@N for all
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 7082 get requests, put_count=7271 evicted_count=4000 eviction_rate=0.550131 and unsatisfied allocation rate=0.576532
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:259] Raising pool_size_limit_ from 2997 to 3296
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 0 get requests, put_count=3398 evicted_count=3000 eviction_rate=0.882872 and unsatisfied allocation rate=0
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 11798 get requests, put_count=12147 evicted_count=4000 eviction_rate=0.329299 and unsatisfied allocation rate=0.350314
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:259] Raising pool_size_limit_ from 5305 to 5835
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 11798 get requests, put_count=11832 evicted_count=1000 eviction_rate=0.0845166 and unsatisfied allocation rate=0.141634
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:259] Raising pool_size_limit_ from 7764 to 8540
P@100:
0.57
P@200:
0.535
P@300:
0.523333333333
2017-04-02T22:13:33.351736
Evaluating all test data and save data for PR curve
saving all test result...
PR curve area:0.257896324167
2017-04-02T22:14:57.170137
P@N for all test data:
P@100:
0.52
P@200:
0.505
P@300:
0.476666666667

About multi-labels

In the paper: [Lin et al., 2016] Yankai Lin, Shiqi Shen, Zhiyuan Liu, Huanbo Luan, and Maosong Sun. Neural Relation Extraction with Selective Attention over Instances. In Proceedings of ACL,
did the author take account into multi labels problem?
Can you tell me how did you fix bugs of multi-label ? I have not found that you have modified the loss function and prediction.

about the embedding the positions of entities

i'm trying to understand how this output matrix is created to embed the positions of related entities

could you please tell me why these specific type of embedding(where did 60,122 numbers came form in pos_embed() ) is used and how are these type of embedding helps to create a better model

in initial.py
line 5:

`def pos_embed(x):
	if x < -60:
		return 0
	if x >= -60 and x <= 60:
		return x+61
	if x > 60:
		return 122
`

line 124:

for i in range(fixlen):  #1-70
			word = word2id['BLANK']
			rel_e1 = pos_embed(i - en1pos)
			rel_e2 = pos_embed(i - en2pos)
			output.append([word,rel_e1,rel_e2])
		for i in range(min(fixlen,len(sentence))):
			word = 0
			if sentence[i] not in word2id:
				word = word2id['UNK']
			else:
				word = word2id[sentence[i]]			
			output[i][0] = word

Question about sen_r in network,py

In Lin's paper, formula (7) computes attention of setence-level, in which e_i "scores how well the input sentence x_i and the predict relation r matches" and r of formula (8) "indicates the representation of relation r".
So, I think r is the vector of target relation for a pair of entity。But in network.py, sen_r is initialized by random and shared by all train samples. I'm puzzled about it.
Did I misunderstand? How to understand r and sen_r?
Thanks.

train_GRU.py IndexError:list index out of range

你好,
我在运行 train_GRU.py 时,遇到list Index out of range error,具体错误显示在
network.py
sen_a = tf.get_variable('attention_A',[gru_size])
麻烦看一下这个问题怎么解决,谢谢!

请教

您好
train.txt: training file, format (fb_mid_e1, fb_mid_e2, e1_name, e2_name, relation, sentence).
对其中,fb_mid_e1,fb_mid_e2,e1_name,e2_name,请问是什么意思?
另外,relation 的结果是实体/实体/关系吗?
感谢

Not able to reproduce the results

I changed the codes to be compatible with TF1.3 and run the training and test.
The performance I got is lower than reported. Any clue?

Evaluating P@N for iter 11000
Evaluating P@N for one
P@100:
0.73
P@200:
0.645
P@300:
0.6
Evaluating P@N for two
P@100:
0.77
P@200:
0.69
P@300:
0.636666666667
Evaluating P@N for all
P@100:
0.77
P@200:
0.695
P@300:
0.66
2017-10-24T19:14:49.392740
Evaluating all test data and save data for PR curve
saving all test result...
PR curve area:0.347798385666
2017-10-24T19:17:38.815224
P@N for all test data:
P@100:
0.78
P@200:
0.72
P@300:
0.69

Thanks,
Lisheng

How to interpret test_results?

In the test_results folder, I am getting two different numpy arrays named model_name_x and model_name_y. What do they mean? Also how do you interpret the array inside? How do we know the entities that are recognized and the relationships created for different sentences?

您好,请问一下

抽取出来的结果转换为txt格式后,与哪个.txt文件的格式相同。谢谢

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.