This repository implements Quantum Embedding from "Quantum embedding of knowledge for reasoning.", a paper published in NerurlISP 2019 on RiceDO and TreatO. The code in this repo is based on the original implementation of the paper's authors repo and pykeen implementation for RiceDO and TreatO.
-
Download both datasets
RiceDO
andTreatO
. Then, put them inricedo/data
,treato/data
and rename themRiceDO-Version2.owl
andTreatO-Version2.owl
respectively. -
Install python environment. We tested on only python 3.12.3 on Windows 11, if you want to use other version, do it on your own risk. You can install every using
conda
. The code will use CUDA automatically if you have torch with cuda install. However, we only tested on CPU only.conda env create -f env.yml conda activate e2r
There might be chances that some package won't install on other OS (such as windows API) or worse the packages didn't register in conda registry. You can try install python 3.12.3 and install packages on your own using pip. Note 16/7/2024: pykeen 1.10.2 cannot run with numpy 2.0.0 (its pretty new at the moment). So, i add specification for numpy (==1.26.4).
conda create -n e2r python=3.12.3 conda activate e2r pip install numpy==1.26.4 pandas matplotlib tdqm owlready # for install pytorch (version 2.2.1), each device has its own way. Seek help here https://pytorch.org/ # Then install pykeen later pip install pykeen
-
Parse and Spliting data.
This step will parse
.owl
file into 3.tsv
filestrain.tsv
,validate.tsv
, andtest.tsv
For RiceDO
cd ricedo/data python parse_and_split_data.py cd ../..
For TreatO
cd treato/data python parse_and_split_data.py cd ../..
-
After this if you want to use any dataset, move your terminal to the dataset you want to work with (either
ricedo
ortreato
).cd ricedo # cd treato
Make sure you move your terminal inside the dataset folder and finished all previous steps.
You can setup the hyperparameters of QE in the reasonE.train.py
file. Then, you can train for QE using this command.
python reasonE.train.py
After training, make sure you adjust the hyperparameters in the reasonE.test.py
. You can evaluate created embedding using this command.
python reasonE.test.py
This command will generate the plot of embedding that I investigate on.
python plot_embedding.py
The command below will generate embedding in numerious methods using pykeen.
python trainpykeen.py