【发布时间】:2021-09-24 01:01:54
【问题描述】:
我正在使用 Hugging Face mrm8488/longformer-base-4096-finetuned-squadv2 预训练模型
https://huggingface.co/mrm8488/longformer-base-4096-finetuned-squadv2.
我想生成句子级嵌入。我有一个包含文本列的数据框。
我正在使用此代码:
import torch
from transformers import AutoTokenizer, AutoModelForQuestionAnswering
ckpt = "mrm8488/longformer-base-4096-finetuned-squadv2"
tokenizer = AutoTokenizer.from_pretrained(ckpt)
model = AutoModelForQuestionAnswering.from_pretrained(ckpt)
text = "Huggingface has democratized NLP. Huge thanks to Huggingface for this." # I will pas text-column here from my data-frame
#question = "What has Huggingface done ?"
encoding = tokenizer(question, text, return_tensors="pt")
# I don't want to use it for Question-Answer use-case. I just need the sentence embeddings
input_ids = encoding["input_ids"]
# default is local attention everywhere
# the forward method will automatically set global attention on question tokens
attention_mask = encoding["attention_mask"]
如何在上面的代码中进行修改以生成句子的嵌入。 ?
我有以下例子:
Text
i've added notes to the claim and it's been escalated for final review
after submitting the request you'll receive an email confirming the open request.
hello my name is person and i'll be assisting you
this is sam and i'll be assisting you for date.
I'll return the amount as asap.
ill return it to you.
【问题讨论】:
标签: python-3.x deep-learning embedding huggingface-transformers transformer