小编and*_*ron的帖子

如何将从现有列派生的句子嵌入添加到新列中?

我有一个数据框,有四个 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)

python nlp pandas sentence-transformers

3
推荐指数
1
解决办法
3465
查看次数

标签 统计

nlp ×1

pandas ×1

python ×1

sentence-transformers ×1