{"id":26418,"date":"2025-02-22T18:37:22","date_gmt":"2025-02-22T10:37:22","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=26418"},"modified":"2025-02-22T18:37:22","modified_gmt":"2025-02-22T10:37:22","slug":"kg-gen","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/en\/kg-gen\/","title":{"rendered":"KG Gen\uff1a\u4ece\u7eaf\u6587\u672c\u4e2d\u81ea\u52a8\u751f\u6210\u77e5\u8bc6\u56fe\u8c31\u7684\u5f00\u6e90\u5de5\u5177"},"content":{"rendered":"<p>KGGen \u662f\u7531\u65af\u5766\u798f\u53ef\u4fe1\u4eba\u5de5\u667a\u80fd\u7814\u7a76\u5b9e\u9a8c\u5ba4\uff08STAIR Lab\uff09\u5f00\u53d1\u7684\u4e00\u6b3e\u5f00\u6e90\u5de5\u5177\uff0c\u6258\u7ba1\u4e8e GitHub\uff0c\u65e8\u5728\u4ece\u4efb\u610f\u6587\u672c\u4e2d\u81ea\u52a8\u751f\u6210\u77e5\u8bc6\u56fe\u8c31\u3002\u5b83\u5229\u7528\u5148\u8fdb\u7684\u8bed\u8a00\u6a21\u578b\u548c\u805a\u7c7b\u7b97\u6cd5\uff0c\u5c06\u975e\u7ed3\u6784\u5316\u7684\u6587\u672c\u6570\u636e\u8f6c\u5316\u4e3a\u7ed3\u6784\u5316\u7684\u5b9e\u4f53\u548c\u5173\u7cfb\u7f51\u7edc\uff0c\u9002\u7528\u4e8e\u7814\u7a76\u4eba\u5458\u3001\u5f00\u53d1\u8005\u548c\u6570\u636e\u5206\u6790\u5e08\u3002\u9879\u76ee\u81ea\u53d1\u5e03\u4ee5\u6765\u53d7\u5230\u5173\u6ce8\uff0c\u56e0\u5176\u5728\u77e5\u8bc6\u63d0\u53d6\u7cbe\u5ea6\u548c\u56fe\u8c31\u8fde\u901a\u6027\u4e0a\u7684\u63d0\u5347\u800c\u5907\u53d7\u597d\u8bc4\u3002KGGen \u7684\u6838\u5fc3\u4f18\u52bf\u5728\u4e8e\u64cd\u4f5c\u7b80\u5355\u3001\u7ed3\u679c\u53ef\u9760\uff0c\u5df2\u88ab\u7528\u4e8e\u5b66\u672f\u7814\u7a76\u548c AI \u5e94\u7528\u5f00\u53d1\uff0c\u6700\u65b0\u66f4\u65b0\u65f6\u95f4\u4e3a 2025 \u5e74 2 \u6708 20 \u65e5\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-26419\" title=\"KG Gen\uff1a\u4ece\u7eaf\u6587\u672c\u4e2d\u81ea\u52a8\u751f\u6210\u77e5\u8bc6\u56fe\u8c31\u7684\u5f00\u6e90\u5de5\u5177-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/44f3a8d3153eac0.jpg\" alt=\"KG Gen\uff1a\u4ece\u7eaf\u6587\u672c\u4e2d\u81ea\u52a8\u751f\u6210\u77e5\u8bc6\u56fe\u8c31\u7684\u5f00\u6e90\u5de5\u5177-1\" width=\"1414\" height=\"646\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/44f3a8d3153eac0.jpg 1414w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/44f3a8d3153eac0-768x351.jpg 768w\" sizes=\"auto, (max-width: 1414px) 100vw, 1414px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>\u529f\u80fd\u5217\u8868<\/h2>\n<ul>\n<li><strong>\u6587\u672c\u5230\u77e5\u8bc6\u56fe\u8c31\u8f6c\u6362<\/strong>\uff1a\u4ece\u4efb\u610f\u6587\u672c\u8f93\u5165\u4e2d\u63d0\u53d6\u5b9e\u4f53\u548c\u5173\u7cfb\uff0c\u751f\u6210\u7ed3\u6784\u5316\u7684\u77e5\u8bc6\u56fe\u8c31\u3002<\/li>\n<li><strong>\u652f\u6301\u591a\u79cd\u8bed\u8a00\u6a21\u578b<\/strong>\uff1a\u96c6\u6210\u4e3b\u6d41\u8bed\u8a00\u6a21\u578b\uff0c\u589e\u5f3a\u6587\u672c\u7406\u89e3\u548c\u7ed3\u6784\u5316\u80fd\u529b\u3002<\/li>\n<li><strong>\u805a\u7c7b\u7b97\u6cd5\u4f18\u5316<\/strong>\uff1a\u901a\u8fc7\u805a\u7c7b\u6280\u672f\u63d0\u5347\u77e5\u8bc6\u56fe\u8c31\u7684\u8fde\u901a\u6027\u548c\u903b\u8f91\u6027\u3002<\/li>\n<li><strong>\u5f00\u6e90\u53ef\u5b9a\u5236<\/strong>\uff1a\u63d0\u4f9b\u5b8c\u6574\u4ee3\u7801\uff0c\u7528\u6237\u53ef\u6839\u636e\u9700\u6c42\u4fee\u6539\u548c\u6269\u5c55\u529f\u80fd\u3002<\/li>\n<li><strong>\u6570\u636e\u5bfc\u51fa<\/strong>\uff1a\u751f\u6210\u7684\u77e5\u8bc6\u56fe\u8c31\u652f\u6301\u591a\u79cd\u683c\u5f0f\u5bfc\u51fa\uff0c\u4fbf\u4e8e\u540e\u7eed\u5206\u6790\u548c\u5e94\u7528\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>\u4f7f\u7528\u5e2e\u52a9<\/h2>\n<h3>\u5b89\u88c5\u6d41\u7a0b<\/h3>\n<p>KGGen \u662f\u4e00\u4e2a\u57fa\u4e8e Python \u7684\u5de5\u5177\uff0c\u90e8\u7f72\u9700\u8981\u4e00\u5b9a\u7684\u7f16\u7a0b\u73af\u5883\u914d\u7f6e\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u7684\u5b89\u88c5\u6b65\u9aa4\uff1a<\/p>\n<h4>1. \u73af\u5883\u51c6\u5907<\/h4>\n<ul>\n<li><strong>\u64cd\u4f5c\u7cfb\u7edf<\/strong>\uff1a\u652f\u6301 Windows\u3001MacOS \u548c Linux\u3002<\/li>\n<li><strong>Python \u7248\u672c<\/strong>\uff1a\u5efa\u8bae\u4f7f\u7528 Python 3.8 \u6216\u4ee5\u4e0a\u3002<\/li>\n<li><strong>Git<\/strong>\uff1a\u786e\u4fdd\u5df2\u5b89\u88c5 Git \u7528\u4e8e\u514b\u9686\u4ee3\u7801\u5e93\u3002<\/li>\n<li><strong>\u4f9d\u8d56\u7ba1\u7406\u5de5\u5177<\/strong>\uff1a\u63a8\u8350\u4f7f\u7528\u00a0<code>pip<\/code>\u00a0\u6216\u00a0<code>conda<\/code>\u3002<\/li>\n<\/ul>\n<h4>2. \u514b\u9686\u4ee3\u7801\u5e93<\/h4>\n<p>\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5c06 KGGen \u9879\u76ee\u514b\u9686\u5230\u672c\u5730\uff1a<\/p>\n<pre><code>git clone https:\/\/github.com\/stair-lab\/kg-gen.git\r\ncd kg-gen\r\n<\/code><\/pre>\n<h4>3. \u5b89\u88c5\u4f9d\u8d56<\/h4>\n<p>\u9879\u76ee\u63d0\u4f9b\u4e86\u4e00\u4e2a\u00a0<code>requirements.txt<\/code>\u00a0\u6587\u4ef6\uff0c\u5305\u542b\u6240\u9700\u4f9d\u8d56\u5e93\u3002\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<pre><code>pip install -r requirements.txt\r\n<\/code><\/pre>\n<p>\u5982\u679c\u4f7f\u7528\u00a0<code>conda<\/code>\uff0c\u53ef\u4ee5\u5148\u521b\u5efa\u4e00\u4e2a\u865a\u62df\u73af\u5883\uff1a<\/p>\n<pre><code>conda create -n kggen python=3.8\r\nconda activate kggen\r\npip install -r requirements.txt\r\n<\/code><\/pre>\n<h4>4. \u9a8c\u8bc1\u5b89\u88c5<\/h4>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u8fdb\u5165 Python \u89e3\u91ca\u5668\uff0c\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\u68c0\u67e5\u662f\u5426\u6210\u529f\uff1a<\/p>\n<pre><code>import kg_gen\r\nprint(kg_gen.__version__)\r\n<\/code><\/pre>\n<p>\u82e5\u8f93\u51fa\u7248\u672c\u53f7\uff08\u5982\u00a0<code>1.0.0<\/code>\uff09\uff0c\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<h3>\u4f7f\u7528\u65b9\u6cd5<\/h3>\n<p>KGGen \u7684\u4e3b\u8981\u529f\u80fd\u662f\u4ece\u6587\u672c\u751f\u6210\u77e5\u8bc6\u56fe\u8c31\uff0c\u4ee5\u4e0b\u662f\u5177\u4f53\u64cd\u4f5c\u6d41\u7a0b\uff1a<\/p>\n<h4>1. \u51c6\u5907\u8f93\u5165\u6587\u672c<\/h4>\n<p>\u521b\u5efa\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff08\u5982\u00a0<code>input.txt<\/code>\uff09\uff0c\u5199\u5165\u9700\u8981\u5904\u7406\u7684\u6587\u672c\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>\u4eba\u5de5\u667a\u80fd\u6b63\u5728\u6539\u53d8\u4e16\u754c\u3002\u673a\u5668\u5b66\u4e60\u662f\u4eba\u5de5\u667a\u80fd\u7684\u6838\u5fc3\u6280\u672f\u3002\u65af\u5766\u798f\u5927\u5b66\u7684\u7814\u7a76\u56e2\u961f\u5f00\u53d1\u4e86\u8bb8\u591a\u521b\u65b0\u5de5\u5177\u3002\r\n<\/code><\/pre>\n<p>\u5c06\u6587\u4ef6\u4fdd\u5b58\u5230\u00a0<code>kg-gen<\/code>\u00a0\u76ee\u5f55\u4e0b\u3002<\/p>\n<h4>2. \u8fd0\u884c KGGen<\/h4>\n<p>\u5728\u7ec8\u7aef\u4e2d\u8fdb\u5165\u9879\u76ee\u76ee\u5f55\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>python -m kg_gen --input input.txt --output graph.json\r\n<\/code><\/pre>\n<ul>\n<li><code>--input<\/code>\uff1a\u6307\u5b9a\u8f93\u5165\u6587\u672c\u6587\u4ef6\u8def\u5f84\u3002<\/li>\n<li><code>--output<\/code>\uff1a\u6307\u5b9a\u751f\u6210\u7684\u77e5\u8bc6\u56fe\u8c31\u8f93\u51fa\u6587\u4ef6\u8def\u5f84\uff08\u652f\u6301 JSON \u683c\u5f0f\uff09\u3002<\/li>\n<\/ul>\n<h4>3. \u67e5\u770b\u7ed3\u679c<\/h4>\n<p>\u8fd0\u884c\u5b8c\u6210\u540e\uff0c\u6253\u5f00\u00a0<code>graph.json<\/code>\uff0c\u4f60\u4f1a\u770b\u5230\u7c7b\u4f3c\u4ee5\u4e0b\u7684\u5185\u5bb9\uff1a<\/p>\n<pre><code>{\r\n\"entities\": [\"\u4eba\u5de5\u667a\u80fd\", \"\u673a\u5668\u5b66\u4e60\", \"\u65af\u5766\u798f\u5927\u5b66\"],\r\n\"relations\": [\r\n{\"source\": \"\u4eba\u5de5\u667a\u80fd\", \"target\": \"\u673a\u5668\u5b66\u4e60\", \"relation\": \"\u5305\u542b\"},\r\n{\"source\": \"\u65af\u5766\u798f\u5927\u5b66\", \"target\": \"\u521b\u65b0\u5de5\u5177\", \"relation\": \"\u5f00\u53d1\"}\r\n]\r\n}\r\n<\/code><\/pre>\n<p>\u8fd9\u8868\u793a KGGen \u4ece\u6587\u672c\u4e2d\u63d0\u53d6\u4e86\u5b9e\u4f53\u5e76\u5efa\u7acb\u4e86\u5173\u7cfb\u3002<\/p>\n<h4>4. \u81ea\u5b9a\u4e49\u914d\u7f6e\uff08\u53ef\u9009\uff09<\/h4>\n<p>KGGen \u652f\u6301\u8c03\u6574\u53c2\u6570\u4ee5\u4f18\u5316\u7ed3\u679c\u3002\u7f16\u8f91\u00a0<code>config.py<\/code>\u00a0\u6587\u4ef6\uff08\u82e5\u6709\uff09\uff0c\u53ef\u4fee\u6539\uff1a<\/p>\n<ul>\n<li><strong>\u8bed\u8a00\u6a21\u578b<\/strong>\uff1a\u66f4\u6362\u4e3a\u5176\u4ed6\u9884\u8bad\u7ec3\u6a21\u578b\uff08\u5982 BERT\uff09\u3002<\/li>\n<li><strong>\u805a\u7c7b\u53c2\u6570<\/strong>\uff1a\u8c03\u6574\u805a\u7c7b\u9608\u503c\u4ee5\u6539\u53d8\u56fe\u8c31\u5bc6\u5ea6\u3002<br \/>\n\u4fee\u6539\u540e\u4fdd\u5b58\u5e76\u91cd\u65b0\u8fd0\u884c\u4e0a\u8ff0\u547d\u4ee4\u3002<\/li>\n<\/ul>\n<h3>\u7279\u8272\u529f\u80fd\u64cd\u4f5c<\/h3>\n<h4><strong>\u6279\u91cf\u5904\u7406\u591a\u6587\u4ef6<\/strong><\/h4>\n<p>\u82e5\u9700\u5904\u7406\u591a\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u53ef\u4f7f\u7528\u811a\u672c\u5faa\u73af\u8c03\u7528\uff1a<\/p>\n<pre><code>for file in *.txt; do python -m kg_gen --input \"$file\" --output \"${file%.txt}.json\"; done\r\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u4e3a\u6bcf\u4e2a\u00a0<code>.txt<\/code>\u00a0\u6587\u4ef6\u751f\u6210\u5bf9\u5e94\u7684\u00a0<code>.json<\/code>\u00a0\u56fe\u8c31\u6587\u4ef6\u3002<\/p>\n<h4><strong>\u53ef\u89c6\u5316\u77e5\u8bc6\u56fe\u8c31<\/strong><\/h4>\n<p>KGGen \u672a\u5185\u7f6e\u53ef\u89c6\u5316\u5de5\u5177\uff0c\u4f46\u4f60\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\uff08\u5982\u00a0<code>networkx<\/code>\u00a0\u548c\u00a0<code>matplotlib<\/code>\uff09\u7ed8\u5236\u56fe\u8c31\uff1a<\/p>\n<ol>\n<li>\u5b89\u88c5\u4f9d\u8d56\uff1a<\/li>\n<\/ol>\n<pre><code>pip install networkx matplotlib\r\n<\/code><\/pre>\n<ol start=\"2\">\n<li>\u7f16\u5199\u4ee5\u4e0b Python \u811a\u672c\uff08<code>visualize.py<\/code>\uff09\uff1a<\/li>\n<\/ol>\n<pre><code>import json\r\nimport networkx as nx\r\nimport matplotlib.pyplot as plt\r\nwith open('graph.json', 'r') as f:\r\ndata = json.load(f)\r\nG = nx.DiGraph()\r\nfor rel in data['relations']:\r\nG.add_edge(rel['source'], rel['target'], label=rel['relation'])\r\npos = nx.spring_layout(G)\r\nnx.draw(G, pos, with_labels=True, node_color='lightblue', font_size=10)\r\nedge_labels = nx.get_edge_attributes(G, 'label')\r\nnx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)\r\nplt.show()\r\n<\/code><\/pre>\n<ol start=\"3\">\n<li>\u8fd0\u884c\u811a\u672c\uff1a<\/li>\n<\/ol>\n<pre><code>python visualize.py\r\n<\/code><\/pre>\n<p>\u5373\u53ef\u770b\u5230\u751f\u6210\u7684\u77e5\u8bc6\u56fe\u8c31\u56fe\u5f62\u3002<\/p>\n<h4><strong>\u8c03\u8bd5\u4e0e\u65e5\u5fd7<\/strong><\/h4>\n<p>\u82e5\u751f\u6210\u7ed3\u679c\u4e0d\u7b26\u5408\u9884\u671f\uff0c\u53ef\u542f\u7528\u8c03\u8bd5\u6a21\u5f0f\uff1a<\/p>\n<pre><code>python -m kg_gen --input input.txt --output graph.json --verbose\r\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u8f93\u51fa\u8be6\u7ec6\u65e5\u5fd7\uff0c\u5e2e\u52a9\u5b9a\u4f4d\u95ee\u9898\u3002<\/p>\n<h3>\u6ce8\u610f\u4e8b\u9879<\/h3>\n<ul>\n<li><strong>\u6587\u672c\u8d28\u91cf<\/strong>\uff1a\u8f93\u5165\u6587\u672c\u8d8a\u6e05\u6670\uff0c\u751f\u6210\u7684\u56fe\u8c31\u8d8a\u51c6\u786e\u3002<\/li>\n<li><strong>\u8ba1\u7b97\u8d44\u6e90<\/strong>\uff1a\u5904\u7406\u957f\u6587\u672c\u53ef\u80fd\u9700\u8981\u8f83\u9ad8\u5185\u5b58\uff0c\u5efa\u8bae\u81f3\u5c11 8GB RAM\u3002<\/li>\n<li><strong>\u66f4\u65b0\u7ef4\u62a4<\/strong>\uff1a\u5b9a\u671f\u68c0\u67e5 GitHub \u4ed3\u5e93\uff0c\u786e\u4fdd\u4f7f\u7528\u6700\u65b0\u7248\u672c\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u4e0a\u624b KGGen\uff0c\u4ece\u6587\u672c\u4e2d\u63d0\u53d6\u7ed3\u6784\u5316\u77e5\u8bc6\u5e76\u5e94\u7528\u4e8e\u5b9e\u9645\u9879\u76ee\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>KGGen \u662f\u7531\u65af\u5766\u798f\u53ef\u4fe1\u4eba\u5de5\u667a\u80fd\u7814\u7a76\u5b9e\u9a8c\u5ba4\uff08STAIR Lab\uff09\u5f00\u53d1\u7684\u4e00\u6b3e\u5f00\u6e90\u5de5\u5177\uff0c\u6258\u7ba1\u4e8e GitHub\uff0c\u65e8\u5728\u4ece\u4efb\u610f\u6587\u672c\u4e2d\u81ea\u52a8\u751f\u6210\u77e5\u8bc6\u56fe\u8c31\u3002\u5b83\u5229\u7528\u5148\u8fdb\u7684\u8bed\u8a00\u6a21\u578b\u548c\u805a\u7c7b\u7b97\u6cd5\uff0c\u5c06\u975e\u7ed3\u6784\u5316\u7684\u6587\u672c\u6570\u636e\u8f6c\u5316\u4e3a\u7ed3\u6784\u5316\u7684\u5b9e\u4f53\u548c\u5173\u7cfb\u7f51\u7edc\uff0c\u9002\u7528\u4e8e\u7814\u7a76\u4eba\u5458\u3001&#8230;<\/p>\n","protected":false},"author":1,"featured_media":61889,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[230,260],"class_list":["post-26418","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tool","tag-aikaiyuanxiangmu","tag-zhishitupu"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts\/26418","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/comments?post=26418"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts\/26418\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/media\/61889"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/media?parent=26418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/categories?post=26418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/tags?post=26418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}