When doing sentence similarity when to use tensors?


I’m trying to do some sentence similarity to compare 2 list of items.

I’m following the guides and so far it works. I was juste wondering why do we need to convert the embeddings to tensors?

I run my script (which is exactly this: Semantic Textual Similarity — Sentence-Transformers documentation) with 2 arrays of about 200 sentences.

The execution times are:

  • with print: ~9s
  • without print: ~2.5s

But then without converting to tensors:

  • with print : ~3s
  • without: ~2.5s

For both, the encode time are quite similar.

The cosine similarity time are very different and it goes way faster when not using tensor embeddings:

  • with tensor: 0.01s
  • without: 0.0004s

I’m very new to ML so my understanding is that the tensor is higher dimension vector.
So my question is why do we need tensors? Will it be faster if i put more and more sentences? Does it impact the precision of the results? And why does this impact the time so much when i print the result?

Thank you very much!