如何使用 DeBERTa.deberta.pooling 获取句子嵌入?
大家好,我应用了 DeBERTa 模型来分析句子,这是我的代码:
from transformers import DebertaTokenizer, DebertaModel
import torch
# downloading the models
tokenizer = DebertaTokenizer.from_pretrained("microsoft/deberta-base")
model = DebertaModel.from_pretrained("microsoft/deberta-base")
# tokenizing the input text and converting it into pytorch tensors
inputs = tokenizer(["The cat cought the mouse", "This is the second sentence"], return_tensors="pt", padding=True)
# pass through the model
outputs = model(**inputs)
我意识到获取句子嵌入的一种选择是使用
查看 CLS 隐藏状态outputs.last_hidden_state[:,0,:]
但是,我更愿意获得合并的输出。据我所知,不支持
pooled_output
,但 DeBERTa 中似乎有一个名为 DeBERTa.deberta.pooling 的实现(请参阅 https://deberta.readthedocs.io/en/latest/_modules/DeBERTa/deberta/pooling .html)。有谁知道怎么用吗
我也遇到同样的问题,请问你解决了吗?