The steps to generate a knowledge graph using KGGen are as follows:
1. Preparation of input text
Create a plain text file (e.g.input.txt), content examples:
人工智能正在改变世界。机器学习是人工智能的核心技术。斯坦福大学的研究团队开发了许多创新工具。
2. Execution of conversion orders
Run it in the project directory:
python -m kg_gen --input input.txt --output graph.json
Among them:
--input: Specify the path to a text file--output: Define the output JSON file path
3. Parsing the output
generatedgraph.jsonContains structured data, examples:
{
"entities": ["人工智能", "机器学习", "斯坦福大学"],
"relations": [
{"source": "人工智能", "target": "机器学习", "relation": "包含"},
{"source": "斯坦福大学", "target": "创新工具", "relation": "开发"}
]
}
4. (Optional) Advanced configuration
- modifications
config.pySwitching Language Models or Adjusting Clustering Thresholds - Batch processing can be recursively invoked using a shell script
- increase
--verboseParameters to enable debug logging
Tip: The semantic clarity of the input text directly affects the quality of the mapping, so it is recommended to perform the necessary data cleaning first.
This answer comes from the articleKG Gen: an open source tool for automatic knowledge graph generation from plain textThe





























