Skip to content

Commit

Permalink
Fix the bug in TransR, which makes the script crash when hidden_sizeE…
Browse files Browse the repository at this point in the history
… != hidden_sizeR
  • Loading branch information
韩旭 committed May 29, 2017
1 parent 85dcfb3 commit 151cc24
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions transR.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,16 @@ def __init__(self, config):
with tf.name_scope('lookup_embeddings'):
pos_h_e = tf.reshape(tf.nn.embedding_lookup(self.ent_embeddings, self.pos_h), [-1, sizeE, 1])
pos_t_e = tf.reshape(tf.nn.embedding_lookup(self.ent_embeddings, self.pos_t), [-1, sizeE, 1])
pos_r_e = tf.reshape(tf.nn.embedding_lookup(self.rel_embeddings, self.pos_r), [-1, sizeE, 1])
pos_r_e = tf.reshape(tf.nn.embedding_lookup(self.rel_embeddings, self.pos_r), [-1, sizeR])
neg_h_e = tf.reshape(tf.nn.embedding_lookup(self.ent_embeddings, self.neg_h), [-1, sizeE, 1])
neg_t_e = tf.reshape(tf.nn.embedding_lookup(self.ent_embeddings, self.neg_t), [-1, sizeE, 1])
neg_r_e = tf.reshape(tf.nn.embedding_lookup(self.rel_embeddings, self.neg_r), [-1, sizeE, 1])
neg_r_e = tf.reshape(tf.nn.embedding_lookup(self.rel_embeddings, self.neg_r), [-1, sizeR])
matrix = tf.reshape(tf.nn.embedding_lookup(self.rel_matrix, self.neg_r), [-1, sizeR, sizeE])

pos_h_e = tf.reshape(tf.batch_matmul(matrix, pos_h_e), [-1, sizeR])
pos_t_e = tf.reshape(tf.batch_matmul(matrix, pos_t_e), [-1, sizeR])
pos_r_e = tf.reshape(tf.batch_matmul(matrix, pos_r_e), [-1, sizeR])
neg_h_e = tf.reshape(tf.batch_matmul(matrix, neg_h_e), [-1, sizeR])
neg_t_e = tf.reshape(tf.batch_matmul(matrix, neg_t_e), [-1, sizeR])
neg_r_e = tf.reshape(tf.batch_matmul(matrix, neg_r_e), [-1, sizeR])

if config.L1_flag:
pos = tf.reduce_sum(abs(pos_h_e + pos_r_e - pos_t_e), 1, keep_dims = True)
Expand Down

2 comments on commit 151cc24

@CountMatrix
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Thank you for sharing your work. I am a student and just started touching python and TensorFlow. I have download your program, but I have some problems. when i run TransR.py , should i adjust some parameters? and where i can take the result? I am a tiro and do not understand the source code very well, so not hesitate to enlighten me.

@THUCSTHanxu13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can run the program directly with the default parameters. If you want to change the parameters, you can change them as follows:
self.hidden_sizeE //the dimension of entity embeddings
self.hidden_sizeR //the dimension of relation embeddings
self.nbatches // the times for each round to traverse the whole dataset
self.margin //You can know more about the margin from the paper
self.L1_flag //True means the score functions will be calculated under l1 distance, False means be calculated under l2 distance.

Please sign in to comment.