Skip to main content

Path-based reasoning with K-nearest neighbor and position embedding for knowledge graph completion


Knowledge graph completion aims to perform link prediction between entities. Reasoning over paths in incomplete knowledge graphs has become a hot research topic. However, most of the existing path reasoning methods ignore both the overlapping phenomenon of paths between similar relations and the order information of relations in paths, and they only consider the obvious paths between entities. To address the problems of knowledge graph reasoning, a new path-based reasoning method with K-Nearest Neighbor and position embedding is proposed in this paper. The method first projects entities and relations to continuous vector space, and then utilizes the idea of the K-Nearest Neighbor algorithm to find the K nearest neighbors of each relation. After that, the paths of similar relations are merged. Then, paths are modeled through the combination operations on relations. The position information of the relations is considered during the combination, that is, the position embedding is added to the relation vector in the path. A series of experiments are conducted on real datasets to prove the effectiveness of the proposed method. The experimental results show that the proposed method significantly outperforms all baselines on entity prediction and relation prediction tasks.

This is a preview of subscription content, access via your institution.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7
Fig. 8
Fig. 9

Data Availability

The datasets generated and/or analysed during the current study are available in

Code Availability

The code implemented during the current study are available in


  1. 1.

    The code and data used for this paper can be obtained from


  1. Bollacker, K., Evans, C., Paritosh, P., Sturge, T., & Taylor, J. (2008). Freebase: a collaboratively created graph database for structuring human knowledge. In Proceedings of the 2008 ACM SIGMOD international conference on management of data (pp. 1247–1250).

  2. Bordes, A., Glorot, X., Weston, J., & Bengio, Y. (2014). A semantic matching energy function for learning with multi-relational data. Machine Learning, 94(2), 233–259.

    MathSciNet  Article  Google Scholar 

  3. Bordes, A., Usunier, N., Garcia-Duran, A., Weston, J., & Yakhnenko, O. (2013). Translating embeddings for modeling multi-relational data. Advances in Neural Information Processing Systems, 26(26), 2787–2795.

    Google Scholar 

  4. Chang, K. W., Yih, W. T., Yang, B., & Meek, C. (2014). Typed tensor decomposition of knowledge bases for relation extraction. In Proceedings of the 2014 conference on empirical methods in natural language processing (EMNLP) (pp. 1568–1579).

  5. Chen, X., Jia, S., & Xiang, Y. (2020). A review: knowledge reasoning over knowledge graph. Expert Systems with Applications, 141, 112948.

    Article  Google Scholar 

  6. Dettmers, T., Minervini, P., Stenetorp, P., & Riedel, S. (2017). Convolutional 2d knowledge graph embeddings. In Proceedings of the thirty-second AAAI conference on artificial intelligence (pp. 1811–1818).

  7. Ebisu, T., & Ichise, R. (2017). Toruse: Knowledge graph embedding on a lie group. In Proceedings of the thirty-second AAAI conference on artificial intelligence (pp. 1819–1826).

  8. Jagvaral, B., Lee, W. K., Roh, J. S., Kim, M. S., & Park, Y. T. (2020). Path-based reasoning approach for knowledge graph completion using cnn-bilstm with attention mechanism. Expert Systems with Applications, 142, 112960.

    Article  Google Scholar 

  9. Ji, G., He, S., Xu, L., Liu, K., & Zhao, J. (2015). Knowledge graph embedding via dynamic mapping matrix. In Proceedings of the 53rd annual meeting of the association for computational linguistics and the 7th international joint conference on natural language processing (volume 1: Long papers) (pp. 687–696).

  10. Ji, S., Pan, S., Cambria, E., Marttinen, P., & Yu, P. S. (2020). A survey on knowledge graphs: Representation, acquisition and applications. arXiv:2002.00388.

  11. Jia, N., Cheng, X., & Su, S. (2020). Improving knowledge graph embedding using locally and globally attentive relation paths. In European conference on information retrieval (pp. 17–32). Springer.

  12. Kazemi, S. M., & Poole, D. (2018). Simple embedding for link prediction in knowledge graphs. In Advances in neural information processing systems (pp. 4284–4295).

  13. Lao, N., & Cohen, W. W. (2010). Relational retrieval using a combination of path-constrained random walks. Machine Learning, 81(1), 53–67.

    MathSciNet  Article  Google Scholar 

  14. Lao, N., Mitchell, T., & Cohen, W. (2011). Random walk inference and learning in a large scale knowledge base. In Proceedings of the 2011 conference on empirical methods in natural language processing (pp. 529–539).

  15. Lehmann, J., Isele, R., Jakob, M., Jentzsch, A., Kontokostas, D., Mendes, P. N., Hellmann, S., Morsey, M., Van Kleef, P., Auer, S., & et al. (2015). Dbpedia–a large-scale, multilingual knowledge base extracted from wikipedia. Semantic Web, 6(2), 167–195.

    Article  Google Scholar 

  16. Lei, K., Zhang, J., Xie, Y., Wen, D., Chen, D., Yang, M., & Shen, Y. (2019). Path-based reasoning with constrained type attention for knowledge graph completion. Neural Computing and Applications, 1–10.

  17. Lin, X., Liang, Y., Giunchiglia, F., Feng, X., & Guan, R. (2016). Compositional learning of relation path embedding for knowledge base completion. arXiv:1611.07232.

  18. Lin, Y., Liu, Z., Luan, H., Sun, M., Rao, S., & Liu, S. (2015). Modeling relation paths for representation learning of knowledge bases. In Proceedings of the 2015 conference on empirical methods in natural language processing (pp. 705–714).

  19. Lin, Y., Liu, Z., Sun, M., Liu, Y., & Zhu, X. (2015). Learning entity and relation embeddings for knowledge graph completion. 2015, 2181–2187.

  20. Mikolov, T., Sutskever, I., Chen, K., Corrado, G. S., & Dean, J. (2013). Distributed representations of words and phrases and their compositionality. Advances in neural information processing systems, 26, 3111–3119.

    Google Scholar 

  21. Miller, G. A. (1995). Wordnet: a lexical database for english. Communications of the ACM, 38(11), 39–41.

    Article  Google Scholar 

  22. Nguyen, D. Q., Nguyen, T. D., Nguyen, D. Q., & Phung, D. (2017). A novel embedding model for knowledge base completion based on convolutional neural network. arXiv:1712.02121.

  23. Nickel, M., Tresp, V., & Kriegel, H. P. (2011). A three-way model for collective learning on multi-relational data. In ICML, (Vol. 11 pp. 809–816).

  24. Niu, G., Zhang, Y., Li, B., Cui, P., Liu, S., Li, J., & Zhang, X. (2020). Rule-guided compositional representation learning on knowledge graphs. In Proceedings of the AAAI conference on artificial intelligence, (Vol. 34 pp. 2950–2958).

  25. Sacenti, J., Fileto, R., & Willrich, R. (2021). Knowledge graph summarization impacts on movie recommendations. Journal of Intelligent Information Systems (1).

  26. Shen, Y., Ding, N., Zheng, H. T., Li, Y., & Yang, M. (2020). Modeling relation paths for knowledge graph completion. IEEE Transactions on Knowledge and Data Engineering.

  27. Shen, Y., Wen, D., Li, Y., Du, N., Zheng, H.t., & Yang, M. (2019). Path-based attribute-aware representation learning for relation prediction. In Proceedings of the 2019 SIAM international conference on data mining (pp. 639–647). SIAM.

  28. Singhal, A. (2012). Introducing the knowledge graph: things, not strings. Official google blog, 5.

  29. Suchanek, F. M., Kasneci, G., & Weikum, G. (2007). Yago: a core of semantic knowledge. In Proceedings of the 16th international conference on World Wide Web (pp. 697–706).

  30. Sudhahar, S., Roberts, I., & Pierleoni, A. (2019). Reasoning over paths via knowledge base completion. arXiv:1911.00492.

  31. Sun, Z., Deng, Z. H., Nie, J. Y., & Tang, J. (2019). Rotate: Knowledge graph embedding by relational rotation in complex space. In 7Th international conference on learning representations (pp. 1–18).

  32. Trouillon, T., Welbl, J., Riedel, S., Gaussier, É., & Bouchard, G. (2016). Complex embeddings for simple link prediction. In Inproceedings of the 33rd international conference on machine learning.

  33. Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, Ł., & Polosukhin, I. (2017). Attention is all you need. In Advances in neural information processing systems (pp. 5998–6008).

  34. Wang, H., Ren, H., & Leskovec, J. (2020). Entity context and relational paths for knowledge graph completion. arXiv:2002.06757.

  35. Wang, Z., Zhang, J., Feng, J., & Chen, Z. (2014). Knowledge graph embedding by translating on hyperplanes. In AAAI, (Vol. 14 pp. 1112–1119). Citeseer.

  36. Xiong, W., Hoang, T., & Wang, W. Y. (2017). Deeppath: A reinforcement learning method for knowledge graph reasoning. arXiv:1707.06690.

  37. Yang, B., Yih, W.t., He, X., Gao, J., & Deng, L. (2015). Embedding entities and relations for learning and inference in knowledge bases. In Proceedings of the 3rd international conference on learning representations (pp. 1–13).

  38. Zhang, S., Sun, Z., & Zhang, W. (2020). Improve the translational distance models for knowledge graph embedding. Journal of Intelligent Information Systems, 55(2), 1–23.

    Google Scholar 

  39. Zhang, S., Tay, Y., Yao, L., & Liu, Q. (2019). Quaternion knowledge graph embeddings. In Advances in neural information processing systems (pp. 2735–2745).

  40. Zhang, Z., Cai, J., Zhang, Y., & Wang, J. (2020). Learning hierarchy-aware knowledge graph embeddings for link prediction. In AAAI (pp. 3065–3072).

  41. Zhu, Y., Liu, H., Wu, Z., Song, Y., & Zhang, T. (2019). Representation learning with ordered relation paths for knowledge graph completion. In Proceedings of the 2019 conference on empirical methods in natural language processing and the 9th international joint conference on natural language processing (pp. 2662–2671).

Download references


This work was jointly supported by the National Natural Science Foundation of China (61876027, 61751312, 61533020), and the Natural Science Foundation of Chongqing (cstc2019jcyj-cxttX0002).

Author information




Related work was carried out by all the authors. The implementation of the proposal and experiments was carried out by Zhihan Peng. All authors drafted, revised and approved the manuscript.

Corresponding author

Correspondence to Hong Yu.

Ethics declarations

Conflict of Interests

The authors have no conflicts of interest to declare that are relevant to the content of this article.

Additional information

Publisher’s note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Rights and permissions

Reprints and Permissions

About this article

Verify currency and authenticity via CrossMark

Cite this article

Peng, Z., Yu, H. & Jia, X. Path-based reasoning with K-nearest neighbor and position embedding for knowledge graph completion. J Intell Inf Syst (2021).

Download citation


  • Knowledge graph completion
  • Path reasoning
  • Position embedding
  • Relation similarity
  • K-nearest neighbor