使用encode_plus方法时令牌索引序列长度错误

问题描述 投票:0回答:1

[使用Transformers库中提供的encode_plus方法尝试为BERT编码问答对时出现一个奇怪的错误。

我正在使用this Kaggle competition中的数据。给定问题标题,问题主体和答案,该模型必须预测30个值(回归问题)。我的目标是获取以下编码作为BERT的输入:

[[CLS] question_title问题主体[SEP]答案[SEP]

但是,当我尝试使用时

tokenizer = transformers.BertTokenizer.from_pretrained("bert-base-uncased")

并且仅编码来自train.csv的第二个输入,如下所示:

inputs = tokenizer.encode_plus(
            df_train["question_title"].values[1] + " " + df_train["question_body"].values[1], # first sequence to be encoded
            df_train["answer"].values[1], # second sequence to be encoded
            add_special_tokens=True, # [CLS] and 2x [SEP] 
            max_len = 512,
            pad_to_max_length=True
            )

我收到以下错误:

Token indices sequence length is longer than the specified maximum sequence length for this model (46 > 512). Running this sequence through the model will result in indexing errors

它说令牌索引的长度大于指定的最大序列长度,但这不是正确的(如您所见,46不是> 512)。

[df_train中的几行都会发生这种情况。我在这里做错了吗?

nlp tokenize huggingface-transformers bert
1个回答
0
投票

模型'bert-base-uncased'没有经过预先训练,可以处理[CLS] +问题+ [SEP] +上下文+ [SEP]的长文本。 Huggingface models中的任何其他专门用于班级问答数据集的模型都可以处理较长的序列。

例如,如果我使用ALBERT模型,我会选择'ktrapeznikov / albert-xlarge-v2-squad-v2'模型。

© www.soinside.com 2019 - 2024. All rights reserved.