Slide 46
Slide 46 text
LLMを使ってTextからグラフ要素を抽出
LLMGraphTransformer.convert_to_graph_documents()
convert_to_graph_ducments() (process_response()) の関数を使いTextをグラフの要素に変換する。
46 Copyright © 2024, Oracle and/or its affiliates
Document GraphDocuments
llm_transformer = LLMGraphTransformer(
llm=llm,
allowed_nodes=["Person", "Place", "Role"],
allowed_relationships=["Retainer", "Resides_at", "Had_role"]
)
text = """
織田 信長(おだ のぶなが)は、日本の戦国時代から安土桃山時代にかけての武将・大名。戦国の
三英傑の一人。
…
しかし、近年の歴史学界ではその政策の前時代性が指摘されるようになり、しばしば「中世社会の最
終段階」とも評され[2]、その革新性を否定する研究が主流となっている
"""
documents = [Document(page_content=text)]
graph_documents = llm_transformer.convert_to_graph_documents(documents)
print(graph_documents)
[GraphDocument(
nodes=[
Node(id='織田信長', type='Person', properties={}),
Node(id='豊臣秀吉', type='Person', properties={}),
…
Node(id='徳川家康', type='Person', properties={})
],
relationships=[
Relationship(
source=Node(id='織田信長', type='Person', properties={}),
target=Node(id='尾張国', type='Place', properties={}),
type='RESIDES_AT', properties={}),
…
Relationship(
source=Node(id='織田信長', type='Person', properties={}),
target=Node(id='豊臣秀吉', type='Person', properties={}),
type='RETAINER', properties={}), ],
source=Document(metadata={}, page_content='織田 信長(おだ のぶな
が)は、日本の戦国時代から安土桃山時代にかけての武将・大名
…
研究が主流となっている')
# Result