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

时间:2021-02-03 13:49:30

标签: tensorflow tf-idf tfx

我正在尝试使用以下代码使用 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 方法的字符串。

谢谢。

0 个答案:

没有答案
相关问题