问题描述
我目前正在尝试通过TensorFlow扩展(TFX)管道来提供带有几个多价要素列的数据集。这是我的示例数据中的一行:
user_id 29601
product_id 28
touched_product_id [2435,28]
liked_product_id [2435,28]
disliked_product_id []
target 1
如您所见,touched_product_id
,liked_product_id
,disliked_product_id
列(功能)是多价的。
现在,为了通过TFX的验证层提供此数据,我遵循以下指南:
https://www.tensorflow.org/tfx/tutorials/tfx/components_keras
根据指南,我使用TFRecord
的实例生成了一些CsvexampleGen
文件,并继续生成统计信息和架构,如下所示:
# create train and eval records
c = CsvexampleGen(input_base='sample_train')
context.run(c)
# generate statistics
statistics_gen = StatisticsGen(
examples=c.outputs['examples']
)
context.run(statistics_gen)
# generate schema
schema_gen = SchemaGen(
statistics=statistics_gen.outputs['statistics'],infer_feature_shape=False)
context.run(schema_gen)
context.show(schema_gen.outputs['schema'])
Type Presence Valency Domain
Feature name
'disliked_product_id' BYTES required single -
'liked_product_id' BYTES required single -
'product_id' INT required single -
'target' INT required single -
'touched_product_id' BYTES required single -
'user_id' INT required single -
很明显,多价特征被错误地推断为单价。为了解决此问题,我手动加载了Schema
原型并尝试调整valence
属性。
schema_path = os.path.join(schema_gen.outputs['schema'].get()[0].uri,'schema.pbtxt')
schema = schema_pb2.Schema()
contents = file_io.read_file_to_string(schema_path)
schema = text_format.Parse(contents,schema)
# THIS LINE DOES NOT WORK
tfdv.get_feature(schema,'user_id').valence = 'multiple'
很显然,最后一行不起作用,因为令我惊讶的是,没有valence
属性。我尝试查看Schema
原型的规范,但没有找到valence
属性。有人知道我该如何解决?任何指导都是不可思议的。
解决方法
尝试将feature.value_count.min或feature.value_count.max设置为大于1的值