0

After reading thousands of tutorials I am not still able to print tensors values in some scenario. What is clear to me is that tensorflow first builds the graph and then it actually feeds the values of variables, placeholders etc. However, I am not able to print the values of some tensor in this code link_1. More details below.

The _build_train() function is defined as following (line 156 of ptranse.py), and it calls the _forward_t_model method in order to return the t_z_pos and t_z_neg tensors.

def _build_train(self):
    t_z_pos, t_z_neg = self._forward_t_model(self._w, self._v, False)
    at_z_pos, at_z_neg = self._forward_t_model(self._aw, self._av, True)
    k_z_pos, k_z_h_neg, k_z_t_neg, k_z_r_neg = self._forward_k_model(self._pos_h, self._pos_t, self._pos_r)
    ak_z_pos, ak_z_h_neg, ak_z_t_neg, ak_z_r_neg = self._forward_k_model(self._pos_ah, self._pos_at, self._pos_ar)
    nce_loss = self._nce_loss(t_z_pos, t_z_neg, k_z_pos, k_z_h_neg, k_z_t_neg, k_z_r_neg)
    nce_loss = nce_loss + self._nce_loss(at_z_pos, at_z_neg, ak_z_pos, ak_z_h_neg, ak_z_t_neg, ak_z_r_neg)
    self._train = self._optimize(nce_loss)
    self._loss = nce_loss

I am interested in printing t_z_pos and t_z_neg values and as suggested here link_2 I have added after t_z_pos, t_z_neg = self._forward_t_model(self._w, self._v, False) the following line:

print(t_z_pos.eval())

However, the execution stops by showing the following message: You must feed a value for placeholder tensor 'w_' with dtype int32 and shape [64]...

I guess that the script crashes because I am asking to print a value while it is still building the graph (so before feeding the tensors with some values). My question is, how can I print the values of tensors just after they have been initialised and feed with some value? There are similar questions for my same problem link_3, link_4 and link_5 but none of them helped me to figure this out.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
Junior hpc
  • 169
  • 1
  • 12

0 Answers0