[英]RuntimeError, working on IA tryna use a pre-trained BERT model
Hi here is a part of my code to use a pre-trained bert model for classification:嗨,这是我使用预训练 bert 模型进行分类的代码的一部分:
model = BertForSequenceClassification.from_pretrained(
"bert-base-uncased", # Use the 12-layer BERT model, with an uncased vocab.
num_labels = 2, # The number of output labels--2 for binary classification.
# You can increase this for multi-class tasks.
output_attentions = False, # Whether the model returns attentions weights.
output_hidden_states = False, # Whether the model returns all hidden-states.
)
... ...
for step, batch in enumerate(train_dataloader):
b_input_ids = batch[0].to(device)
b_input_mask = batch[1].to(device)
b_labels = batch[2].to(device)
outputs = model(b_input_ids,
token_type_ids=None,
attention_mask=b_input_mask,
labels=b_labels)
but then I receive this error message:但随后我收到此错误消息:
RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long;
RuntimeError: 参数 #1 'indices' 的预期张量具有标量类型 Long;
but got torch.IntTensor instead (while checking arguments for embedding) So I think I should transform my b_input_ids
to tensor but don't know how to do it.但是得到了 torch.IntTensor (同时检查嵌入参数)所以我想我应该将我的
b_input_ids
转换为张量,但不知道该怎么做。 Thanks a lot in advance for your help everyone !非常感谢大家的帮助!
最后成功使用 .to(torch.int64)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.