Prakhar Bhandari commited on
Commit ·
0beb8e1
1
Parent(s): b77d203
updated prompt and function for traffic law wiki
Browse filesFiles changed (6)
- kg_builder/src/__pycache__/api_connections.cpython-39.pyc
- kg_builder/src/__pycache__/knowledge_graph_builder.cpython-39.pyc
- kg_builder/src/__pycache__/models.cpython-39.pyc
- kg_builder/src/__pycache__/utils.cpython-39.pyc
- kg_builder/src/api_connections.py+62-2
- kg_builder/src/knowledge_graph_builder.py+1-1
39 unmodified lines4041424344454647484939 unmodified lines):if category == "Chemotherapy":# Chemotherapy-specific promptprompt_text = ""elif category == "Traffic Law":# Traffic Law-specific promptprompt_text = "[Traffic Law-specific instructions]"else:raise ValueError("Unknown category")39 unmodified lines40414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810939 unmodified lines):if category == "Chemotherapy":# Chemotherapy-specific promptprompt_text = f"""# Knowledge Graph Instructions for GPT-4## 1. OverviewYou are a sophisticated algorithm tailored for parsing Wikipedia pages to construct a knowledge graph about chemotherapy and related cancer treatments.- **Nodes** symbolize entities such as medical conditions, drugs, symptoms, treatments, and associated medical concepts.- The goal is to create a precise and comprehensible knowledge graph, serving as a reliable resource for medical practitioners and scholarly research.## 2. Labeling Nodes- **Consistency**: Utilize uniform labels for node types to maintain clarity.- For instance, consistently label drugs as **"Drug"**, symptoms as **"Symptom"**, and treatments as **"Treatment"**.- **Node IDs**: Apply descriptive, legible identifiers for node IDs, sourced directly from the text.{'- **Allowed Node Labels:**' + ", ".join(['Drug', 'Symptom', 'Treatment', 'MedicalCondition', 'ResearchStudy']) if allowed_nodes else ""}{'- **Allowed Relationship Types**:' + ", ".join(['Treats', 'Causes', 'Researches', 'Recommends']) if allowed_rels else ""}## 3. Handling Numerical Data and Dates- Integrate numerical data and dates as attributes of the corresponding nodes.- **No Isolated Nodes for Dates/Numbers**: Directly associate dates and numerical figures as attributes with pertinent nodes.- **Property Format**: Follow a straightforward key-value pattern for properties, with keys in camelCase, for example, `approvedYear`, `dosageAmount`.## 4. Coreference Resolution- **Entity Consistency**: Guarantee uniform identification of each entity across the graph.- For example, if "Methotrexate" and "MTX" reference the same medication, uniformly apply "Methotrexate" as the node ID.## 5. Relationship Naming Conventions- **Clarity and Standardization**: Utilize clear and standardized relationship names, preferring uppercase with underscores for readability.- For instance, use "HAS_SIDE_EFFECT" instead of "HASSIDEEFFECT", use "CAN_RESULT_FROM" instead of "CANRESULTFROM" etc. You keep making the same mistakes of storing the relationships without the "_" in between the words. Any further similar errors will lead to termination.- **Relevance and Specificity**: Choose relationship names that accurately reflect the connection between nodes, such as "INHIBITS" or "ACTIVATES" for interactions between substances.## 6. Strict ComplianceRigorous adherence to these instructions is essential. Failure to comply with the specified formatting and labeling norms will necessitate output revision or discard."""elif category == "Traffic Law":# Traffic Law-specific promptprompt_text = f"""# Knowledge Graph Instructions for GPT-4## 1. OverviewYou are a sophisticated algorithm tailored for parsing Wikipedia pages to construct a knowledge graph about traffic laws and regulations in the United States.- **Nodes** symbolize entities such as types of traffic violations, penalties, driving regulations, and relevant legal statutes.- The goal is to create a precise and comprehensible knowledge graph, serving as a reliable resource for legal professionals, law enforcement agencies, and the general public.## 2. Labeling Nodes- **Consistency**: Utilize uniform labels for node types to maintain clarity.- For instance, consistently label violations as **"Violation"**, penalties as **"Penalty"**, and statutes as **"Statute"**.- **Node IDs**: Apply descriptive, legible identifiers for node IDs, sourced directly from the text.{'- **Allowed Node Labels:**' + ", ".join(['Violation', 'Penalty', 'Statute', 'VehicleType', 'LegalDocument']) if allowed_nodes else ""}{'- **Allowed Relationship Types**:' + ", ".join(['Violates', 'Penalizes', 'Governs', 'Cites']) if allowed_rels else ""}## 3. Handling Numerical Data and Dates- Integrate numerical data and dates as attributes of the corresponding nodes.- **No Isolated Nodes for Dates/Numbers**: Directly associate dates and numerical figures as attributes with pertinent nodes.- **Property Format**: Follow a straightforward key-value pattern for properties, with keys in camelCase, for example, `fineAmount`, `lawEffectiveDate`.## 4. Coreference Resolution- **Entity Consistency**: Guarantee uniform identification of each entity across the graph.- For example, if "Vehicle Code 22350" and "Speed Law" reference the same statute, uniformly apply "Vehicle Code 22350" as the node ID.## 5. Relationship Naming Conventions- **Clarity and Standardization**: Utilize clear and standardized relationship names, preferring uppercase with underscores for readability.- For instance, use "IS_PENALIZED_BY" instead of "ISPENALIZEDBY", use "IS_GOVERNED_BY" instead of "ISGOVERNEDBY" etc. You keep making the same mistakes of storing the relationships without the "_" in between the words. Any further similar errors will lead to termination.- **Relevance and Specificity**: Choose relationship names that accurately reflect the connection between nodes, such as "REQUIRES" or "PROHIBITS" for legal requirements or prohibitions.## 6. Strict ComplianceRigorous adherence to these instructions is essential. Failure to comply with the specified formatting and labeling norms will necessitate output revision or discard."""else:raise ValueError("Unknown category")
27 unmodified lines2829303132333427 unmodified linesgraph = get_graph_connection(category)# Extract graph data using OpenAI functionsextract_chain = get_extraction_chain(nodes, rels)data = extract_chain.invoke(document.page_content)['function']# Construct a graph documentgraph_document = GraphDocument(27 unmodified lines2829303132333427 unmodified linesgraph = get_graph_connection(category)# Extract graph data using OpenAI functionsextract_chain = get_extraction_chain(category, nodes, rels)data = extract_chain.invoke(document.page_content)['function']# Construct a graph documentgraph_document = GraphDocument(
kg_builder/src/__pycache__/api_connections.cpython-39.pyc
kg_builder/src/__pycache__/knowledge_graph_builder.cpython-39.pyc
kg_builder/src/__pycache__/models.cpython-39.pyc
kg_builder/src/__pycache__/utils.cpython-39.pyc
kg_builder/src/api_connections.py+62-2
kg_builder/src/knowledge_graph_builder.py+1-1