Hey mates. Hope you are in good health. I need some guidance. I’m rebuilding an embedding model from TensorFlow to PyTorch. Here is the link:

  
      github.com
  
  
    Sujit-O/pykg2vec/blob/702e0d4012195dd8b807ec9f412887a7f3c02c9e/pykg2vec/core/TransM.py#L124



    score_pos = pos_r_theta*self.distance(pos_h_e, pos_r_e, pos_t_e)
    score_neg = neg_r_theta*self.distance(neg_h_e, neg_r_e, neg_t_e)


    self.loss = tf.reduce_sum(tf.maximum(score_pos + self.config.margin - score_neg, 0))


def test_batch(self):
    """Function that performs batch testing for the algorithm.


       Returns:
           Tensors: Returns ranks of head and tail.
    """
    head_vec, rel_vec, tail_vec = self.embed(self.test_h_batch, self.test_r_batch, self.test_t_batch)


    norm_ent_embeddings = tf.nn.l2_normalize(self.ent_embeddings, axis=1)
    score_head = self.distance(norm_ent_embeddings, tf.expand_dims(rel_vec, 1), tf.expand_dims(tail_vec, 1))
    score_tail = self.distance(tf.expand_dims(head_vec, 1), tf.expand_dims(rel_vec, 1), norm_ent_embeddings)


    _, head_rank = tf.nn.top_k(score_head, k=self.data_stats.tot_entity)
    _, tail_rank = tf.nn.top_k(score_tail, k=self.data_stats.tot_entity)





  
  
    
    
  
  


On line 112 and 113, As I build and pass in my pytorch code:
    pos_r_theta = nn.Embedding(self.theta, pos_r)
    neg_r_theta = nn.Embedding(self.theta, neg_r)

It show me error (attached image). Q1: why this embedding not accepting the tensors as my parameters? Q2: what is the difference between tf.nn.embedding_lookup() in tf and nn.embedding() in pytorch? Q3: Does pytorch support any function similar to np.asarray (code line 103) (now want to use torch.from_numpy, proceed only in pytorch)?

error.png1111×167 7.75 KB