From b658ab40c0320d7038c5e0b260167cd2c6a1ea36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Geron?= Date: Mon, 21 Feb 2022 16:43:52 +1300 Subject: [PATCH] Add workaround for StringLookup in Sequential model issue --- 13_loading_and_preprocessing_data.ipynb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/13_loading_and_preprocessing_data.ipynb b/13_loading_and_preprocessing_data.ipynb index ba4ab7f..de45fd6 100644 --- a/13_loading_and_preprocessing_data.ipynb +++ b/13_loading_and_preprocessing_data.ipynb @@ -2654,7 +2654,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**Warning**: there's currently a bug in TensorFlow 2.8.0 ([issue #54459](https://github.com/tensorflow/tensorflow/issues/54459)) which prevents using a `StringLookup` layer inside a model, so the next 4 cells will fail. If you run into this issue, you must either skip these cells, or downgrade to TensorFlow 2.7.1 (e.g., using `%pip install tensorflow~=2.7.1`) and run the notebook again. I'll update this notebook as soon as the bug is fixed, or when a better workaround exists." + "**Warning**: there's a bug in Keras 2.8.0 ([issue #16101](https://github.com/keras-team/keras/issues/16101)) which prevents using a `StringLookup` layer as the first layer of a `Sequential` model. Luckily, there's a simple workaround: just add an `InputLayer` as the first layer." ] }, { @@ -2682,11 +2682,12 @@ "str_lookup_layer = tf.keras.layers.StringLookup()\n", "str_lookup_layer.adapt(ocean_prox)\n", "lookup_and_embed = tf.keras.Sequential([\n", + " tf.keras.layers.InputLayer(input_shape=[], dtype=tf.string), # WORKAROUND\n", " str_lookup_layer,\n", " tf.keras.layers.Embedding(input_dim=str_lookup_layer.vocabulary_size(),\n", " output_dim=2)\n", "])\n", - "lookup_and_embed(np.array([[\"<1H OCEAN\"], [\"ISLAND\"], [\"<1H OCEAN\"]]))" + "lookup_and_embed(np.array([\"<1H OCEAN\", \"ISLAND\", \"<1H OCEAN\"]))" ] }, {