Update libraries to latest version, including TensorFlow 2.4.1 and Scikit-Learn 0.24.1

main
Aurélien Geron 2021-02-16 15:04:34 +13:00
parent 198227f586
commit f86635b233
3 changed files with 39 additions and 11 deletions

View File

@ -1366,7 +1366,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.7.9"
},
"nav_menu": {},
"toc": {

View File

@ -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": {

View File

@ -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": {