FlagEmbedding icon indicating copy to clipboard operation
FlagEmbedding copied to clipboard

correct return type for encoding

Open dream-tentacle opened this issue 1 year ago • 0 comments

The returning type was only np.ndarray, but it is possible to change the return type to torch.Tensor if we set convert_to_numpy to False. The origin version can lead to wordy and inefficient codes because people don't know that encode() can return Tensor. For example, the code in Tutorial uses encode() as follow: image

which has to convert the tensor to np.ndarray and then convert it into Tensor. This code can be changed into: embeddings = model.encode([sentence_1, sentence_2, sentence_3], convert_to_numpy=False) which is more effective.

dream-tentacle avatar Sep 23 '24 10:09 dream-tentacle