\n",
"
\n",
" 特征列 | \n",
" Keras 层 | \n",
"
\n",
" \n",
" `tf.feature_column.bucketized_column` | \n",
" `tf.keras.layers.Discretization` | \n",
"
\n",
" \n",
" `tf.feature_column.categorical_column_with_hash_bucket` | \n",
" `tf.keras.layers.Hashing` | \n",
"
\n",
" \n",
" `tf.feature_column.categorical_column_with_identity` | \n",
" `tf.keras.layers.CategoryEncoding` | \n",
"
\n",
" \n",
" `tf.feature_column.categorical_column_with_vocabulary_file` | \n",
" `tf.keras.layers.StringLookup` 或 `tf.keras.layers.IntegerLookup` | \n",
"
\n",
" \n",
" `tf.feature_column.categorical_column_with_vocabulary_list` | \n",
" `tf.keras.layers.StringLookup` 或 `tf.keras.layers.IntegerLookup` | \n",
"
\n",
" \n",
" `tf.feature_column.crossed_column` | \n",
" `tf.keras.layers.experimental.preprocessing.HashedCrossing` | \n",
"
\n",
" \n",
" `tf.feature_column.embedding_column` | \n",
" `tf.keras.layers.Embedding` | \n",
"
\n",
" \n",
" `tf.feature_column.indicator_column` | \n",
" `output_mode='one_hot'` 或 `output_mode='multi_hot'`* | \n",
"
\n",
" \n",
" `tf.feature_column.numeric_column` | \n",
" `tf.keras.layers.Normalization` | \n",
"
\n",
" \n",
" `tf.feature_column.sequence_categorical_column_with_hash_bucket` | \n",
" `tf.keras.layers.Hashing` | \n",
"
\n",
" \n",
" `tf.feature_column.sequence_categorical_column_with_identity` | \n",
" `tf.keras.layers.CategoryEncoding` | \n",
"
\n",
" \n",
" `tf.feature_column.sequence_categorical_column_with_vocabulary_file` | \n",
" `tf.keras.layers.StringLookup`、`tf.keras.layers.IntegerLookup` 或 `tf.keras.layer.TextVectorization`† | \n",
"
\n",
" \n",
" `tf.feature_column.sequence_categorical_column_with_vocabulary_list` | \n",
" `tf.keras.layers.StringLookup`、`tf.keras.layers.IntegerLookup` 或 `tf.keras.layer.TextVectorization`† | \n",
"
\n",
" \n",
" `tf.feature_column.sequence_numeric_column` | \n",
" `tf.keras.layers.Normalization` | \n",
"
\n",
" \n",
" `tf.feature_column.weighted_categorical_column` | \n",
" `tf.keras.layers.CategoryEncoding` | \n",
"
\n",
"\n",
"
\n",
"\n",
"* `output_mode` 可以传递给 `tf.keras.layers.CategoryEncoding`、`tf.keras.layers.StringLookup`、`tf.keras.layers.IntegerLookup` 和 `tf.keras.layers.TextVectorization`。\n",
"\n",
"† `tf.keras.layers.TextVectorization` 可以直接处理自由格式的文本输入(例如,整个句子或段落)。这不是 TensorFlow 1 中分类序列处理的一对一替代,但可以为临时文本预处理提供方便的替代。\n",
"\n",
"注:线性 Estimator(例如 `tf.estimator.LinearClassifier`)可以在没有 `embedding_column` 或 `indicator_column` 的情况下处理直接分类输入(整数索引)。但是,整数索引不能直接传递给 `tf.keras.layers.Dense` 或 `tf.keras.experimental.LinearModel`。在调用 `Dense` 或 `LinearModel` 之前,应当首先使用 `tf.layers.CategoryEncoding` 对这些输入进行编码,其中 `output_mode='count'`(如果类别大小很大,则为 `sparse=True`)。"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "AQCJ6lM3YDq_"
},
"source": [
"## 后续步骤\n",
"\n",
"- 有关 Keras 预处理层的更多信息,请转到[使用预处理层](https://tensorflow.google.cn/guide/keras/preprocessing_layers)指南。\n",
"- 有关将预处理层应用于结构化数据的更深入示例,请参阅[使用 Keras 预处理层对结构化数据进行分类](../../tutorials/structured_data/preprocessing_layers.ipynb)教程。"
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "migrating_feature_columns.ipynb",
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}