我正在尝试使用预训练的BERT模型进行文本分类。我在我的数据集上训练了模型,并在测试阶段;我知道BERT只能接受512个令牌,所以我编写了if条件来检查我的数据帧中测试的长度。如果它长于512,我将句子分成序列,每个序列有512个标记。然后进行标记器编码。序列的长度是512,但是在执行tokenize编码之后,长度变成了707,我得到了这个错误。The size of tensor a (707)
我正在执行以下操作: energy.masked_fill(mask == 0, float("-1e20")) 我的蟒蛇痕迹在下面, File "/usr/local/lib/python3.6(mask == 0, float("-1e20"))
RuntimeError: The size of tensor a (1024) must match the size of tensor b(512) at non-singleton d
bert = AutoModel.from_pretrained('bert-base-uncased') 这是训练的代码。position_embeddings + token_type_embeddings
RuntimeError: The size of tensor a (4000) must match the size of tensor b(512) at non-singleton dimension 1 如果您注意到,我已经在代码中打印了手电筒的大小。print(