def build(self, save_path = 'this-model.ckpt', data_save_path = 'this-data.bin'): self.multiG = multiG.multiG() self.multiG.load(data_save_path) self.tf_parts = model.TFParts(num_rels1=self.multiG.KG1.num_rels(), num_ents1=self.multiG.KG1.num_ents(), num_rels2=self.multiG.KG2.num_rels(), num_ents2=self.multiG.KG2.num_ents(), dim=self.multiG.dim, #batch_sizeK=self.batch_sizeK, #batch_sizeA=self.batch_sizeA, L1=self.multiG.L1) c = tf.ConfigProto(inter_op_parallelism_threads=3, intra_op_parallelism_threads=3) c.gpu_options.allow_growth = True self.sess = sess = tf.Session(config=c) self.tf_parts._saver.restore(sess, save_path) # load it value_ht1, value_r1, value_ht2, value_r2, value_M, value_b = sess.run([self.tf_parts._ht1_norm, self.tf_parts._r1, self.tf_parts._ht2_norm, self.tf_parts._r2, self.tf_parts._M, self.tf_parts._b]) # extract values. #value_ht1, value_r1, value_ht2, value_r2, value_M = sess.run([self.tf_parts._ht1_norm, self.tf_parts._r1, self.tf_parts._ht2_norm, self.tf_parts._r2, self.tf_parts._M]) #sess.close() self.vec_e[1] = np.array(value_ht1) self.vec_e[2] = np.array(value_ht2) self.vec_r[1] = np.array(value_r1) self.vec_r[2] = np.array(value_r2) self.mat = np.array(value_M) self._b = np.array(value_b)
def build(self, multiG, dim=64, batch_sizeK=1024, batch_sizeA=32, a1=5., a2=0.5, m1=0.5, save_path='this-model.ckpt', multiG_save_path='this-multiG.bin', L1=False): self.multiG = multiG self.dim = self.multiG.dim = self.multiG.KG1.dim = self.multiG.KG2.dim = dim #self.multiG.KG1.wv_dim = self.multiG.KG2.wv_dim = wv_dim self.batch_sizeK = self.multiG.batch_sizeK = batch_sizeK self.batch_sizeA = self.multiG.batch_sizeA = batch_sizeA self.multiG_save_path = multiG_save_path self.save_path = save_path self.L1 = self.multiG.L1 = L1 self.tf_parts = model.TFParts(num_rels1=self.multiG.KG1.num_rels(), num_ents1=self.multiG.KG1.num_ents(), num_rels2=self.multiG.KG2.num_rels(), num_ents2=self.multiG.KG2.num_ents(), dim=dim, batch_sizeK=self.batch_sizeK, batch_sizeA=self.batch_sizeA, L1=self.L1) self.tf_parts._m1 = m1 self.sess = sess = tf.Session() sess.run(tf.initialize_all_variables())
def build(self, save_path='this-model.ckpt', data_save_path='this-data.bin'): self.multiG = multiG.multiG() self.multiG.load(data_save_path) self.tf_parts = model.TFParts( num_rels1=self.multiG.KG1.num_rels(), num_ents1=self.multiG.KG1.num_ents(), num_rels2=self.multiG.KG2.num_rels(), num_ents2=self.multiG.KG2.num_ents(), dim=self.multiG.dim, #batch_sizeK=self.batch_sizeK, #batch_sizeA=self.batch_sizeA, L1=self.multiG.L1) self.sess = sess = tf.Session() self.tf_parts._saver.restore(sess, save_path) # load it value_ht1, value_r1, value_ht2, value_r2, value_M, value_b = sess.run([ self.tf_parts._ht1_norm, self.tf_parts._r1, self.tf_parts._ht2_norm, self.tf_parts._r2, self.tf_parts._M, self.tf_parts._b ]) # extract values. #value_ht1, value_r1, value_ht2, value_r2, value_M = sess.run([self.tf_parts._ht1_norm, self.tf_parts._r1, self.tf_parts._ht2_norm, self.tf_parts._r2, self.tf_parts._M]) #sess.close() self.vec_e[1] = np.array(value_ht1) self.vec_e[2] = np.array(value_ht2) self.vec_r[1] = np.array(value_r1) self.vec_r[2] = np.array(value_r2) self.mat = np.array(value_M) self._b = np.array(value_b)
def build(self, multiG, method='transe', bridge='CG-one', dim1=300, dim2=50, batch_sizeK1=1024, batch_sizeK2=1024, batch_sizeA=32, a1=5., a2=0.5, m1=0.5, m2=1.0, save_path='this-model.ckpt', multiG_save_path='this-multiG.bin', log_save_path='tf_log', L1=False): self.multiG = multiG self.method = method self.bridge = bridge self.dim1 = self.multiG.dim1 = self.multiG.KG1.dim = dim1 # update dim self.dim2 = self.multiG.dim2 = self.multiG.KG2.dim = dim2 # update dim #self.multiG.KG1.wv_dim = self.multiG.KG2.wv_dim = wv_dim self.batch_sizeK1 = self.multiG.batch_sizeK1 = batch_sizeK1 self.batch_sizeK2 = self.multiG.batch_sizeK2 = batch_sizeK2 self.batch_sizeA = self.multiG.batch_sizeA = batch_sizeA self.multiG_save_path = multiG_save_path self.log_save_path = log_save_path self.save_path = save_path self.L1 = self.multiG.L1 = L1 self.tf_parts = model.TFParts(num_rels1=self.multiG.KG1.num_rels(), num_ents1=self.multiG.KG1.num_ents(), num_rels2=self.multiG.KG2.num_rels(), num_ents2=self.multiG.KG2.num_ents(), method=self.method, bridge=self.bridge, dim1=dim1, dim2=dim2, batch_sizeK1=self.batch_sizeK1, batch_sizeK2=self.batch_sizeK2, batch_sizeA=self.batch_sizeA, L1=self.L1) self.tf_parts._m1 = m1 self.tf_parts._m2 = m2 config = tf.ConfigProto() config.gpu_options.allow_growth = True self.sess = tf.Session(config=config) self.sess.run(tf.global_variables_initializer()) self.writer = tf.summary.FileWriter(log_save_path, graph=tf.get_default_graph())
def load_tfparts(multiG, dim=64, batch_sizeK=1024, batch_sizeA=64, save_path='this-model.ckpt', L1=False): tf_parts = model.TFParts(num_rels1=multiG.KG1.num_rels(), num_ents1=multiG.KG1.num_ents(), num_rels2=multiG.KG2.num_rels(), num_ents2=multiG.KG2.num_ents(), dim=dim, batch_sizeK=batch_sizeK, batch_sizeA=batch_sizeA, L1=L1) #with tf.Session() as sess: sess = tf.Session() tf_parts._saver.restore(sess, save_path)
def build(self, multiG, dim=64, batch_sizeK=1024, batch_sizeA=32, batch_sizeH=1024, a1=5., a2=0.5, m1=0.5, save_path='this-model.ckpt', multiG_save_path='this-multiG.bin', L1=False): self.multiG = multiG self.dim = self.multiG.dim = self.multiG.KG1.dim = self.multiG.KG2.dim = dim # self.multiG.KG1.wv_dim = self.multiG.KG2.wv_dim = wv_dim self.batch_sizeK = self.multiG.batch_sizeK = batch_sizeK self.batch_sizeA = self.multiG.batch_sizeA = batch_sizeA self.batch_sizeH = self.multiG.batch_sizeH = batch_sizeH self.batch_sizeL1 = self.batch_sizeH * self.multiG.KG1.low_high self.batch_sizeL2 = self.batch_sizeH * self.multiG.KG2.low_high self.multiG_save_path = multiG_save_path self.save_path = save_path self.L1 = self.multiG.L1 = L1 self.tf_parts = model.TFParts(num_rels1=self.multiG.KG1.num_rels(), num_ents1=self.multiG.KG1.num_ents(), num_rels2=self.multiG.KG2.num_rels(), num_ents2=self.multiG.KG2.num_ents(), dim=dim, batch_sizeK=self.batch_sizeK, batch_sizeA=self.batch_sizeA, batch_sizeH=self.batch_sizeH, batch_sizeL1=self.batch_sizeL1, batch_sizeL2=self.batch_sizeL2, L1=self.L1) self.tf_parts._m1 = m1 c = tf.ConfigProto(inter_op_parallelism_threads=3, intra_op_parallelism_threads=3) c.gpu_options.allow_growth = True self.sess = sess = tf.Session(config=c) sess.run(tf.initialize_all_variables())
def load_tfparts(multiG, method='transe', bridge='CG-one', dim1=300, dim2=100, batch_sizeK1=1024, batch_sizeK=1024, batch_sizeA=64, save_path='this-model.ckpt', L1=False): tf_parts = model.TFParts(num_rels1=multiG.KG1.num_rels(), num_ents1=multiG.KG1.num_ents(), num_rels2=multiG.KG2.num_rels(), num_ents2=multiG.KG2.num_ents(), method=self.method, bridge=self.bridge, dim1=dim1, dim2=dim2, batch_sizeK=batch_sizeK, batch_sizeA=batch_sizeA, L1=L1) #with tf.Session() as sess: sess = tf.Session() tf_parts._saver.restore(sess, save_path)