{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/codekgc-code-language-model-for-generative","title":"CodeKGC: Code Language Model for Generative Knowledge Graph Construction","arxiv_id":"2304.09048","date":"2023-04-18","proceeding":null,"authors":["Zhen Bi","Jing Chen","Yinuo Jiang","Feiyu Xiong","Wei Guo","Huajun Chen","Ningyu Zhang"],"abstract":"Current generative knowledge graph construction approaches usually fail to capture structural knowledge by simply flattening natural language into serialized texts or a specification language. However, large generative language model trained on structured data such as code has demonstrated impressive capability in understanding natural language for structural prediction and reasoning tasks. Intuitively, we address the task of generative knowledge graph construction with code language model: given a code-format natural language input, the target is to generate triples which can be represented as code completion tasks. Specifically, we develop schema-aware prompts that effectively utilize the semantic structure within the knowledge graph. As code inherently possesses structure, such as class and function definitions, it serves as a useful model for prior semantic structural knowledge. Furthermore, we employ a rationale-enhanced generation method to boost the performance. Rationales provide intermediate steps, thereby improving knowledge extraction abilities. Experimental results indicate that the proposed approach can obtain better performance on benchmark datasets compared with baselines. Code and datasets are available in https://github.com/zjunlp/DeepKE/tree/main/example/llm.","url_abs":"https://arxiv.org/abs/2304.09048v2","url_pdf":"https://arxiv.org/pdf/2304.09048v2.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"codekgc-code-language-model-for-generative","repo_url":"https://github.com/zjunlp/deepke","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"codekgc-code-language-model-for-generative","repo_url":"https://github.com/zjunlp/DeepKE/tree/main/example/llm","is_official":1,"mentioned_in_paper":0,"mentioned_in_github":0,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"code-completion","task_name":"Code Completion"},{"task_slug":"language-modeling","task_name":"Language Modeling"},{"task_slug":"language-modelling","task_name":"Language Modelling"},{"task_slug":"graph-construction","task_name":"graph construction"}],"methods":[{"method_slug":"fail","method_name":"fail"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2304.09048","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2304.09048"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/zjunlp/DeepKE/tree/main/example/llm","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/zjunlp/deepke","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran_draft_wrong":1,"unverified":15},"by_repo_kind":{"official":{"samples":16,"ran":1,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"705aa67db81dcc32","entry":"gen_train_facts","repo":"zjunlp/DeepKE","repo_kind":"official","path":"src/deepke/relation_extraction/document/evaluation.py","file_url":"https://github.com/zjunlp/DeepKE/blob/HEAD/src/deepke/relation_extraction/document/evaluation.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"705aa67db81dcc32"}},{"code_sha256_prefix":"b6545335b7f399a2","entry":"chunks","repo":"zjunlp/DeepKE","repo_kind":"official","path":"src/deepke/relation_extraction/document/prepro.py","file_url":"https://github.com/zjunlp/DeepKE/blob/HEAD/src/deepke/relation_extraction/document/prepro.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"b6545335b7f399a2"}},{"code_sha256_prefix":"20c8771d9d2aae90","entry":"collate_fn","repo":"zjunlp/DeepKE","repo_kind":"official","path":"src/deepke/relation_extraction/document/utils.py","file_url":"https://github.com/zjunlp/DeepKE/blob/HEAD/src/deepke/relation_extraction/document/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"20c8771d9d2aae90"}},{"code_sha256_prefix":"53be30fa2bb69d92","entry":"collate_fn_sample","repo":"zjunlp/DeepKE","repo_kind":"official","path":"src/deepke/relation_extraction/document/utils.py","file_url":"https://github.com/zjunlp/DeepKE/blob/HEAD/src/deepke/relation_extraction/document/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"53be30fa2bb69d92"}},{"code_sha256_prefix":"859f514ce96f405e","entry":"convert","repo":"zjunlp/DeepKE","repo_kind":"official","path":"src/deepke/triple_extraction/PRGC/dataloader_utils.py","file_url":"https://github.com/zjunlp/DeepKE/blob/HEAD/src/deepke/triple_extraction/PRGC/dataloader_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"859f514ce96f405e"}},{"code_sha256_prefix":"7b0a68af7010382a","entry":"evaluate","repo":"zjunlp/DeepKE","repo_kind":"official","path":"src/deepke/triple_extraction/PRGC/evaluate.py","file_url":"https://github.com/zjunlp/DeepKE/blob/HEAD/src/deepke/triple_extraction/PRGC/evaluate.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"7b0a68af7010382a"}},{"code_sha256_prefix":"6adefb5e4abb5be2","entry":"find_head_idx","repo":"zjunlp/DeepKE","repo_kind":"official","path":"src/deepke/triple_extraction/PRGC/dataloader_utils.py","file_url":"https://github.com/zjunlp/DeepKE/blob/HEAD/src/deepke/triple_extraction/PRGC/dataloader_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"6adefb5e4abb5be2"}},{"code_sha256_prefix":"0858952626966671","entry":"get_labels","repo":"zjunlp/DeepKE","repo_kind":"official","path":"src/deepke/relation_extraction/few_shot/generate_k_shot.py","file_url":"https://github.com/zjunlp/DeepKE/blob/HEAD/src/deepke/relation_extraction/few_shot/generate_k_shot.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0858952626966671"}},{"code_sha256_prefix":"626bdc34ef9914c2","entry":"get_metrics","repo":"zjunlp/DeepKE","repo_kind":"official","path":"src/deepke/triple_extraction/PRGC/evaluate.py","file_url":"https://github.com/zjunlp/DeepKE/blob/HEAD/src/deepke/triple_extraction/PRGC/evaluate.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"626bdc34ef9914c2"}},{"code_sha256_prefix":"9f47bb60899af064","entry":"multilabel_categorical_crossentropy","repo":"zjunlp/DeepKE","repo_kind":"official","path":"src/deepke/relation_extraction/document/losses.py","file_url":"https://github.com/zjunlp/DeepKE/blob/HEAD/src/deepke/relation_extraction/document/losses.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9f47bb60899af064"}},{"code_sha256_prefix":"fd5637cef4c93295","entry":"official_evaluate","repo":"zjunlp/DeepKE","repo_kind":"official","path":"src/deepke/relation_extraction/document/evaluation.py","file_url":"https://github.com/zjunlp/DeepKE/blob/HEAD/src/deepke/relation_extraction/document/evaluation.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"fd5637cef4c93295"}},{"code_sha256_prefix":"1caea7819d2e4841","entry":"process_long_input","repo":"zjunlp/DeepKE","repo_kind":"official","path":"src/deepke/relation_extraction/document/prepro.py","file_url":"https://github.com/zjunlp/DeepKE/blob/HEAD/src/deepke/relation_extraction/document/prepro.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"1caea7819d2e4841"}},{"code_sha256_prefix":"402533ae0c194b8a","entry":"read_examples","repo":"zjunlp/DeepKE","repo_kind":"official","path":"src/deepke/triple_extraction/PRGC/dataloader_utils.py","file_url":"https://github.com/zjunlp/DeepKE/blob/HEAD/src/deepke/triple_extraction/PRGC/dataloader_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"402533ae0c194b8a"}},{"code_sha256_prefix":"94ab66ec54e9046e","entry":"span2str","repo":"zjunlp/DeepKE","repo_kind":"official","path":"src/deepke/triple_extraction/PRGC/evaluate.py","file_url":"https://github.com/zjunlp/DeepKE/blob/HEAD/src/deepke/triple_extraction/PRGC/evaluate.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"94ab66ec54e9046e"}},{"code_sha256_prefix":"3e44103f6e52ca2f","entry":"split_label_words","repo":"zjunlp/DeepKE","repo_kind":"official","path":"src/deepke/relation_extraction/few_shot/get_label_word.py","file_url":"https://github.com/zjunlp/DeepKE/blob/HEAD/src/deepke/relation_extraction/few_shot/get_label_word.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3e44103f6e52ca2f"}},{"code_sha256_prefix":"25620f5a71d51a9f","entry":"to_official","repo":"zjunlp/DeepKE","repo_kind":"official","path":"src/deepke/relation_extraction/document/evaluation.py","file_url":"https://github.com/zjunlp/DeepKE/blob/HEAD/src/deepke/relation_extraction/document/evaluation.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"25620f5a71d51a9f"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}