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

why pos_r_e and neg_r_e are multiplied by a matrix in transR.py? #5

Closed jiaky777 closed 7 years ago

jiaky777 commented 7 years ago

in transR.py line 59 and line 62

57: pos_h_e = tf.reshape(tf.batch_matmul(matrix, pos_h_e), [-1, sizeR])
58: pos_t_e = tf.reshape(tf.batch_matmul(matrix, pos_t_e), [-1, sizeR])
59: pos_r_e = tf.reshape(tf.batch_matmul(matrix, pos_r_e), [-1, sizeR])
60: neg_h_e = tf.reshape(tf.batch_matmul(matrix, neg_h_e), [-1, sizeR])
61: neg_t_e = tf.reshape(tf.batch_matmul(matrix, neg_t_e), [-1, sizeR])
62: neg_r_e = tf.reshape(tf.batch_matmul(matrix, neg_r_e), [-1, sizeR])

embedding of relations are multiplied by rel_matrix, which seems wrongly implemented. pos_r_e is of shape [batchSize, sizeR] , matrix is of shape [batchSize, sizeE, sizeR], tf.batch_matmul(matrix, neg_r_e) cannot be computed unless sizeE = sizeR, but this assumption isn't always true. In transR's original paper , relation's embedding does not need to be multiplied by some matrix.

transR.py script will crash if you set hidden_sizeE != hidden_sizeR

THUCSTHanxu13 commented 7 years ago

Thank you for your suggestion. We have fixed this problem.