在尝试使用encode_plusTransformers 库中提供的方法为 BERT 编码问答对时,我遇到了一个奇怪的错误。
我正在使用来自这个 Kaggle 比赛的数据。给定问题标题、问题正文和答案,模型必须预测 30 个值(回归问题)。我的目标是将以下编码作为 BERT 的输入:
[CLS] question_title question_body [SEP] 回答 [SEP]
但是,当我尝试使用
tokenizer = transformers.BertTokenizer.from_pretrained("bert-base-uncased")
Run Code Online (Sandbox Code Playgroud)
并仅对来自 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
)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Token indices sequence length is longer than the specified maximum sequence length for this model (46 > 512). …Run Code Online (Sandbox Code Playgroud)