我正在尝试使用BERT模型,该模型提供注意力、输入ID和令牌类型ID。但当我试图将我的数据集转换为TF数据集时,它抛出了以下错误:
ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type list).
我尝试查看ValueError:未能将NumPy数组转换为Tensor(不支持的对象类型列表(,但它没有解决我的问题。请参阅下面的代码。
for fold in range(5):
train_fold = train[train['kfold'] != fold]
valid_fold = train[train['kfold'] == fold]
X_train_dataset = (X_train[0][train_fold.index.to_list()], X_train[1]
[train_fold.index.to_list()],
X_train[2][train_fold.index.to_list()])
train_dataset = (
tf.data.Dataset
.from_tensor_slices((X_train_dataset, train_fold['discourse_effectiveness'].values))
.repeat()
.shuffle(2048)
.batch(BATCH_SIZE)
.prefetch(AUTO)
)
当我看到数据集的类型如下:
for x in X_train_dataset:
print(type(x))
type(train_fold['target'].values)
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
numpy.ndarray
我使用存储input_ids、attention\ymask和令牌类型id的方式解决了同样的问题。我尝试使用np.zeros((df.shape[0],256((,然后添加数据