gpt4 book ai didi

nlp - 使用encode_plus方法时 token 索引序列长度错误

转载 作者:行者123 更新时间:2023-12-03 14:53:47 24 4
gpt4 key购买 nike

尝试使用 encode_plus 为 BERT 编码问答对时遇到一个奇怪的错误Transformers 库中提供的方法。
我正在使用来自 this Kaggle competition 的数据.给定问题标题、问题正文和答案,模型必须预测 30 个值(回归问题)。我的目标是将以下编码作为 BERT 的输入:
[CLS] question_title question_body [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
它说 token 索引的长度比指定的最大序列长度长,但事实并非如此(如您所见,46 不 > 512)。
这发生在 df_train 中的几行中.我在这里做错了吗?

最佳答案

模型 'bert-base-uncased' 没有经过预训练来处理 [CLS] + Question + [SEP] + Context + [SEP] 的长文本。来自 Huggingface models 的任何其他型号专用于小队问答数据集将处理长序列。

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

关于nlp - 使用encode_plus方法时 token 索引序列长度错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61322251/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com