我训练了一个基于 BERT 的编码器解码器模型(EncoderDecoderModel
) named ed_model
使用 HuggingFace 的变压器模块。
我用的是BertTokenizer
命名为input_tokenizer
我用以下方法标记了输入:
txt = "Some wonderful sentence to encode"
inputs = input_tokenizer(txt, return_tensors="pt").to(device)
print(inputs)
输出清楚地表明input_ids
是返回字典
{'input_ids': tensor([[ 101, 5660, 7975, 2127, 2053, 2936, 5061, 102]], device='cuda:0'), 'token_type_ids': tensor([[0, 0, 0, 0, 0, 0, 0, 0]], device='cuda:0'), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1]], device='cuda:0')}
但是当我尝试预测时,我收到此错误:ed_model.forward(**inputs)
ValueError:您必须指定 input_ids 或 input_embeds
有任何想法吗 ?