|
674 | 674 | "source": [ |
675 | 675 | "### Keras\n", |
676 | 676 | "\n", |
677 | | - "[tf.keras](https://www.tensorflow.org/guide/keras) is TensorFlow's high-level API for building and training deep learning models. Ragged tensors may be passed as inputs to a Keras model by setting `ragged=True` on `tf.keras.Input` or `tf.keras.layers.InputLayer`. Ragged tensors may also be passed between Keras layers, and returned by Keras models. The following example shows a toy LSTM model that is trained using ragged tensors." |
| 677 | + "[tf.keras](https://www.tensorflow.org/guide/keras) is TensorFlow's high-level API for building and training deep learning models. Ragged tensors can be passed as inputs to a Keras model by using ragged tensors between Keras layers, and returning ragged tensors by Keras models. The following example shows a toy LSTM model that is trained using ragged tensors:" |
678 | 678 | ] |
679 | 679 | }, |
680 | 680 | { |
|
700 | 700 | "\n", |
701 | 701 | "# Build the Keras model.\n", |
702 | 702 | "keras_model = tf.keras.Sequential([\n", |
703 | | - " tf.keras.layers.Input(shape=[None], dtype=tf.int64, ragged=True),\n", |
704 | | - " tf.keras.layers.Embedding(hash_buckets, 16),\n", |
705 | | - " tf.keras.layers.LSTM(32, use_bias=False),\n", |
| 703 | + " tf.keras.layers.Embedding(hash_buckets, 16, input_length=hashed_words.shape[1]),\n", |
| 704 | + " tf.keras.layers.LSTM(32, return_sequences=True, use_bias=False),\n", |
| 705 | + " tf.keras.layers.Flatten(),\n", |
706 | 706 | " tf.keras.layers.Dense(32),\n", |
707 | 707 | " tf.keras.layers.Activation(tf.nn.relu),\n", |
708 | 708 | " tf.keras.layers.Dense(1)\n", |
709 | 709 | "])\n", |
710 | 710 | "\n", |
711 | 711 | "keras_model.compile(loss='binary_crossentropy', optimizer='rmsprop')\n", |
712 | 712 | "keras_model.fit(hashed_words, is_question, epochs=5)\n", |
713 | | - "print(keras_model.predict(hashed_words))" |
| 713 | + "print(keras_model.predict(hashed_words))\n" |
714 | 714 | ] |
715 | 715 | }, |
716 | 716 | { |
|
0 commit comments