From 9d99ae9f9fefa0d2ef1c124e5cec860a789c7da9 Mon Sep 17 00:00:00 2001 From: Ian Beauregard Date: Mon, 19 Oct 2020 12:38:17 -0400 Subject: [PATCH 1/6] Correct small coding typo --- 16_nlp_with_rnns_and_attention.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/16_nlp_with_rnns_and_attention.ipynb b/16_nlp_with_rnns_and_attention.ipynb index 328e421..7944feb 100644 --- a/16_nlp_with_rnns_and_attention.ipynb +++ b/16_nlp_with_rnns_and_attention.ipynb @@ -1383,7 +1383,7 @@ "outputs": [], "source": [ "def string_to_ids(s, chars=POSSIBLE_CHARS):\n", - " return [POSSIBLE_CHARS.index(c) for c in s]" + " return [chars.index(c) for c in s]" ] }, { From 7848437dc23db090f8947db3ab919a750c6906a7 Mon Sep 17 00:00:00 2001 From: Ian Beauregard Date: Mon, 19 Oct 2020 12:44:33 -0400 Subject: [PATCH 2/6] Correct typo --- 16_nlp_with_rnns_and_attention.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/16_nlp_with_rnns_and_attention.ipynb b/16_nlp_with_rnns_and_attention.ipynb index 7944feb..cd719a5 100644 --- a/16_nlp_with_rnns_and_attention.ipynb +++ b/16_nlp_with_rnns_and_attention.ipynb @@ -1452,7 +1452,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "What classes does it belong to?" + "What class does it belong to?" ] }, { From a2ffc37d2f4e2ff1be5ddd0b64ad849ebc81e402 Mon Sep 17 00:00:00 2001 From: Ian Beauregard Date: Mon, 19 Oct 2020 13:33:35 -0400 Subject: [PATCH 3/6] Modify creation of possible char list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I concatenated the string of all digits (+ comma and space) to the argument of function sorted ∘ set. Also, the digit '0' was written twice in the digit string. --- 16_nlp_with_rnns_and_attention.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/16_nlp_with_rnns_and_attention.ipynb b/16_nlp_with_rnns_and_attention.ipynb index cd719a5..b682c3e 100644 --- a/16_nlp_with_rnns_and_attention.ipynb +++ b/16_nlp_with_rnns_and_attention.ipynb @@ -1599,7 +1599,7 @@ "metadata": {}, "outputs": [], "source": [ - "INPUT_CHARS = \"\".join(sorted(set(\"\".join(MONTHS)))) + \"01234567890, \"\n", + "INPUT_CHARS = \"\".join(sorted(set(\"\".join(MONTHS) + \"0123456789, \")))\n", "INPUT_CHARS" ] }, From e0cae0c7beaf144f138c486a39d693c03e8f89a0 Mon Sep 17 00:00:00 2001 From: Ian Beauregard Date: Mon, 19 Oct 2020 14:19:42 -0400 Subject: [PATCH 4/6] Replace deprecated method See https://www.tensorflow.org/api_docs/python/tf/keras/Sequential?hl=en#predict_classes. --- 16_nlp_with_rnns_and_attention.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/16_nlp_with_rnns_and_attention.ipynb b/16_nlp_with_rnns_and_attention.ipynb index b682c3e..f7baa44 100644 --- a/16_nlp_with_rnns_and_attention.ipynb +++ b/16_nlp_with_rnns_and_attention.ipynb @@ -353,7 +353,7 @@ "outputs": [], "source": [ "X_new = preprocess([\"How are yo\"])\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 +1785,7 @@ "metadata": {}, "outputs": [], "source": [ - "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 +1819,7 @@ "metadata": {}, "outputs": [], "source": [ - "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 +1847,7 @@ "\n", "def convert_date_strs(date_strs):\n", " X = prepare_date_strs_padded(date_strs)\n", - " ids = model.predict_classes(X)\n", + " ids = np.argmax(model.predict(X), axis=-1)\n", " return ids_to_date_strs(ids)" ] }, From 2c700450b5d048eddeb3bf542692243570f9e305 Mon Sep 17 00:00:00 2001 From: Ian Beauregard Date: Mon, 19 Oct 2020 17:17:35 -0400 Subject: [PATCH 5/6] Change Embedding's input_dim argument Wrong argument for the decoder's embedding layer. --- 16_nlp_with_rnns_and_attention.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/16_nlp_with_rnns_and_attention.ipynb b/16_nlp_with_rnns_and_attention.ipynb index f7baa44..562b856 100644 --- a/16_nlp_with_rnns_and_attention.ipynb +++ b/16_nlp_with_rnns_and_attention.ipynb @@ -2063,7 +2063,7 @@ " len(INPUT_CHARS) + 1, encoder_embedding_size)(encoder_inputs)\n", "\n", "decoder_embedding_layer = keras.layers.Embedding(\n", - " len(INPUT_CHARS) + 2, decoder_embedding_size)\n", + " len(OUTPUT_CHARS) + 2, decoder_embedding_size)\n", "decoder_embeddings = decoder_embedding_layer(decoder_inputs)\n", "\n", "encoder = keras.layers.LSTM(units, return_state=True)\n", @@ -2260,7 +2260,7 @@ " len(INPUT_CHARS) + 1, encoder_embedding_size)(encoder_inputs)\n", "\n", "decoder_embedding_layer = keras.layers.Embedding(\n", - " len(INPUT_CHARS) + 2, decoder_embedding_size)\n", + " len(OUTPUT_CHARS) + 2, decoder_embedding_size)\n", "decoder_embeddings = decoder_embedding_layer(decoder_inputs)\n", "\n", "encoder = keras.layers.LSTM(units, return_state=True)\n", From daf309c2bb7d747f2a2d0283103ce20ba6bd3d99 Mon Sep 17 00:00:00 2001 From: Ian Beauregard Date: Tue, 20 Oct 2020 12:08:21 -0400 Subject: [PATCH 6/6] Install transformers library --- 16_nlp_with_rnns_and_attention.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/16_nlp_with_rnns_and_attention.ipynb b/16_nlp_with_rnns_and_attention.ipynb index 562b856..945bc5f 100644 --- a/16_nlp_with_rnns_and_attention.ipynb +++ b/16_nlp_with_rnns_and_attention.ipynb @@ -2588,6 +2588,7 @@ "metadata": {}, "outputs": [], "source": [ + "!pip install -q -U transformers\n", "from transformers import TFOpenAIGPTLMHeadModel\n", "\n", "model = TFOpenAIGPTLMHeadModel.from_pretrained(\"openai-gpt\")"