【发布时间】:2021-01-01 21:12:03
【问题描述】:
我需要一些关于 tf.data 的帮助。
我正在对 SQUAD 数据集进行一些实验。给出的数据集结构如下:
row-1] { conext: "some big string", question:"q string", "answer": "some ans" }
我想利用 tf.data 进行加载和预处理。加载后,它被加载。格式:
{
context: Tensor("some big string"),
question:Tensor(q string),
answer": Tensor(some ans)
}
现在我们要对数据进行预处理。现在这里的预处理并不简单,因为值是张量对象。
Tensorflow 为此类预处理提供了一些 api,但是 如果我想进行自定义预处理,或者我想使用 spacy,它只对字符串等原始数据类型而不是张量进行操作。强>
基本上我需要关于这个 sn-p 的帮助:
def format_data(row):
# Now I can access individual data row here. But value of row is in Tensor form.
# Hence I can't use my custom function. How to use custom function or spacy function which operates on string and not on tensor?
# I can use only below tf functions
return tf.strings.regex_replace(row['context'],'some-regex',' ',True)
train = dataset.map(format_data).batch(2)
ist(train.take(1))
【问题讨论】:
-
#我也试过用tf.py_function,不行。
标签: python tensorflow tf.data.dataset