TensorFlow Transform

TensorFlow Transform 是一個使用 TensorFlow 預先處理資料的程式庫。tf.Transform 適用於需要完整傳遞的資料,例如

  • 依平均值和標準差將輸入值標準化。
  • 透過產生所有輸入值的詞彙表,將字串轉換為整數。
  • 透過根據觀察到的資料分佈將浮點數指派給儲存區,將其轉換為整數。

TensorFlow 內建支援對單一範例或批次範例進行操作。tf.Transform 擴充了這些功能,以支援對範例資料進行完整傳遞。

tf.Transform 的輸出會匯出為 TensorFlow 圖表,以用於訓練和服務。由於在訓練和服務階段套用了相同的轉換,因此針對訓練和服務使用相同的圖表可以防止偏差。

如需 tf.Transform 的簡介,請參閱 TFX 開發人員高峰會談論 TFX 的 tf.Transform 章節 (連結:link)。

安裝

tensorflow-transform PyPI 套件是安裝 tf.Transform 的建議方式

pip install tensorflow-transform

從原始碼建構 TFT

若要從原始碼建構,請按照下列步驟執行:執行下列命令來建立虛擬環境

python3 -m venv <virtualenv_name>
source <virtualenv_name>/bin/activate
pip3 install setuptools wheel
git clone https://github.com/tensorflow/transform.git
cd transform
python3 setup.py bdist_wheel

這會在 dist 目錄中建構 TFT wheel。若要從 dist 目錄安裝 wheel,請執行下列命令

cd dist
pip3 install tensorflow_transform-<version>-py3-none-any.whl

每晚套件

TFT 也會在 Google Cloud 上的 https://pypi-nightly.tensorflow.org 上託管每晚套件。若要安裝最新的每晚套件,請使用下列命令

pip install --extra-index-url https://pypi-nightly.tensorflow.org/simple tensorflow-transform

這會安裝 TFT 主要依附元件 (例如 TensorFlow Metadata (TFMD)、TFX Basic Shared Libraries (TFX-BSL)) 的每晚套件。

值得注意的依附元件

TensorFlow 為必要項目。

Apache Beam 為必要項目;這是支援有效分散式運算的方式。根據預設,Apache Beam 在本機模式中執行,但也可以使用 Google Cloud Dataflow 和其他 Apache Beam 執行器在分散式模式中執行。

Apache Arrow 也是必要項目。TFT 使用 Arrow 在內部表示資料,以便使用向量化 numpy 函式。

相容版本

下表是彼此相容的 tf.Transform 套件版本。這是由我們的測試架構所決定,但其他未經測試的組合也可能有效。

tensorflow-transform apache-beam[gcp] pyarrow tensorflow tensorflow-metadata tfx-bsl
GitHub master 2.47.0 10.0.0 nightly (2.x) 1.15.0 1.15.1
1.15.0 2.47.0 10.0.0 2.15 1.15.0 1.15.1
1.14.0 2.47.0 10.0.0 2.13 1.14.0 1.14.0
1.13.0 2.41.0 6.0.0 2.12 1.13.1 1.13.0
1.12.0 2.41.0 6.0.0 2.11 1.12.0 1.12.0
1.11.0 2.41.0 6.0.0 1.15.5 / 2.10 1.11.0 1.11.0
1.10.0 2.40.0 6.0.0 1.15.5 / 2.9 1.10.0 1.10.0
1.9.0 2.38.0 5.0.0 1.15.5 / 2.9 1.9.0 1.9.0
1.8.0 2.38.0 5.0.0 1.15.5 / 2.8 1.8.0 1.8.0
1.7.0 2.36.0 5.0.0 1.15.5 / 2.8 1.7.0 1.7.0
1.6.1 2.35.0 5.0.0 1.15.5 / 2.8 1.6.0 1.6.0
1.6.0 2.35.0 5.0.0 1.15.5 / 2.7 1.6.0 1.6.0
1.5.0 2.34.0 5.0.0 1.15.2 / 2.7 1.5.0 1.5.0
1.4.1 2.33.0 4.0.1 1.15.2 / 2.6 1.4.0 1.4.0
1.4.0 2.33.0 4.0.1 1.15.2 / 2.6 1.4.0 1.4.0
1.3.0 2.31.0 2.0.0 1.15.2 / 2.6 1.2.0 1.3.0
1.2.0 2.31.0 2.0.0 1.15.2 / 2.5 1.2.0 1.2.0
1.1.1 2.29.0 2.0.0 1.15.2 / 2.5 1.1.0 1.1.1
1.1.0 2.29.0 2.0.0 1.15.2 / 2.5 1.1.0 1.1.0
1.0.0 2.29.0 2.0.0 1.15 / 2.5 1.0.0 1.0.0
0.30.0 2.28.0 2.0.0 1.15 / 2.4 0.30.0 0.30.0
0.29.0 2.28.0 2.0.0 1.15 / 2.4 0.29.0 0.29.0
0.28.0 2.28.0 2.0.0 1.15 / 2.4 0.28.0 0.28.1
0.27.0 2.27.0 2.0.0 1.15 / 2.4 0.27.0 0.27.0
0.26.0 2.25.0 0.17.0 1.15 / 2.3 0.26.0 0.26.0
0.25.0 2.25.0 0.17.0 1.15 / 2.3 0.25.0 0.25.0
0.24.1 2.24.0 0.17.0 1.15 / 2.3 0.24.0 0.24.1
0.24.0 2.23.0 0.17.0 1.15 / 2.3 0.24.0 0.24.0
0.23.0 2.23.0 0.17.0 1.15 / 2.3 0.23.0 0.23.0
0.22.0 2.20.0 0.16.0 1.15 / 2.2 0.22.0 0.22.0
0.21.2 2.17.0 0.15.0 1.15 / 2.1 0.21.0 0.21.3
0.21.0 2.17.0 0.15.0 1.15 / 2.1 0.21.0 0.21.0
0.15.0 2.16.0 0.14.0 1.15 / 2.0 0.15.0 0.15.0
0.14.0 2.14.0 0.14.0 1.14 0.14.0 不適用
0.13.0 2.11.0 不適用 1.13 0.12.1 不適用
0.12.0 2.10.0 不適用 1.12 0.12.0 不適用
0.11.0 2.8.0 不適用 1.11 0.9.0 不適用
0.9.0 2.6.0 不適用 1.9 0.9.0 不適用
0.8.0 2.5.0 不適用 1.8 不適用 不適用
0.6.0 2.4.0 不適用 1.6 不適用 不適用
0.5.0 2.3.0 不適用 1.5 不適用 不適用
0.4.0 2.2.0 不適用 1.4 不適用 不適用
0.3.1 2.1.1 不適用 1.3 不適用 不適用
0.3.0 2.1.1 不適用 1.3 不適用 不適用
0.1.10 2.0.0 不適用 1.0 不適用 不適用

問題

如有任何關於使用 tf.Transform 的問題,請使用 tensorflow-transform 標籤將問題導向 Stack Overflow