- 准备一份包含对比关系的财务报表,或其他领域的数据集。
- 利用ChatGLM3,从数据集中抽取关键实体、属性及它们之间的关系,进而构建财务报表的知识图谱。
通过构建知识图谱,可以更加直观地表示和理解财务报表中复杂知识和关系,为后续智能问答等应用奠定基础。
首先获取查询问题的最近似段落:
import json
file_name = "./dataset/2021年度报告.txt"
with open(file_name,encoding="utf-8") as f:
financial_report = f.read()
financial_report = financial_report.strip().split("\n")
context = ""
for line in financial_report:
line = json.loads(line)
if line["type"] == "text":
try:
con = line["inside"]
context += con
except:
pass
document = context[:480]
然后对文本进行知识图谱抽取:
from langchain_community.graphs.index_creator import GraphIndexCreator
from LLM_Server import ChatGLM
llm = ChatGLM()
index_creator = GraphIndexCreator(llm=llm)
graph = index_creator.from_text(document)
print(graph.get_triples())
打印结果如图: