1

我正在尝试创建一个嵌入以用于单词匹配技术,但出现以下错误:

   Traceback (most recent call last)
    /var/folders/k1/jt1nfyks4cx689d50f5mtg0w0000gp/T/ipykernel_1349/3490519318.py in <module>
         53 #Compute embedding for both lists
         54 
    ---> 55 embeddings1 = model.encode(fifteen_percent_list, convert_to_tensor=True)
         56 
         57 
    
    /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sentence_transformers/SentenceTransformer.py in encode(self, sentences, batch_size, show_progress_bar, output_value, convert_to_numpy, convert_to_tensor, device, normalize_embeddings)
        185 
        186         if convert_to_tensor:
    --> 187             all_embeddings = torch.stack(all_embeddings)
        188         elif convert_to_numpy:
        189             all_embeddings = np.asarray([emb.numpy() for emb in all_embeddings])
    
    RuntimeError: stack expects a non-empty TensorList

我似乎不明白为什么会发生这种情况,因为我的第二个嵌入(2)没有任何错误就很好地完成了?

如果有帮助,这里是一些代码:

from sentence_transformers import SentenceTransformer, util
model = SentenceTransformer('distilbert-base-nli-stsb-mean-tokens')

fifteen_percent_list = list(fiften_percent)

#Compute embedding for both lists

embeddings1 = model.encode(fifteen_percent_list, convert_to_tensor=True)


# try on a smaller set of 10k, as it takes too long to run on full set of queries

rest_of_queries_list = list(set(rest_of_queries))[:10000]
embeddings2 = model.encode(rest_of_queries_list, convert_to_tensor=True)
4

0 回答 0