with torch.no_grad():
logits = torch.zeros(len(definitions), dtype=torch.double).to(DEVICE)
for i, bert_input in list(enumerate(features)):
logits[i] = model.ranking_linear(
model.bert(
input_ids=torch.tensor(bert_input.input_ids, dtype=torch.long).unsqueeze(0).to(DEVICE),
attention_mask=torch.tensor(bert_input.input_mask, dtype=torch.long).unsqueeze(0).to(DEVICE),
token_type_ids=torch.tensor(bert_input.segment_ids, dtype=torch.long).unsqueeze(0).to(DEVICE)
)[1]
)
scores = softmax(logits, dim=0)
preds = (sorted(zip(sense_keys, definitions, scores), key=lambda x: x[-1], reverse=True))
这是我得到的错误
IndexError Traceback(最后一次调用) 在
() 3 对于我,列表中的 bert_input(枚举(特征)): 4 logits[i] = model.ranking_linear( 5 模型.bert( 6 input_ids=torch.tensor(bert_input.input_ids, dtype=torch.long).unsqueeze(0).to(设备), 7 attention_mask=torch.tensor(bert_input.input_mask, dtype=torch.long).unsqueeze(0).to(DEVICE), | 6帧
/usr/local/lib/python3.10/dist-packages/torch/nn/functional.py 嵌入(输入、权重、padding_idx、max_norm、norm_type、scale_grad_by_freq、稀疏) 2208 # 删除一次脚本支持 set_grad_enabled 第2209章 第2210章 2211 2212 IndexError: index out of range in self
我想运行这段代码,我很困惑为什么它给我一个索引超出范围的错误