python - 在 TensorFlow 数据集上应用预处理需要很长时间
问题描述
我正在尝试应用预处理器从 Tensorflow 数据集的文件中删除 html 标签。我在执行t5
which uses时使用它segio
。
my_preprocessor
如果我使用,它可以正常工作,text = row[field_index]
并且在训练中,它会打印几行并继续,但是如果我使用text = normalize_text(row[field_index])
它,它会挂在无限或长循环上,就好像它想将它应用于整个数据集行一样!
def normalize_text(text):
"""Lowercase and remove quotes and tags from a TensorFlow string."""
text = tf.strings.lower(text)
text = tf.strings.regex_replace(text,"'(.*)'", r"\1")
text = tf.strings.regex_replace(text,"<[^>]+>", " ")
return text
def make_add_field_names_preprocessor(
field_names: Sequence[str], field_indices: Optional[Sequence[int]] = None,
) -> Callable:
def my_preprocessor(ds):
def to_inputs_and_targets(*row):
ret = {}
count=0
tf.print("=======================")
for field_name, field_index in zip(field_names, field_indices):
# if I use this, it works okay
text = row[field_index]
# if I use the following it falls to a long or endless loop
text = normalize_text(row[field_index])
tf.print(count, "Row:",text)
ret[field_name] = text
count+=1
return ret
return ds.map(to_inputs_and_targets,
num_parallel_calls=tf.data.experimental.AUTOTUNE)
return my_preprocessor
更新:预处理器获取两个字段名称,行 [1] 的“输入”和行 [2] 的“目标”。normalize_text
当我打电话时,我注意到问题存在很多row[2]
解决方案
推荐阅读
- c# - 拉伸平面的角以将包含的四边形拉伸成矩形?(给出的图像)
- c# - 在c#中使用内容设置href元素的innerText以~/开头
- php - 如何正确配置 php.uni 来解决这些错误
- swiftui - Xcode SwiftUI 共享自定义图像为空白
- reactjs - 反应导航6隐藏抽屉项目
- docusignapi - Docu 签名 REST Api - 尝试将用户添加到组中,并给出 404 异常
- android-constraintlayout - 使用指南时Android约束布局结果不同
- kotlin - Kotlin - 类型不匹配:推断类型是 Any?但布尔值是预期的
- thingsboard - Thingsboard PE3.3 中的解决方案模板
- r - 如何用R中的多个条件替换值