Source code for our paper Hierarchical Blockmodelling for Knowledge Graphs. The implementation is an extension of Qirong Ho's Gibbs Sampler provided to the authors via private correspondence.
compile.mdefines the necessary paths and the mex compilation and linking functionrun.mis the script to run the Gibbs sampler on the Synthetic Binary Tree dataset described in the papersampler.mis the Matlab wrapper for the C++ Gibbs sampler. This wrapper calls the mex gateway functiongateway.cppgateway.ccpis the mex gateway function. It is called bysampler.mand initializes the Gibbs samplerhb.hppis the core of the Gibbs sampler. It defines the tree structure and performs all the necessary sampling computationsdata/synthetic_binary_tree.txtis the for data file the Synthetic Binary Tree dataset. Each line contains the index of the subject, object, and predicate of a triple in the datadata/fb15k-237.txtis the for data file the FB15k-237 dataset. Each line contains the index of the subject, object, and predicate of a triple in the datadata/wikidata.txtis the for data file the Wikidata dataset. Each line contains the index of the subject, object, and predicate of a triple in the datadata/fb15k-237_id2entity.txtis the transaltion file between indices and entities for the FB15k-237 datasetdata/fb15k-wikidata.txtis the transaltion file between indices and entities for the Wikidata dataset
- Install Boost 1.67.0 C++ libraries
- Install MinGW in MATLAB
- Update the variables
BOOST_PATHandBOOST_LIB_PATHincompile.mto reflect the root and library paths of Boost 1.67.0 - Run
compile.m
Run run.m to perform inference on the model on the Synthetic Binary Tree dataset. If you wish to perform inference using the other two datasets in our paper, follow these steps:
- Change the size of the input matrix
Eincompile.m - Change the sizes of
model_Nandmodel_Ringateway.cppto correspond to the size of the graph's adjacency tensor - Change the input file in the Mex gateway function
gateway.cpp - Run
compile.mto recompile C++ code - Update model hyperparameters
- Run
run.mto perform inference