{"id":13605313,"url":"https://github.com/KRR-Oxford/GNNQ","last_synced_at":"2025-04-12T05:32:27.658Z","repository":{"id":94600785,"uuid":"381132247","full_name":"KRR-Oxford/GNNQ","owner":"KRR-Oxford","description":null,"archived":false,"fork":false,"pushed_at":"2022-08-11T23:08:54.000Z","size":246,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-29T11:50:26.827Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KRR-Oxford.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-06-28T18:52:05.000Z","updated_at":"2023-07-05T08:11:10.000Z","dependencies_parsed_at":"2023-03-16T13:45:36.290Z","dependency_job_id":null,"html_url":"https://github.com/KRR-Oxford/GNNQ","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KRR-Oxford%2FGNNQ","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KRR-Oxford%2FGNNQ/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KRR-Oxford%2FGNNQ/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KRR-Oxford%2FGNNQ/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KRR-Oxford","download_url":"https://codeload.github.com/KRR-Oxford/GNNQ/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223497741,"owners_count":17155199,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T19:00:57.301Z","updated_at":"2024-11-07T10:30:24.055Z","avatar_url":"https://github.com/KRR-Oxford.png","language":"Python","funding_links":[],"categories":[":wrench: Implementations"],"sub_categories":["Dataset tools"],"readme":"# GNNQ: A Neuro-Symbolic Approach to Query Answering over Incomplete Knowledge Graphs\n\n### About\nThe GNNQ repository contains the source code for the GNNQ system presented in the paper [GNNQ: A Neuro-Symbolic Approach to Query Answering over Incomplete Knowledge Graphs](https://portal.sds.ox.ac.uk/ndownloader/files/36649044) accepted to ISWC22. \n\nGNNQ is a neuro-symbolic system to answer monadic tree-like conjunctive queries over incomplete KGs. GNNQ ﬁrst symbolically augments an input KG (formally a set of facts) with additional facts representing subsets matching connected query fragments, and then applies a generalisation of the Relational Graph Convolutional Networks (RGCNs) model to the augmented KG to produce the predicted query answers.\n\n### Source Code\nClone the GNNQ repository.\n\n` git clone https://github.com/KRR-Oxford/GNNQ.git ` or ` git clone git@github.com:KRR-Oxford/GNNQ.git `\n\n### Requirements\nWe assume that the following is pre-installed. We used the respective versions specified in brackets.\n- python (3.8.10 or higher)\n- pip (19.2.3 or higher)\n- venv\n\nInstructions for the installation of the requirements can be found [here](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/).\n\nPlease follow the steps outlined below to reproduce the experiments.\n\n### Dependencies\nTo install all dependencies required for our experiments follow the instructions below:\n- Navigate to the `GNNQ/` directory. \\\n```cd path/to/download/GNNQ```\n- Create a virtual environment. \\\n```python -m venv env```\n- Start virtual environment. \\\n```source env/bin/activate```\n- Install PyTorch. Replace `${CUDA}` with `cpu` or `cu113`. \\\n```pip install torch==1.11.0+${CUDA}  --extra-index-url https://download.pytorch.org/whl/${CUDA}```\n- Install PyTorch Scatter. Replace `${CUDA}` with `cpu` or `cu113`. \\\n```pip install torch-scatter -f https://data.pyg.org/whl/torch-1.11.0+${CUDA}.html```\n- Install all other dependencies. \\\n```pip install -r requirements.txt```\n\n### Datasets\nThe `datasets/` directory, containing both the WatDiv-Qi and the FB15k237-Qi benchmarks, can be downloaded from here (https://portal.sds.ox.ac.uk/ndownloader/files/36445044). Unzip the downloaded .zip-file and place the `datasets/` directory in the `GNNQ/` directory.\n\n### Run Experiments\nTo train and evaluate a 4-layer GNNQ instance on the WatDiv-Q1 benchmark run the following command from the GNNQ folder. Please remember that the virtual environment needs to be active. \n```\npython main.py  --log_dir watdiv_q1_4l_aug/ --num_layers 4 --aug --test --train_data datasets/watdiv/train_samples --val_data datasets/watdiv/val_samples --test_data datasets/watdiv/test_samples --query_string \"SELECT distinct ?v0 WHERE { ?v0  \u003chttp://schema.org/caption\u003e ?v1 . ?v0   \u003chttp://schema.org/text\u003e ?v2 . ?v0 \u003chttp://schema.org/contentRating\u003e ?v3 . ?v0   \u003chttp://purl.org/stuff/rev#hasReview\u003e ?v4 .  ?v4 \u003chttp://purl.org/stuff/rev#title\u003e ?v5 . ?v4  \u003chttp://purl.org/stuff/rev#reviewer\u003e ?v6 . ?v7 \u003chttp://schema.org/actor\u003e ?v6 . ?v7 \u003chttp://schema.org/language\u003e ?v8  }\" \n```\n\nTo train and evaluate an instance on other WatDiv benchmarks exchange the query specified by the `--query_string` parameter and specify a new logging directory using the `--log_dir` parameter. All benchmark queries can be found in the `datasets/benchmark_queries.txt`- file. To train and evaluate a 4-layer GNNQ\u003csup\u003e-\u003c/sup\u003e (baseline), remove the `--aug` parameter. The number of layers for all models can be specified using the `--num_layers`parameter.\n\nTo train and evaluate a 4-layer GNNQ instance on the FB15k237-Q1 benchmark run the following command from the GNNQ folder. Please remember again that the virtual environment needs to be active.\n\n```\npython main.py  --log_dir fb15k237_q1_4l_aug/ --num_layers 4 --aug --test --batch_size 40 --train_data  datasets/fb15k237/org_train_samples --val_data datasets/fb15k237/org_val_samples --test_data datasets/fb15k237/org_test_samples --query_string \"select distinct ?org where { ?org \u003chttp://dummyrel.com/organization/organization/headquarters./location/mailing_address/state_province_region\u003e ?region . ?biggerregion \u003chttp://dummyrel.com/location/location/contains\u003e ?region . ?biggerregion \u003chttp://dummyrel.com/location/location/adjoin_s./location/adjoining_relationship/adjoins\u003e ?neighbourregion . ?biggerregion \u003chttp://dummyrel.com/location/country/capital\u003e ?capital . ?neighbourregion \u003chttp://dummyrel.com/location/country/official_language\u003e ?lang . ?capital \u003chttp://dummyrel.com/common/topic/webpage./common/webpage/category\u003e ?category . ?capital \u003chttp://dummyrel.com/travel/travel_destination/climate./travel/travel_destination_monthly_climate/month\u003e ?month }\"  \n```\nTo train and evaluate a 4-layer GNNQ instance on the other FB15k237-Qi benchmarks, exchange the query specified by the `--query_string` parameter and specify the training, validation and testing samples for the respective query using the `--train_data`, `--val_data` and `--test_data` parameters (the sample files for the FB15k237 benchmarks are named with the answer variable of the respective query). All benchmark queries can be found in the `datasets/benchmark_queries.txt`-file and all samples can be found in the `datasets/fb15k237/` directory. Furthermore, specify a new logging directory using the `--log_dir` parameter. To train and evaluate a 4-layer GNNQ\u003csup\u003e-\u003c/sup\u003e (baseline), remove the `--aug` parameter. The number of layers for all models can be specified using the `--num_layers`parameter.\n\n\n\n### Hyperparameter Tuning and Training with GPU:\nTo tune hyperparameters for a benchmark use the `--tune` parameter. This will start an Optuna study with 100 trials. If you installed PyTorch and PyTorch-Scatter with Cuda, i.e. you replaced `${CUDA}` with `cu113`, you can use the `--gpu` parameter to train an instance on an available GPU.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKRR-Oxford%2FGNNQ","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKRR-Oxford%2FGNNQ","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKRR-Oxford%2FGNNQ/lists"}