我有一个数据框,有四个 nw_data=['Qn_id', 'Qn_context', 'Qns', 'Anwsers']。这就是它的样子
Qn_id | Qn_context | Qns | Anwsers
01 | In 1962, Uk gave... | what year....| the year 1962 was.....
02 | Major kanuti raised..| Who raised...| Kanuti akorimo rasied.
Run Code Online (Sandbox Code Playgroud)
我想向该数据集添加第五列,其中包含列 ['Answers'] 的句子嵌入。
我使用 Sentence_transformers 生成句子嵌入。
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('all-MiniLM-L6-v2')
Run Code Online (Sandbox Code Playgroud)
我尝试使用一种方法:
#Created a var for the column
sent = nw_data['Answers']
Run Code Online (Sandbox Code Playgroud)
和
#Passed the variable sent into the model and created the embeddings
embeddings = model.encode(sent)
Run Code Online (Sandbox Code Playgroud)
然后
#Tried passing the embeddings into …Run Code Online (Sandbox Code Playgroud)