1

我正在尝试让以下预训练的拥抱脸模型工作: https ://huggingface.co/mmoradi/Robust-Biomed-RoBERTa-RelationClassification

我使用以下代码:

from transformers import AutoTokenizer, AutoModel
  
tokenizer = AutoTokenizer.from_pretrained("mmoradi/Robust-Biomed-RoBERTa-RelationClassification")

model = AutoModel.from_pretrained("mmoradi/Robust-Biomed-RoBERTa-RelationClassification")

inputs = tokenizer("""The colorectal cancer was caused by mutations in angina""")
outputs = model(**inputs)

出于某种原因,在尝试生成输出时出现以下错误,因此在我的代码的最后一行:

--> 796 input_shape = input_ids.size() 797 elif inputs_embeds 不是 None: 798 input_shape = inputs_embeds.size()[:-1]

AttributeError:“列表”对象没有属性“大小”

输入如下所示:

{'input_ids': [0, 133, 11311, 1688, 3894, 337, 1668, 21, 1726, 30, 28513, 11, 1480, 347, 2], 'attention_mask': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}

我不知道如何调试这个,所以欢迎任何帮助或提示!

4

1 回答 1

2

您必须指定要作为回报的张量类型tokenizer。如果你不这样做,它将返回一个包含两个列表(input_idsattention_mask)的字典:

inputs = tokenizer("""The colorectal cancer was caused by mutations in angina""", return_tensors="pt")
于 2021-10-22T13:26:46.030 回答