エバリュエーター TFX パイプライン コンポーネント

Evaluator TFX パイプライン コンポーネントは、モデルのトレーニング結果に対して詳細な分析を実行し、データのサブセットに対してモデルがどのように実行されるかを理解するのに役立ちます。また、エバリュエーターは、エクスポートされたモデルを検証して、本番環境にプッシュするのに「十分な」モデルであることを確認するのにも役立ちます。

検証が有効になっている場合、エバリュエーターは新しいモデルをベースライン (現在提供されているモデルなど) と比較して、ベースラインと比較して「十分に優れている」かどうかを判断します。これは、評価データセットで両方のモデルを評価し、メトリクス (AUC、損失など) に基づいてパフォーマンスを計算することによって行われます。新しいモデルのメトリクスが、ベースライン モデルと比較して開発者が指定した基準を満たしている場合 (AUC が低くないなど)、モデルは「良好」 (良好とマークされます) となり、モデルを運用環境にプッシュしても問題がないことをプッシャーに示します。

  • 消費するもの:
    • Exampleからの eval の分割
    • Trainerからのトレーニング済みモデル
    • 以前に祝福されたモデル (検証が実行される場合)
  • 放出:

エバリュエーターと TensorFlow モデル分析

Evaluator は、 TensorFlow モデル分析ライブラリを活用して分析を実行し、スケーラブルな処理のためにApache Beamを使用します。

エバリュエーターコンポーネントの使用

Evaluator パイプライン コンポーネントは通常、展開が非常に簡単で、ほとんどの作業が Evaluator TFX コンポーネントによって実行されるため、カスタマイズはほとんど必要ありません。

エバリュエーターを設定するには、次の情報が必要です。

検証を含める場合は、次の追加情報が必要です。

有効にすると、定義されたすべてのメトリクスとスライスに対して検証が実行されます。

典型的なコードは次のようになります。

import tensorflow_model_analysis as tfma
...

# For TFMA evaluation

eval_config = tfma.EvalConfig(
    model_specs=[
        # This assumes a serving model with signature 'serving_default'. If
        # using estimator based EvalSavedModel, add signature_name='eval' and
        # remove the label_key. Note, if using a TFLite model, then you must set
        # model_type='tf_lite'.
        tfma.ModelSpec(label_key='<label_key>')
    ],
    metrics_specs=[
        tfma.MetricsSpec(
            # The metrics added here are in addition to those saved with the
            # model (assuming either a keras model or EvalSavedModel is used).
            # Any metrics added into the saved model (for example using
            # model.compile(..., metrics=[...]), etc) will be computed
            # automatically.
            metrics=[
                tfma.MetricConfig(class_name='ExampleCount'),
                tfma.MetricConfig(
                    class_name='BinaryAccuracy',
                    threshold=tfma.MetricThreshold(
                        value_threshold=tfma.GenericValueThreshold(
                            lower_bound={'value': 0.5}),
                        change_threshold=tfma.GenericChangeThreshold(
                            direction=tfma.MetricDirection.HIGHER_IS_BETTER,
                            absolute={'value': -1e-10})))
            ]
        )
    ],
    slicing_specs=[
        # An empty slice spec means the overall slice, i.e. the whole dataset.
        tfma.SlicingSpec(),
        # Data can be sliced along a feature column. In this case, data is
        # sliced along feature column trip_start_hour.
        tfma.SlicingSpec(feature_keys=['trip_start_hour'])
    ])

# The following component is experimental and may change in the future. This is
# required to specify the latest blessed model will be used as the baseline.
model_resolver = Resolver(
      strategy_class=dsl.experimental.LatestBlessedModelStrategy,
      model=Channel(type=Model),
      model_blessing=Channel(type=ModelBlessing)
).with_id('latest_blessed_model_resolver')

model_analyzer = Evaluator(
      examples=examples_gen.outputs['examples'],
      model=trainer.outputs['model'],
      baseline_model=model_resolver.outputs['model'],
      # Change threshold will be ignored if there is no baseline (first run).
      eval_config=eval_config)

エバリュエーターは、 TFMA を使用してロードできるEvalResult (検証が使用された場合はオプションでValidationResult ) を生成します。以下は、結果を Jupyter ノートブックにロードする方法の例です。

import tensorflow_model_analysis as tfma

output_path = evaluator.outputs['evaluation'].get()[0].uri

# Load the evaluation results.
eval_result = tfma.load_eval_result(output_path)

# Visualize the metrics and plots using tfma.view.render_slicing_metrics,
# tfma.view.render_plot, etc.
tfma.view.render_slicing_metrics(tfma_result)
...

# Load the validation results
validation_result = tfma.load_validation_result(output_path)
if not validation_result.validation_ok:
  ...

詳細については、 Evaluator API リファレンスを参照してください。