Home

Awesome

Knowledge Base Completion (kbc)

This code reproduces results in Canonical Tensor Decomposition for Knowledge Base Completion (ICML 2018).

Installation

Create a conda environment with pytorch cython and scikit-learn :

conda create --name kbc_env python=3.7
source activate kbc_env
conda install --file requirements.txt -c pytorch

Then install the kbc package to this environment

python setup.py install

Datasets

To download the datasets, go to the kbc/scripts folder and run:

chmod +x download_data.sh
./download_data.sh

Once the datasets are download, add them to the package data folder by running :

python kbc/process_datasets.py

This will create the files required to compute the filtered metrics.

Running the code

Reproduce the results below with the following command :

python kbc/learn.py --dataset FB15K --model ComplEx --rank 500 --optimizer
Adagrad --learning_rate 1e-1 --batch_size 1000 --regularizer N3 --reg 1e-2
 --max_epochs 100 --valid 5

Results

In addition to the results in the paper, here are the performances of ComplEx regularized with the weighted N3 on several datasets, for several dimensions. We use an init scale of 1e-3, a learning rate of 0.1, a batch size of 1000 and 100 max epochs unless specified otherwise. We use the Adagrad optimizer.

FB15k

For rank 2000 : learning rate 1e-2, batch-size 100, max epochs 200.

rank525501005002000
MRR0.360.610.780.830.840.86
H@10.270.520.730.790.800.83
H@30.410.670.810.850.870.87
H@100.550.770.860.890.910.91
reg1e-51e-51e-57.5e-41e-22.5e-3
#Params163k815k1.630M3.259M1.630M65.184M

WN18

Max Epochs : 20

rank581625501005002000
MRR0.190.450.920.940.950.950.950.95
H@10.140.370.910.940.940.940.940.94
H@30.200.500.930.940.950.950.950.95
H@100.290.600.940.950.950.950.960.96
reg1e-35e-45e-41e-35e-35e-25e-25e-2
#Params410k656k1.311M2.049M4.098M8.196M40.979M163.916M

FB15K-237

Batch Size : 100 (1000 for rank 1000)

rank5255010050010002000
MRR0.280.330.340.350.360.370.37
H@10.200.240.250.260.270.270.27
H@30.310.360.370.390.400.400.40
H@100.440.510.520.540.560.560.56
reg5e-45e-25e-25e-25e-25e-25e-2
#Params150k751k1.502M3.003M15.015M30.030M60.060M

WN18RR

Batch Size : 100 (1000 for rank 8)

rank581625501005002000
MRR0.260.360.420.440.460.470.490.49
H@10.200.380.390.410.430.430.440.44
H@30.290.380.420.450.470.490.500.50
H@100.360.410.460.490.520.560.580.58
reg5e-45e-45e-21e-11e-11e-11e-11e-1
#Params410k655k1.311M2.048M4.097M8.193M40.975M163.860M

YAGO3-10

rank51625501005001000
MRR0.150.340.460.540.560.570.58
H@10.100.260.380.470.490.500.50
H@30.160.370.500.580.600.620.62
H@100.250.500.600.670.690.710.71
reg1e-31e-45e-35e-35e-35e-35e-3
#Params1.233M3.944M6.163M12.326M24.652M123.262M246.524M

License

kbc is CC-BY-NC licensed, as found in the LICENSE file.