Add workaround for StringLookup in Sequential model issue
parent
446fbb81cb
commit
b658ab40c0
|
@ -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\"]))"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue