“您必须指定 input_ids 或 input_embeds”,但我确实指定了 input_ids

2024-03-06

我训练了一个基于 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

有任何想法吗 ?


嗯,显然这是一个已知问题,例如:本期T5 https://github.com/huggingface/transformers/issues/3626

问题是代码中可能存在重命名过程,因为我们使用编码器-解码器架构,所以我们有 2 种类型的输入 id。

解决办法是显式指定输入id的类型

ed_model.forward(decoder_input_ids=inputs['input_ids'],**inputs) 

我希望它被记录在某个地方,但现在你知道了:-)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

“您必须指定 input_ids 或 input_embeds”,但我确实指定了 input_ids 的相关文章

随机推荐