Coder Social home page Coder Social logo

daiquocnguyen / r-men Goto Github PK

View Code? Open in Web Editor NEW
79.0 5.0 14.0 53.15 MB

Transformer-based Memory Networks for Knowledge Graph Embeddings (ACL 2020) (Pytorch and Tensorflow)

License: Apache License 2.0

Python 81.51% C++ 7.78% C 10.66% Shell 0.04%
triple-classification relational-memory self-attention knowledge-graph transformer search-personalization knowledge-graph-transformer knowledge-graph-embeddings

r-men's Introduction

Transformer-based Memory Networks for Knowledge Graph EmbeddingsTwitter

GitHub top languageGitHub issues GitHub repo size GitHub last commit GitHub forks GitHub stars GitHub

This program provides the implementation of our KG embedding model R-MeN as described in the ACL2020 paper. R-MeN utilizes a transformer-based memory network to model (head entity, relation, tail entity) in knowledge graphs.

News

  • June 11: Update Pytorch (1.5.0) implementation. This implementation, which is based on the OpenKE framework, aims to adapt R-MeN for knowledge graph completion (for future works).

  • April 04: The Tensorflow implementation was completed one year ago, and now it is out-of-date, caused by the change of Tensorflow from 1.x to 2.x.

Usage

Requirements

  • Python 3.x
  • Tensorflow 1.x
  • dm-sonnet 1.34
  • scipy 1.3

Running commands:

Without using the CNN decoder (v1):

$ python train_R_MeN_TripleCls.py --name WN11 --embedding_dim 50 --num_epochs 30 --batch_size 16 --head_size 512 --memory_slots 1 --num_heads 4 --attention_mlp_layers 4 --learning_rate 0.0001 --model_name wn11_d50_bs16_mlp4_hs512_1_4_2

$ python train_R_MeN_TripleCls.py --name FB13 --embedding_dim 50 --num_epochs 30 --batch_size 256 --head_size 1024 --memory_slots 1 --num_heads 1 --attention_mlp_layers 3 --learning_rate 0.000001 --model_name fb13_d50_bs256_mlp3_hs1024_1_1_6

With using the CNN decoder:

$ python train_R_MeN_TripleCls_CNN.py --name WN11 --embedding_dim 50 --num_epochs 30 --batch_size 16 --head_size 1024 --memory_slots 1 --num_heads 3 --attention_mlp_layers 4 --num_filters 1024 --learning_rate 0.0001 --model_name wn11_d50_bs16_f1024_mlp4_hs1024_1_3_2
	
$ python train_R_MeN_TripleCls_CNN.py --name FB13 --embedding_dim 50 --num_epochs 30 --batch_size 256 --head_size 1024 --memory_slots 1 --num_heads 2 --attention_mlp_layers 4 --num_filters 1024 --learning_rate 0.000005 --model_name fb13_d50_bs256_f1024_mlp4_hs1024_1_2_5

Cite

Please cite the paper whenever R-MeN is used to produce published results or incorporated into other software:

@inproceedings{Nguyen2020RMeN,
	author={Dai Quoc Nguyen and Tu Dinh Nguyen and Dinh Phung},
	title={A Relational Memory-based Embedding Model for Triple Classification and Search Personalization},
	booktitle={Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics (ACL)},
	pages={3429โ€“-3435},
	year={2020}
}

License

As a free open-source implementation, R-MeN is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. All other warranties including, but not limited to, merchantability and fitness for purpose, whether express, implied, or arising by operation of law, course of dealing, or trade usage are hereby disclaimed. I believe that the programs compute what I claim they compute, but I do not guarantee this. The programs may be poorly and inconsistently documented and may contain undocumented components, features or modifications. I make no guarantee that these programs will be suitable for any application.

R-MeN is licensed under the Apache License 2.0.

r-men's People

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

Watchers

 avatar  avatar  avatar  avatar  avatar

r-men's Issues

About decoder

I would like to ask about how the decoder is implemented, is there any detailed code? Thank you !

Runtime Error in pytorch version

Hi, I've been learning your code implentented by pyTorch lately. After I finished installing the required packages and started running the code by using console :python RMeN_pytorch/train_RMeN.py,the error occurs:

Namespace(attention_mlp_layers=2, checkpoint_path=None, dataset='WN18RR', dropout=0.5, gate_style='memory', head_size=64, hidden_size=50, learning_rate=0.005, lmbda=0.1, lmbda2=0.01, memory_slots=1, mode='train', model_name='RMeN', nbatches=100, neg_num=1, num_epochs=400, num_heads=2, num_of_filters=100, optim='adagrad', save_steps=1000, test_file='', use_init=1, use_pos=1, valid_steps=100)
Writing to /home/jojo/PythonProjects/KGE/R-MeN/runs_RMeN

Input Files Path : ./benchmarks/WN18RR/
Test File Path : 
The toolkit is importing datasets.
The total of relations is 11.
The total of entities is 40943.
The total of train triples is 86835.
The total of test triples is 3134.
The total of valid triples is 3034.
Initializing training model...
Finish initializing
  0%|                                                                                                                     | 0/400 [00:00<?, ?it/s]/home/jojo/PythonProjects/KGE/R-MeN/RMeN_pytorch/relational_rnn_general.py:177: UserWarning: Output 0 of SplitWithSizesBackward is a view and is being modified inplace. This view is an output of a function that returns multiple views. Inplace operators on such views are being deprecated and will be forbidden starting from version 1.8. Consider using `unsafe_` version of the function that produced this view or don't modify this view inplace. (Triggered internally at  /pytorch/torch/csrc/autograd/variable.cpp:491.)
  q *= (self.key_size ** -0.5)
  0%|                                                                                                                     | 0/400 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "train_RMeN.py", line 139, in <module>
    con.training_model()
  File "/home/jojo/PythonProjects/KGE/R-MeN/RMeN_pytorch/Config.py", line 462, in training_model
    loss = self.train_one_step()
  File "/home/jojo/PythonProjects/KGE/R-MeN/RMeN_pytorch/Config.py", line 416, in train_one_step
    loss.backward()
  File "/home/jojo/anaconda3/envs/tf2/lib/python3.7/site-packages/torch/tensor.py", line 221, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph)
  File "/home/jojo/anaconda3/envs/tf2/lib/python3.7/site-packages/torch/autograd/__init__.py", line 132, in backward
    allow_unreachable=True)  # allow_unreachable flag
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [1736, 2, 2, 192]], which is output 0 of PermuteBackward, is at version 1; expected version 0 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

my torch version is 1.7.1 and python version is 3.7

Looking forward to your reply.

About positional embedding

Thank you for your code. It is very helpful to me, but I have some questions. What is positional embedding ? How do you initialize it ?

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.