thunlp / TensorFlow-TransX

An implementation of TransE and its extended models for Knowledge Representation Learning on TensorFlow
MIT License
514 stars 196 forks source link

How to compile and use it? #11

Closed icaro56 closed 6 years ago

icaro56 commented 6 years ago

Hi,

I compiled the project with "make.sh" and was generated a file init.so. Now, what are the step to use the lib?

When I call python TransR.py I have the problem: TabError: inconsistent use of tabs and spaces in indentation. This problem was fixed reformating the code by PyCharm

What the Python version of the project? How do use the TransX python file on the data FB15K?

Now, I execute python TransR and I get the error: "Ambiguous dimension: 4831.42"

I am using the FB15K, and the triple2id.txt has 483142 triples in the file. How could I to fix this problem?

Thanks.

icaro56 commented 6 years ago

In TransR file on line 35, the error on tensorflow happens.

with tf.name_scope("read_inputs"):
self.pos_h = tf.placeholder(tf.int32, [batch_size])

batch_size = 483142 / 100 = 4831.42

icaro56 commented 6 years ago

I try this:

config.batch_size = (int)(lib.getTripleTotal() / config.nbatches)

And the error above does not happens, but now, another error:

On line 125: lib.getBatch(ph_addr, pt_addr, pr_addr, nh_addr, nt_addr, nr_addr, config.batch_size)

ctypes.ArgumentError: argument 1: <class 'OverflowError'>: int too long to convert

icaro56 commented 6 years ago

I add the following import

from ctypes import *

And I convert the pointers that are passed to C function to:

ph_addr = c_int64(ph.__array_interface__['data'][0])
pt_addr = c_int64(pt.__array_interface__['data'][0])
pr_addr = c_int64(pr.__array_interface__['data'][0])
nh_addr = c_int64(nh.__array_interface__['data'][0])
nt_addr = c_int64(nt.__array_interface__['data'][0])
nr_addr = c_int64(nr.__array_interface__['data'][0])

I do not know if to use c_int64 is correct, but it fixed the OverflowError problem

THUCSTHanxu13 commented 6 years ago

My python version is python 2.X, and I think your python version may be python 3.X (In python 2.X, batch_size = 483142 / 100 = 4831). I change some codes and attempt to make them be able to run on python 3.X. You can try with the new codes.