Replies: 2 comments 5 replies
-
@MRgsj 🌟 Hello there! I'm here to help you with bugs, questions, and becoming a contributor. Let's tackle this together! To get the node and relationship types in Chinese when using from langchain_experimental.graph_transformers import LLMGraphTransformer
from langchain_core.documents import Document
from langchain_openai import ChatOpenAI
# Initialize the language model
zhipuai_chat = ChatZhipuAI(model_name="glm-4",
api_key="dbb23f5e10ad26571ceee87d64d3c856.jacZLN0tPXzFNzrW",
system_message="请用中文回答",
temperature=0)
# Define the transformer with Chinese node and relationship types
llm_transformer = LLMGraphTransformer(
llm=zhipuai_chat,
allowed_nodes=["地点", "神", "种族", "物品", "灾难", "树"], # Node types in Chinese
allowed_relationships=["位于", "种植", "造成", "毁坏", "尝试复活", "被复活", "被污染", "净化", "用于净化"] # Relationship types in Chinese
)
# Example text in Chinese
text = """
尤格-萨隆这个名字最早被提起是在灰熊丘陵,这里有一棵已经枯萎的世界之树沃达希尔。有熊怪会告诉冒险者,在远古时期暗夜精灵德鲁伊栽种了这棵世界之树,但是由于根须扎得太深,
甚至达到了古神尤格-萨隆的巢穴。古神的黑暗力量开始泄露,那些暗夜精灵德鲁伊害怕沃达希尔会造成巨大的灾难,于是就将这棵世界之树毁掉了。在《巫妖王之怒》中,一些住在附近的熊怪又开始重新将断成三段的沃达希尔栽种,
并打算复活在上古之战牺牲的巨熊之神乌索克,最终乌索克被熊怪们复活了,可是已经被古神污染了。在冒险者和曾经帮助复活乌索克的木喉熊怪的帮助下,一名德鲁伊最终依靠净化过的沃达希尔之尘净化了乌索克。
"""
# Convert the text to graph documents
documents = [Document(page_content=text)]
graph_documents = llm_transformer.convert_to_graph_documents(documents)
# Print the nodes and relationships
print(f"Nodes: {graph_documents[0].nodes}")
print(f"Relationships: {graph_documents[0].relationships}") In this example, the node types are specified as "地点" (Location), "神" (God), "种族" (Race), "物品" (Item), "灾难" (Disaster), and "树" (Tree). The relationship types are specified as "位于" (located in), "种植" (planted), "造成" (causes), "毁坏" (destroyed), "尝试复活" (attempted revival), "被复活" (was revived by), "被污染" (was contaminated by), "净化" (purified), and "用于净化" (used for purification). Adjust these values according to the specific Chinese terms you need for your knowledge graph [1]. |
Beta Was this translation helpful? Give feedback.
-
you can change the source code of prompt in LLMGraphTransformer |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
I want to get a KG as chinese but i get as follow:
Nodes:[Node(id='灰熊丘陵', type='Location'), Node(id='古神', type='God'), Node(id='尤格-萨隆', type='God'), Node(id='德鲁伊', type='Race'), Node(id='熊怪', type='Race'), Node(id='暗夜精灵德鲁伊', type='Race'), Node(id='乌索克', type='God'), Node(id='沃达希尔之尘', type='Item'), Node(id='巨大的灾难', type='Disaster'), Node(id='沃达希尔', type='Tree')]
Relationships:[Relationship(source=Node(id='尤格-萨隆', type='God'), target=Node(id='灰熊丘陵', type='Location'), type='LIVES_IN'), Relationship(source=Node(id='沃达希尔', type='Tree'), target=Node(id='灰熊丘陵', type='Location'), type='LOCATED_IN'), Relationship(source=Node(id='暗夜精灵德鲁伊', type='Race'), target=Node(id='沃达希尔', type='Tree'), type='PLANTED'), Relationship(source=Node(id='沃达希尔', type='Tree'), target=Node(id='巨大的灾难', type='Disaster'), type='CAUSES'), Relationship(source=Node(id='暗夜精灵德鲁伊', type='Race'), target=Node(id='沃达希尔', type='Tree'), type='DESTROYED'), Relationship(source=Node(id='熊怪', type='Race'), target=Node(id='乌索克', type='God'), type='ATTEMPTED_REVIVAL'), Relationship(source=Node(id='乌索克', type='God'), target=Node(id='熊怪', type='Race'), type='WAS_REVIVED_BY'), Relationship(source=Node(id='乌索克', type='God'), target=Node(id='古神', type='God'), type='WAS_CONTAMINATED_BY'), Relationship(source=Node(id='德鲁伊', type='Race'), target=Node(id='乌索克', type='God'), type='PURIFIED'), Relationship(source=Node(id='沃达希尔之尘', type='Item'), target=Node(id='乌索克', type='God'), type='USED_FOR_PURIFICATION')]
the type is written as english, so how can i get it as chinese?
thank.
System Info
ubuntu20.04
Beta Was this translation helpful? Give feedback.
All reactions