TFX Tensorflow Transform 将文本转换为 TFIDF 矢量

问题描述

我正在尝试使用以下代码使用 TXF 转换组件为我的电子邮件分类问题计算 TFIDF 向量化。

#module_file=pd_preprocess.py

def preprocessing_fn(inputs):
    outputs = {}
    tf.compat.v1.disable_eager_execution()
    tokens = tf.compat.v1.string_split(inputs['Email'])
    indices = tft.compute_and_apply_vocabulary(tokens,top_k=VOCAB_SIZE)
    outputs[_transformed_name('Email')] = tft.tfidf(indices,VOCAB_SIZE + 1)
    return outputs

TFX 转换组件:

from tfx.components import Transform
advert_transform = 'pd_preprocess.py'
transform = Transform(
   examples=example_gen.outputs['examples'],schema=schema_gen.outputs['schema'],module_file=advert_transform)
context.run(transform)

但在我上面的代码不起作用并抛出以下错误

TypeError: 预期的字符串,在 0x7f7510bf8e90 处得到了 ,类型为“SparseTensor”。

有人可以帮助我在上面的转换代码中做错了什么,为什么它会期望 Tensorflow 方法的字符串。

谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)