From f86635b2332193ea8ec71c1064a0697857bab927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Geron?= Date: Tue, 16 Feb 2021 15:04:34 +1300 Subject: [PATCH] Update libraries to latest version, including TensorFlow 2.4.1 and Scikit-Learn 0.24.1 --- 14_deep_computer_vision_with_cnns.ipynb | 2 +- ...essing_sequences_using_rnns_and_cnns.ipynb | 5 ++- 16_nlp_with_rnns_and_attention.ipynb | 43 +++++++++++++++---- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/14_deep_computer_vision_with_cnns.ipynb b/14_deep_computer_vision_with_cnns.ipynb index 860ce3a..c1b9e2f 100644 --- a/14_deep_computer_vision_with_cnns.ipynb +++ b/14_deep_computer_vision_with_cnns.ipynb @@ -1366,7 +1366,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.7.9" }, "nav_menu": {}, "toc": { diff --git a/15_processing_sequences_using_rnns_and_cnns.ipynb b/15_processing_sequences_using_rnns_and_cnns.ipynb index 10933e5..8441ada 100644 --- a/15_processing_sequences_using_rnns_and_cnns.ipynb +++ b/15_processing_sequences_using_rnns_and_cnns.ipynb @@ -1868,7 +1868,8 @@ " arpegio = tf.reshape(arpegio, [1, -1])\n", " for chord in range(length):\n", " for note in range(4):\n", - " next_note = model.predict_classes(arpegio)[:1, -1:]\n", + " #next_note = model.predict_classes(arpegio)[:1, -1:]\n", + " next_note = np.argmax(model.predict(arpegio), axis=-1)[:1, -1:]\n", " arpegio = tf.concat([arpegio, next_note], axis=1)\n", " arpegio = tf.where(arpegio == 0, arpegio, arpegio + min_note - 1)\n", " return tf.reshape(arpegio, shape=[-1, 4])" @@ -2010,7 +2011,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.7.9" }, "nav_menu": {}, "toc": { diff --git a/16_nlp_with_rnns_and_attention.ipynb b/16_nlp_with_rnns_and_attention.ipynb index 328e421..3efe4d5 100644 --- a/16_nlp_with_rnns_and_attention.ipynb +++ b/16_nlp_with_rnns_and_attention.ipynb @@ -309,6 +309,20 @@ "## Creating and Training the Model" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Warning**: the following code may take up to 24 hours to run, depending on your hardware. If you use a GPU, it may take just 1 or 2 hours, or less." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Note**: the `GRU` class will only use the GPU (if you have one) when using the default values for the following arguments: `activation`, `recurrent_activation`, `recurrent_dropout`, `unroll`, `use_bias` and `reset_after`. This is why I commented out `recurrent_dropout=0.2` (compared to the book)." + ] + }, { "cell_type": "code", "execution_count": 18, @@ -317,9 +331,11 @@ "source": [ "model = keras.models.Sequential([\n", " keras.layers.GRU(128, return_sequences=True, input_shape=[None, max_id],\n", - " dropout=0.2, recurrent_dropout=0.2),\n", + " #dropout=0.2, recurrent_dropout=0.2),\n", + " dropout=0.2),\n", " keras.layers.GRU(128, return_sequences=True,\n", - " dropout=0.2, recurrent_dropout=0.2),\n", + " #dropout=0.2, recurrent_dropout=0.2),\n", + " dropout=0.2),\n", " keras.layers.TimeDistributed(keras.layers.Dense(max_id,\n", " activation=\"softmax\"))\n", "])\n", @@ -346,6 +362,13 @@ " return tf.one_hot(X, max_id)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Warning**: the `predict_classes()` method is deprecated. Instead, we must use `np.argmax(model.predict(X_new), axis=-1)`." + ] + }, { "cell_type": "code", "execution_count": 20, @@ -353,7 +376,8 @@ "outputs": [], "source": [ "X_new = preprocess([\"How are yo\"])\n", - "Y_pred = model.predict_classes(X_new)\n", + "#Y_pred = model.predict_classes(X_new)\n", + "Y_pred = np.argmax(model.predict(X_new), axis=-1)\n", "tokenizer.sequences_to_texts(Y_pred + 1)[0][-1] # 1st sentence, last char" ] }, @@ -1785,7 +1809,8 @@ "metadata": {}, "outputs": [], "source": [ - "ids = model.predict_classes(X_new)\n", + "#ids = model.predict_classes(X_new)\n", + "ids = np.argmax(model.predict(X_new), axis=-1)\n", "for date_str in ids_to_date_strs(ids):\n", " print(date_str)" ] @@ -1819,7 +1844,8 @@ "metadata": {}, "outputs": [], "source": [ - "ids = model.predict_classes(X_new)\n", + "#ids = model.predict_classes(X_new)\n", + "ids = np.argmax(model.predict(X_new), axis=-1)\n", "for date_str in ids_to_date_strs(ids):\n", " print(date_str)" ] @@ -1847,7 +1873,8 @@ "\n", "def convert_date_strs(date_strs):\n", " X = prepare_date_strs_padded(date_strs)\n", - " ids = model.predict_classes(X)\n", + " #ids = model.predict_classes(X)\n", + " ids = np.argmax(model.predict(X), axis=-1)\n", " return ids_to_date_strs(ids)" ] }, @@ -2226,7 +2253,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**Warning**: due to a TF bug, this version only works using TensorFlow 2.2." + "**Warning**: due to a TF bug, this version only works using TensorFlow 2.2 or above." ] }, { @@ -2711,7 +2738,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.7.9" }, "nav_menu": {}, "toc": {