This is an implementation of the paper Knowledge Graph Embedding with Numeric Attributes of Entities .
These codes base on TransE [2] and TensorFlow-TransX
Datasets are required in the following format:
-
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).
-
valid2id.txt: the same format as triple2id.txt
-
test2id.txt: the same format as triple2id.txt
-
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.
-
attr2id.txt: all numeric attributes and corresponding ids. The first line is the number of attribute relation.
-
attrm2id.txt: attributive triplets, the first line is the number of attributive triplets. Format (e, a, v), v is normalized by Max-Min method.
bash makeEA.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 transE/transEA.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 transE/transEA.py
If you use the code or datasets, please kindly cite the papers listed in our reference.
[1] Yanrong Wu, Zhichun Wang. Knowledge Graph Embedding with Numeric Attributes of Entities. Proceedings of The Third Workshop on Representation Learning for NLP. 2018.
[2] Bordes, Antoine, et al. Translating embeddings for modeling multi-relational data. Proceedings of NIPS, 2013.
[3] Yankai Lin, Zhiyuan Liu, et al. Learning Entity and Relation Embeddings for Knowledge Graph Completion. Proceedings of AAAI, 2015.