Transformer课程 第7课Gavin BERT文本分类-数据预处理
Comment Length Distribution为了决定这个数据集的截断策略,让我们首先看看评论长度的分布。为此,我们的第一步是标记训练集中的所有评论。
标记所有评论,tokenizer.encode函数为我们组合了多个步骤:
-
把句子切分成标记。
-
添加特殊的[CLS]和[SEP]标记。
-
将令牌映射到它们的ID。
为了探索评论长度的分布,我们在这里不执行任何截断,这会导致标记器对每个长度超过512个标记的评论发出警告,现在暂忽略这些。
import numpy as np
# Tokenize all of the sentences and map the tokens to thier word IDs.
input_ids = []
# Record the length of each sequence (after truncating to 512).
lengths =