You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法按拆分获取Post Transform Statistics的TFX技术求助

问题

在交互式模式下运行企鹅数据集的TFX管道,已拆分train/eval数据集,Transform步骤执行完成后,无法获取按拆分划分的post_transform_statistics制品:

  • 指定的制品文件夹/tmp/tfx-penguin_custom_INTERACTIVE-nq5dn56x/Transform/post_transform_stats/5中只有单个FeaturesStats.pb文件,没有Split-train和Split-eval子文件夹
  • 但转换后样本的制品文件夹/tmp/tfx-penguin_custom_INTERACTIVE-nq5dn56x/Transform/transformed_examples/5/中存在对应的拆分子文件夹

Transform组件定义如下(已显式指定拆分并设置disable_statistics=False):

transform = tfx.components.Transform(
  examples=example_gen.outputs['examples'],
  schema=schema_gen.outputs['schema'],
    disable_statistics=False,
  splits_config= transform_pb2.SplitsConfig(
        analyze=['train'], transform=['train', 'eval']),
  module_file=_transformer_module_file)

查看组件文档时,看到关于统计存储的注释产生困惑:

disable_statistics: If True, do not invoke TFDV to compute pre-transform
        and post-transform statistics. When statistics are computed, they will
        will be stored in the `pre_transform_feature_stats/` and
        `post_transform_feature_stats/` subfolders of the `transform_graph`
        export.

目前临时方案是禁用Transform组件的统计功能,并行定义单独的统计组件处理转换后特征的拆分统计,但希望直接通过Transform组件获取拆分统计。

解决方案

原因分析

Transform组件默认只会为用于分析(analyze)的拆分生成统计数据,即使指定了多个转换(transform)拆分,也不会自动为所有转换拆分生成独立的统计子文件夹。这是因为TFDV统计计算在Transform组件中绑定到分析阶段,而非转换阶段的每个拆分。

直接通过Transform组件获取拆分统计的方法

要让Transform组件为所有转换拆分生成独立的post-transform统计,需修改SplitsConfig配置,确保每个需要统计的拆分都被包含在analyze列表中:

transform = tfx.components.Transform(
  examples=example_gen.outputs['examples'],
  schema=schema_gen.outputs['schema'],
  disable_statistics=False,
  splits_config= transform_pb2.SplitsConfig(
        # 同时将train和eval加入analyze列表
        analyze=['train', 'eval'], 
        transform=['train', 'eval']),
  module_file=_transformer_module_file)

配置完成后,Transform组件会分别为train和eval拆分生成对应的Split-train和Split-eval子文件夹,每个文件夹下都会有对应的FeaturesStats.pb文件。

注意事项

  • 当将多个拆分加入analyze列表时,Transform会为每个拆分单独运行TFDV统计计算,会增加一定计算开销,但能满足获取拆分统计的需求。
  • 如果仍希望仅使用train拆分进行分析(避免数据泄露),临时方案(禁用Transform统计+单独定义StatisticsGen处理转换后数据)更合理,强制用eval拆分做分析可能引入数据泄露风险。

内容的提问来源于stack exchange,提问作者Youcef Kacer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 21:50:37