Skip to main content

Extract a knowledge graph with LLM from texts and perform QA over the resulted KG

Project description

Wikontic logo

Wikontic

Build ontology-aware, Wikidata-aligned knowledge graphs from raw text using LLMs


🚀 Overview

Knowledge Graphs (KGs) provide structured, verifiable representations of knowledge, enabling fact grounding and empowering large language models (LLMs) with up-to-date, real-world information. However, creating high-quality KGs from open-domain text is challenging due to issues like redundancy, inconsistency, and lack of alignment with formal ontologies.

Wikontic is a multi-stage pipeline for constructing ontology-aligned KGs from unstructured text using LLMs and Wikidata. It extracts candidate triples from raw text, then refines them through ontology-based typing, schema validation, and entity deduplication—resulting in compact, semantically coherent graphs.


📁 Repository Structure

  • preprocessing/constraint-preprocessing.ipynb
    Jupyter notebook for collecting constraint rules from Wikidata.

  • utils/
    Utilities for LLM-based triple extraction and alignment with Wikidata ontology rules.

  • utils/openai_utils.py
    LLMTripletExtractor class for LLM-based triple extraction.

To use ontology:

  • utils/ontology_mappings/
    JSON files containing ontology mappings from Wikidata.

  • utils/structured_inference_with_db.py

    • StructuredInferenceWithDB class: triple extraction and qa functions
  • utils/structured_aligner.py

    • Aligner class: ontology alignment and entity name refinement

Not to use ontology:

  • utils/inference_with_db.py

    • InferenceWithDB class: triple extraction and qa functions
  • utils/dynamic_aligner.py

    • Aligner class: entity and relation name refinement

Evaluation:

  • inference_and_eval/
    • Scripts for building KGs for MuSiQue and HotPot datasets and evaluation of QA performance
  • analysis/
    • Notebooks with downstream analysis of the resulted KG

Use Wikontic as a service:

  • pages/ and Wikontic.py
    Code for the web service for knowledge graph extraction and visualization.

  • Dockerfile
    For building a containerized web service.


🏁 Getting Started

  1. Set up the ontology and KG databases:

    ./setup_db.sh
    
  2. Launch the web service:

    streamlit run Wikontic.py
    

Enjoy building knowledge graphs with Wikontic!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wikontic-0.0.5.tar.gz (748.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wikontic-0.0.5-py3-none-any.whl (780.3 kB view details)

Uploaded Python 3

File details

Details for the file wikontic-0.0.5.tar.gz.

File metadata

  • Download URL: wikontic-0.0.5.tar.gz
  • Upload date:
  • Size: 748.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for wikontic-0.0.5.tar.gz
Algorithm Hash digest
SHA256 dbc13ee9f330857ebb34b8d8819d5f3aa15bf76575d079bf39fb26b949bcccb9
MD5 0b174c44a68459489336b86f459833e7
BLAKE2b-256 7b81a870da111255a6973ed871d0621e05beb1a13f4c60d6df2db45380a1118b

See more details on using hashes here.

File details

Details for the file wikontic-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: wikontic-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 780.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for wikontic-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 be2c143a76f68e38ffd5a277a48cb3e34c95115842828a5f753e23e714515ab3
MD5 f579468b325a7f6c742a9d8ec082c0c5
BLAKE2b-256 0fc5a901f3143ba79f36938aa865ce5d5b238c149d51b85b1ab8d9a28cfdfb80

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page