{"id":28676567,"url":"https://github.com/zjunlp/knn-kg","last_synced_at":"2025-10-25T18:38:09.352Z","repository":{"id":41165017,"uuid":"439533434","full_name":"zjunlp/KNN-KG","owner":"zjunlp","description":"[NLPCC 2023] Reasoning Through Memorization: Nearest Neighbor Knowledge Graph Embeddings with Language Models","archived":false,"fork":false,"pushed_at":"2023-07-31T13:21:27.000Z","size":34454,"stargazers_count":52,"open_issues_count":1,"forks_count":9,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-06-13T23:05:08.894Z","etag":null,"topics":["fb15k-237","fb15k237","inductive","inductive-reasoning","kg","kge","knn","knn-kge","knnkg","knowledge-graph","knowledge-graph-embeddings","machine-learning","semiparametric-models","transductive","transductive-reasoning","wn18rr"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zjunlp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-18T05:10:27.000Z","updated_at":"2025-03-19T10:17:53.000Z","dependencies_parsed_at":"2023-01-20T17:00:51.111Z","dependency_job_id":null,"html_url":"https://github.com/zjunlp/KNN-KG","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zjunlp/KNN-KG","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjunlp%2FKNN-KG","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjunlp%2FKNN-KG/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjunlp%2FKNN-KG/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjunlp%2FKNN-KG/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zjunlp","download_url":"https://codeload.github.com/zjunlp/KNN-KG/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjunlp%2FKNN-KG/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281003219,"owners_count":26428017,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fb15k-237","fb15k237","inductive","inductive-reasoning","kg","kge","knn","knn-kge","knnkg","knowledge-graph","knowledge-graph-embeddings","machine-learning","semiparametric-models","transductive","transductive-reasoning","wn18rr"],"created_at":"2025-06-13T23:05:12.261Z","updated_at":"2025-10-25T18:38:09.347Z","avatar_url":"https://github.com/zjunlp.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KNN-KG\nCode for the NLPCC2023 paper \"[Reasoning Through Memorization: Nearest Neighbor Knowledge Graph Embeddings with Language Models](https://arxiv.org/abs/2201.05575)\".\n\n\u003cdiv align=center\u003e\u003cimg src=\"model.png\" width=\"80%\" height=\"80%\" /\u003e\u003c/div\u003e\n\nRequirements\n==========\nTo install requirements:\n\n```\npip install -r requirements.txt\n```\n\n\nRun the experiments\n==========\n\n## Training\n\n### Entity Embedding Initialization\n\nUse the command below to add entities to BERT and train the entity embedding layer to use in the later training. For another dataset `WN18RR` just replacing the dataset name will be fine.\n\n```shell\n./scripts/pretrain_fb15k.sh\n```\n\nThe parameters of Entity Embedding Layer trained will be used in the next `Entity prediction task`.\n\n ### Entity Prediction Task\n\nUse the command below to train the model to predict the correct entity in the masked position.\n\n```shell\n./scripts/fb15k-237/fb15k.sh\n```\n\n## Consturct Knowledge Store\n\nAfter training the model in `Entity prediction task`, we use the model to get the knowledge store built from triples and descriptions.\n\n```shell\n./scripts/fb15k-237/get_knowledge_store.sh\n```\n\n## Inference\n\nHere we have a trained model and our knowledge store (e.g., faiss.dump file), use the command below to inference in the test set.\n\n```shell\n./scripts/fb15k-237/inference.sh\n```\n\nAnd for inductive setting, the command is similar to the transductive setting (just replace the `dataset` with inductive dataset), the code will automatically handle the differences.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzjunlp%2Fknn-kg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzjunlp%2Fknn-kg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzjunlp%2Fknn-kg/lists"}