【问题标题】:"You have to specify either input_ids or inputs_embeds", but I did specify the input_ids“您必须指定 input_ids 或 inputs_embeds”,但我确实指定了 input_ids
【发布时间】:2021-08-21 05:54:03
【问题描述】:

我使用 HuggingFace 的转换器模块训练了一个名为 ed_model 的基于 BERT 的编码器解码器模型 (EncoderDecoderModel)。

我使用了名为input_tokenizerBertTokenizer

我将输入标记为:

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 或 inputs_embeds

有什么想法吗?

【问题讨论】:

标签: bert-language-model huggingface-transformers


【解决方案1】:

好吧,显然这是一个已知问题,例如:This issue of T5

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-16
    • 1970-01-01
    • 2019-06-23
    • 2021-04-30
    • 2017-05-13
    • 2015-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多