Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
leo 8df5b41331 | 1 year ago | |
---|---|---|
data | 6 years ago | |
LICENSE | 7 years ago | |
README.md | 1 year ago | |
init.cpp | 4 years ago | |
make.sh | 6 years ago | |
test.cpp | 4 years ago | |
transD.py | 4 years ago | |
transE.py | 4 years ago | |
transH.py | 4 years ago | |
transR.py | 4 years ago |
This repository is a subproject of THU-OpenSK, and all subprojects of THU-OpenSK are as follows.
The implementation of TransE [1], TransH [2], TransR [3], TransD [4] for knowledge representation learning (KRL). The overall framework is based on TensorFlow. We use C++ to implement some underlying operations such as data preprocessing and negative sampling. For each specific model, it is implemented by TensorFlow with Python interfaces so that there is a convenient platform to run models on GPUs.
These codes will be gradually integrated into the new framework [OpenKE].
If you have a new idea and need to implement its code, you just need to change Python interfaces for your customized model. Read these codes, you will find that to change the class TransXModel will meet your needs.
More results about models can be found in ("https://github.com/thunlp/KB2E").
Datasets are required in the following format, containing three files:
triple2id.txt: training file, the first line is the number of triples for training. Then the follow lines are all in the format (e1, e2, rel).
entity2id.txt: all entities and corresponding ids, one per line. The first line is the number of entities.
relation2id.txt: all relations and corresponding ids, one per line. The first line is the number of relations.
You can download FB15K and WN18 from [Download], and the more datasets can also be found in ("https://github.com/thunlp/KB2E").
bash make.sh
To train models based on random initialization:
Change class Config in transX.py
class Config(object):
def __init__(self):
...
lib.setInPath("your training data path...")
self.testFlag = False
self.loadFromData = False
...
python transX.py
To train models based on pretrained results:
Change class Config in transX.py
class Config(object):
def __init__(self):
...
lib.setInPath("your training data path...")
self.testFlag = False
self.loadFromData = True
...
python transX.py
To test your models:
Change class Config in transX.py
class Config(object):
def __init__(self):
...
test_lib.setInPath("your testing data path...")
self.testFlag = True
self.loadFromData = True
...
python transX.py
If you use the code, please kindly cite the papers listed in our reference.
[1] Bordes, Antoine, et al. Translating embeddings for modeling multi-relational data. Proceedings of NIPS, 2013.
[2] Zhen Wang, Jianwen Zhang, et al. Knowledge Graph Embedding by Translating on Hyperplanes. Proceedings of AAAI, 2014.
[3] Yankai Lin, Zhiyuan Liu, et al. Learning Entity and Relation Embeddings for Knowledge Graph Completion. Proceedings of AAAI, 2015.
[4] Guoliang Ji, Shizhu He, et al. Knowledge Graph Embedding via Dynamic Mapping Matrix. Proceedings of ACL, 2015.
No Description
Text Python other
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》