1

I want to save the embeddings generated by Universal Sentence Encoder as .txt files. When I run the following code I get this error- TypeError: write() argument must be str, not tensorflow.python.framework.ops.EagerTensor

embeddings = USE_model(text[0:100])
txtfile = file_path + '/embedding' + '.txt'
if not os.path.exists(txtfile):
    text_file = open(txtfile, "a")
    text_file.write(embeddings)
    text_file.close()

What's the best way to convert tensorflow.python.framework.ops.EagerTensor to text?

Mansi -
  • 11
  • 1
  • 1
    It's a tensor, meaning a multidimensional array of numbers, so you have to convert number array into a string and then give it to `text_file.write` to dump in the text file. So you should look for a way to convert the tensor into an array (to get all the numbers) and then convert it into string. This may help: https://stackoverflow.com/q/49568041/2650427 – TrigonaMinima Jul 23 '20 at 04:23
  • Understood, was able to implement by using embeddings.numpy(). Thanks! – Mansi - Jul 24 '20 at 15:09

0 Answers0