【发布时间】:2023-03-14 10:36:02
【问题描述】:
我正在处理这个电影分类问题 https://www.tensorflow.org/tutorials/keras/text_classification
在这个例子中,文本文件(12500 个带有电影评论的文件)被读取并准备了一个批处理数据集,如下所示
raw_train_ds = tf.keras.preprocessing.text_dataset_from_directory(
'aclImdb/train',
batch_size=batch_size,
validation_split=0.2,
subset='training',
seed=seed)
标准化时
def custom_standardization(input_data):
lowercase = tf.strings.lower(input_data)
stripped_html = tf.strings.regex_replace(lowercase, '<br />', ' ')
#I WANT TO REMOVE STOP WORDS HERE, CAN I DO
return tf.strings.regex_replace(stripped_html,'[%s]' % re.escape(string.punctuation),'')
问题:我了解到我的训练数据集带有变量“raw_train_ds”中的标签。现在我想遍历这个数据集并从电影评论文本中删除停用词并存储回同一个变量,我尝试在函数“custom_standardization”中执行此操作,但它给出了类型错误,
我也尝试使用tf.strings.as_strings,但它返回错误
InvalidArgumentError: attr 'T' of string 的值不在允许值列表中:int8、int16、int32、int64
有人可以帮忙吗,或者只是请帮助如何从批处理数据集中删除停用词
【问题讨论】:
标签: python-3.x keras tensorflow-datasets