Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"FeatureSpace advanced use cases" Keras code example - Fixing typos a… #1482

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions examples/structured_data/feature_space_advanced.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
Title: FeatureSpace avanced use cases
Title: FeatureSpace advanced use cases
Author: [Dimitre Oliveira](https://www.linkedin.com/in/dimitre-oliveira-7a1a0113a/)
Date created: 2023/07/01
Last modified: 2023/07/01
Last modified: 2023/08/04
Description: How to use FeatureSpace for advanced preprocessing use cases.
Accelerator: None
"""
Expand All @@ -12,7 +12,7 @@
This example is an extension of the
[Structured data classification with FeatureSpace](https://keras.io/examples/structured_data/structured_data_classification_with_feature_space/)
code example, and here we will extend it to cover more complex use
cases of the [`keras.utils.FeatureSpace`](https://keras.io/api/utils/feature_space/)
cases of the [keras.utils.FeatureSpace](https://keras.io/api/utils/feature_space/)
preprocessing utility, like feature hashing, feature crosses, handling missing values and
integrating [Keras preprocessing layers](https://keras.io/guides/preprocessing_layers/)
with FeatureSpace.
Expand Down Expand Up @@ -113,7 +113,7 @@
"""

print(f"Dataframe shape: {dataframe.shape}")
display(dataframe.head())
dataframe.head().T

"""
The column, "y", indicates whether the client has subscribed a term deposit or not.
Expand All @@ -137,7 +137,7 @@
## Generating TF datasets

Let's generate
[`tf.data.Dataset`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset) objects
[tf.data.Dataset](https://www.tensorflow.org/api_docs/python/tf/data/Dataset) objects
for each dataframe, since our target column `y` is a string we also need to encode it as
an integer to be able to train our model with it. To achieve this we will create a
`StringLookup` layer that will map the strings "no" and "yes" into "0" and "1"
Expand Down Expand Up @@ -362,7 +362,7 @@ def example_feature_space(dataset, feature_space, feature_names):
your own custom Keras preprocessing layers and use it in the same way.

Here we are going to use the
[`tf.keras.layers.TextVectorization`](https://keras.io/api/layers/preprocessing_layers/text/text_vectorization/#textvectorization-class)
[tf.keras.layers.TextVectorization](https://keras.io/api/layers/preprocessing_layers/text/text_vectorization/#textvectorization-class)
preprocessing layer to create a TF-IDF
feature from our data. Note that this feature is not a really good use case for TF-IDF,
this is just for demonstration purposes.
Expand Down Expand Up @@ -478,7 +478,7 @@ def example_feature_space(dataset, feature_space, feature_names):
if you need to re-run the preprocessing step, and mainly for model deployment, where by
loading it you can be sure that you will be applying the same preprocessing steps don't
matter the device or environment, this is a great way to reduce
[training/servingskew](https://developers.google.com/machine-learning/guides/rules-of-ml#training-serving_skew).
[training-serving skew](https://developers.google.com/machine-learning/guides/rules-of-ml#training-serving_skew).
"""

feature_space.save("myfeaturespace.keras")
Expand Down
14 changes: 7 additions & 7 deletions examples/structured_data/ipynb/feature_space_advanced.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"colab_type": "text"
},
"source": [
"# FeatureSpace avanced use cases\n",
"# FeatureSpace advanced use cases\n",
"\n",
"**Author:** [Dimitre Oliveira](https://www.linkedin.com/in/dimitre-oliveira-7a1a0113a/)<br>\n",
"**Date created:** 2023/07/01<br>\n",
"**Last modified:** 2023/07/01<br>\n",
"**Last modified:** 2023/08/04<br>\n",
"**Description:** How to use FeatureSpace for advanced preprocessing use cases."
]
},
Expand All @@ -25,7 +25,7 @@
"This example is an extension of the\n",
"[Structured data classification with FeatureSpace](https://keras.io/examples/structured_data/structured_data_classification_with_feature_space/)\n",
"code example, and here we will extend it to cover more complex use\n",
"cases of the [`keras.utils.FeatureSpace`](https://keras.io/api/utils/feature_space/)\n",
"cases of the [keras.utils.FeatureSpace](https://keras.io/api/utils/feature_space/)\n",
"preprocessing utility, like feature hashing, feature crosses, handling missing values and\n",
"integrating [Keras preprocessing layers](https://keras.io/guides/preprocessing_layers/)\n",
"with FeatureSpace.\n",
Expand Down Expand Up @@ -185,7 +185,7 @@
"outputs": [],
"source": [
"print(f\"Dataframe shape: {dataframe.shape}\")\n",
"display(dataframe.head())"
"dataframe.head().T"
]
},
{
Expand Down Expand Up @@ -234,7 +234,7 @@
"## Generating TF datasets\n",
"\n",
"Let's generate\n",
"[`tf.data.Dataset`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset) objects\n",
"[tf.data.Dataset](https://www.tensorflow.org/api_docs/python/tf/data/Dataset) objects\n",
"for each dataframe, since our target column `y` is a string we also need to encode it as\n",
"an integer to be able to train our model with it. To achieve this we will create a\n",
"`StringLookup` layer that will map the strings \"no\" and \"yes\" into \"0\" and \"1\"\n",
Expand Down Expand Up @@ -600,7 +600,7 @@
"your own custom Keras preprocessing layers and use it in the same way.\n",
"\n",
"Here we are going to use the\n",
"[`tf.keras.layers.TextVectorization`](https://keras.io/api/layers/preprocessing_layers/text/text_vectorization/#textvectorization-class)\n",
"[tf.keras.layers.TextVectorization](https://keras.io/api/layers/preprocessing_layers/text/text_vectorization/#textvectorization-class)\n",
"preprocessing layer to create a TF-IDF\n",
"feature from our data. Note that this feature is not a really good use case for TF-IDF,\n",
"this is just for demonstration purposes."
Expand Down Expand Up @@ -771,7 +771,7 @@
"if you need to re-run the preprocessing step, and mainly for model deployment, where by\n",
"loading it you can be sure that you will be applying the same preprocessing steps don't\n",
"matter the device or environment, this is a great way to reduce\n",
"[training/servingskew](https://developers.google.com/machine-learning/guides/rules-of-ml#training-serving_skew)."
"[training-serving skew](https://developers.google.com/machine-learning/guides/rules-of-ml#training-serving_skew)."
]
},
{
Expand Down
Loading
Loading