CodeKGC: Code Language Model for Generative Knowledge Graph Construction
Zhen Bi, Jing Chen, Yinuo Jiang, Feiyu Xiong, Wei Guo, Huajun Chen, Ningyu Zhang
TL;DR
CodeKGC reframes knowledge graph construction as a code-generation problem, harnessing code-language models and schema-aware prompts to preserve the structural topology of KG data. By encoding KG schemas in Python class definitions and optionally guiding generation with rationales, CodeKGC improves both zero-shot and few-shot extraction on ADE, CoNLL04, and SciERC compared to traditional text-based prompts. Extensive ablations show the value of schema-aware prompts and rationale steps, and the approach demonstrates robustness to hard cases like overlapping triples, especially with larger code LMs. The work suggests a promising direction for structured information extraction, linking programming-language structure with semantic graph construction and enabling more reliable, scalable KG population.
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.
