commit 5ed300f900e546037cb36da28051baa04232477a Author: Adrian Klessa <50918271+AdrianKlessa@users.noreply.github.com> Date: Sat May 25 15:41:19 2024 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9df665d --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/fra-eng/fra.txt +/fra-eng/_about.txt +/fin-eng/fin.txt +/fin-eng/_about.txt diff --git a/fin-to-en-seq2seq-v1.ipynb b/fin-to-en-seq2seq-v1.ipynb new file mode 100644 index 0000000..b0e54fe --- /dev/null +++ b/fin-to-en-seq2seq-v1.ipynb @@ -0,0 +1,768 @@ +{ + "metadata": { + "kernelspec": { + "language": "python", + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python", + "version": "3.10.13", + "mimetype": "text/x-python", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "pygments_lexer": "ipython3", + "nbconvert_exporter": "python", + "file_extension": ".py" + }, + "kaggle": { + "accelerator": "nvidiaTeslaT4", + "dataSources": [ + { + "sourceId": 8461085, + "sourceType": "datasetVersion", + "datasetId": 5043715 + } + ], + "dockerImageVersionId": 30699, + "isInternetEnabled": true, + "language": "python", + "sourceType": "notebook", + "isGpuEnabled": true + } + }, + "nbformat_minor": 4, + "nbformat": 4, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "### Sprawdzanie zbioru danych" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 1, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "\n", + "training_file = pd.read_csv(\"/kaggle/input/anki-en-fin/fin.txt\", sep='\\t', names=[\"English\",\"Finnish\",\"attribution\"])" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "source": [ + "training_file.head()" + ], + "metadata": { + "execution": { + "iopub.status.busy": "2024-05-25T12:00:07.929498Z", + "iopub.execute_input": "2024-05-25T12:00:07.929855Z", + "iopub.status.idle": "2024-05-25T12:00:07.949697Z", + "shell.execute_reply.started": "2024-05-25T12:00:07.929826Z", + "shell.execute_reply": "2024-05-25T12:00:07.948716Z" + }, + "trusted": true + }, + "execution_count": 2, + "outputs": [ + { + "execution_count": 2, + "output_type": "execute_result", + "data": { + "text/plain": " English Finnish attribution\n0 Go. Mene. CC-BY 2.0 (France) Attribution: tatoeba.org #2...\n1 Hi. Moro! CC-BY 2.0 (France) Attribution: tatoeba.org #5...\n2 Hi. Terve. CC-BY 2.0 (France) Attribution: tatoeba.org #5...\n3 Run! Juokse! CC-BY 2.0 (France) Attribution: tatoeba.org #9...\n4 Run! Juoskaa! CC-BY 2.0 (France) Attribution: tatoeba.org #9...", + "text/html": "
\n | English | \nFinnish | \nattribution | \n
---|---|---|---|
0 | \nGo. | \nMene. | \nCC-BY 2.0 (France) Attribution: tatoeba.org #2... | \n
1 | \nHi. | \nMoro! | \nCC-BY 2.0 (France) Attribution: tatoeba.org #5... | \n
2 | \nHi. | \nTerve. | \nCC-BY 2.0 (France) Attribution: tatoeba.org #5... | \n
3 | \nRun! | \nJuokse! | \nCC-BY 2.0 (France) Attribution: tatoeba.org #9... | \n
4 | \nRun! | \nJuoskaa! | \nCC-BY 2.0 (France) Attribution: tatoeba.org #9... | \n
Model: \"functional_1\"\n
\n"
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": "┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓\n┃\u001B[1m \u001B[0m\u001B[1mLayer (type) \u001B[0m\u001B[1m \u001B[0m┃\u001B[1m \u001B[0m\u001B[1mOutput Shape \u001B[0m\u001B[1m \u001B[0m┃\u001B[1m \u001B[0m\u001B[1m Param #\u001B[0m\u001B[1m \u001B[0m┃\u001B[1m \u001B[0m\u001B[1mConnected to \u001B[0m\u001B[1m \u001B[0m┃\n┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩\n│ input_layer │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m87\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ - │\n│ (\u001B[38;5;33mInputLayer\u001B[0m) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ input_layer_1 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m79\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ - │\n│ (\u001B[38;5;33mInputLayer\u001B[0m) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ lstm (\u001B[38;5;33mLSTM\u001B[0m) │ [(\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m256\u001B[0m), │ \u001B[38;5;34m352,256\u001B[0m │ input_layer[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n│ │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m256\u001B[0m), │ │ │\n│ │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m256\u001B[0m)] │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ lstm_1 (\u001B[38;5;33mLSTM\u001B[0m) │ [(\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;45mNone\u001B[0m, │ \u001B[38;5;34m344,064\u001B[0m │ input_layer_1[\u001B[38;5;34m0\u001B[0m]… │\n│ │ \u001B[38;5;34m256\u001B[0m), (\u001B[38;5;45mNone\u001B[0m, │ │ lstm[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m1\u001B[0m], │\n│ │ \u001B[38;5;34m256\u001B[0m), (\u001B[38;5;45mNone\u001B[0m, │ │ lstm[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m2\u001B[0m] │\n│ │ \u001B[38;5;34m256\u001B[0m)] │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dense (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m79\u001B[0m) │ \u001B[38;5;34m20,303\u001B[0m │ lstm_1[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n└─────────────────────┴───────────────────┴────────────┴───────────────────┘\n",
+ "text/html": "┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓\n┃ Layer (type) ┃ Output Shape ┃ Param # ┃ Connected to ┃\n┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩\n│ input_layer │ (None, None, 87) │ 0 │ - │\n│ (InputLayer) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ input_layer_1 │ (None, None, 79) │ 0 │ - │\n│ (InputLayer) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ lstm (LSTM) │ [(None, 256), │ 352,256 │ input_layer[0][0] │\n│ │ (None, 256), │ │ │\n│ │ (None, 256)] │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ lstm_1 (LSTM) │ [(None, None, │ 344,064 │ input_layer_1[0]… │\n│ │ 256), (None, │ │ lstm[0][1], │\n│ │ 256), (None, │ │ lstm[0][2] │\n│ │ 256)] │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dense (Dense) │ (None, None, 79) │ 20,303 │ lstm_1[0][0] │\n└─────────────────────┴───────────────────┴────────────┴───────────────────┘\n\n" + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": "\u001B[1m Total params: \u001B[0m\u001B[38;5;34m716,623\u001B[0m (2.73 MB)\n", + "text/html": "
Total params: 716,623 (2.73 MB)\n\n" + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": "\u001B[1m Trainable params: \u001B[0m\u001B[38;5;34m716,623\u001B[0m (2.73 MB)\n", + "text/html": "
Trainable params: 716,623 (2.73 MB)\n\n" + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": "\u001B[1m Non-trainable params: \u001B[0m\u001B[38;5;34m0\u001B[0m (0.00 B)\n", + "text/html": "
Non-trainable params: 0 (0.00 B)\n\n" + }, + "metadata": {} + } + ] + }, + { + "cell_type": "code", + "source": [ + "from tensorflow.python.keras import backend as K\n", + "K._get_available_gpus()" + ], + "metadata": { + "execution": { + "iopub.status.busy": "2024-05-25T12:01:08.192068Z", + "iopub.execute_input": "2024-05-25T12:01:08.192827Z", + "iopub.status.idle": "2024-05-25T12:01:08.199285Z", + "shell.execute_reply.started": "2024-05-25T12:01:08.192792Z", + "shell.execute_reply": "2024-05-25T12:01:08.198269Z" + }, + "trusted": true + }, + "execution_count": 11, + "outputs": [ + { + "execution_count": 11, + "output_type": "execute_result", + "data": { + "text/plain": "['/device:GPU:0', '/device:GPU:1']" + }, + "metadata": {} + } + ] + }, + { + "cell_type": "code", + "source": [ + "model.compile(\n", + " optimizer=\"rmsprop\", loss=\"categorical_crossentropy\", metrics=[\"accuracy\"]\n", + ")\n", + "model.fit(\n", + " [encoder_input_data, decoder_input_data],\n", + " decoder_target_data,\n", + " batch_size=batch_size,\n", + " epochs=epochs,\n", + " validation_split=0.2,\n", + ")\n", + "# Save model\n", + "model.save(\"s2s_fin_en_model.keras\")" + ], + "metadata": { + "execution": { + "iopub.status.busy": "2024-05-25T12:01:15.676471Z", + "iopub.execute_input": "2024-05-25T12:01:15.677157Z", + "iopub.status.idle": "2024-05-25T12:17:10.755065Z", + "shell.execute_reply.started": "2024-05-25T12:01:15.677121Z", + "shell.execute_reply": "2024-05-25T12:17:10.754208Z" + }, + "trusted": true + }, + "execution_count": 12, + "outputs": [ + { + "name": "stdout", + "text": "Epoch 1/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m13s\u001B[0m 44ms/step - accuracy: 0.8327 - loss: 0.9095 - val_accuracy: 0.8553 - val_loss: 0.5346\nEpoch 2/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 35ms/step - accuracy: 0.8559 - loss: 0.5304 - val_accuracy: 0.8693 - val_loss: 0.4829\nEpoch 3/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 36ms/step - accuracy: 0.8537 - loss: 0.5072 - val_accuracy: 0.8797 - val_loss: 0.4209\nEpoch 4/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 36ms/step - accuracy: 0.8820 - loss: 0.4118 - val_accuracy: 0.8870 - val_loss: 0.3939\nEpoch 5/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 36ms/step - accuracy: 0.8880 - loss: 0.3853 - val_accuracy: 0.8893 - val_loss: 0.3766\nEpoch 6/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 37ms/step - accuracy: 0.8908 - loss: 0.3720 - val_accuracy: 0.8925 - val_loss: 0.3642\nEpoch 7/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 37ms/step - accuracy: 0.8940 - loss: 0.3597 - val_accuracy: 0.8950 - val_loss: 0.3552\nEpoch 8/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 37ms/step - accuracy: 0.8981 - loss: 0.3451 - val_accuracy: 0.8980 - val_loss: 0.3441\nEpoch 9/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.8998 - loss: 0.3391 - val_accuracy: 0.9000 - val_loss: 0.3382\nEpoch 10/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m10s\u001B[0m 38ms/step - accuracy: 0.9024 - loss: 0.3299 - val_accuracy: 0.9015 - val_loss: 0.3293\nEpoch 11/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m10s\u001B[0m 38ms/step - accuracy: 0.9042 - loss: 0.3228 - val_accuracy: 0.9042 - val_loss: 0.3219\nEpoch 12/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m10s\u001B[0m 38ms/step - accuracy: 0.9055 - loss: 0.3177 - val_accuracy: 0.9053 - val_loss: 0.3170\nEpoch 13/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m10s\u001B[0m 38ms/step - accuracy: 0.9065 - loss: 0.3134 - val_accuracy: 0.9056 - val_loss: 0.3137\nEpoch 14/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9091 - loss: 0.3051 - val_accuracy: 0.9077 - val_loss: 0.3086\nEpoch 15/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 37ms/step - accuracy: 0.9101 - loss: 0.3007 - val_accuracy: 0.9091 - val_loss: 0.3035\nEpoch 16/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9118 - loss: 0.2943 - val_accuracy: 0.9105 - val_loss: 0.2985\nEpoch 17/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 37ms/step - accuracy: 0.9132 - loss: 0.2899 - val_accuracy: 0.9117 - val_loss: 0.2943\nEpoch 18/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9140 - loss: 0.2867 - val_accuracy: 0.9127 - val_loss: 0.2905\nEpoch 19/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9148 - loss: 0.2837 - val_accuracy: 0.9139 - val_loss: 0.2863\nEpoch 20/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9163 - loss: 0.2783 - val_accuracy: 0.9145 - val_loss: 0.2840\nEpoch 21/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9173 - loss: 0.2747 - val_accuracy: 0.9151 - val_loss: 0.2808\nEpoch 22/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9183 - loss: 0.2706 - val_accuracy: 0.9164 - val_loss: 0.2776\nEpoch 23/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m10s\u001B[0m 38ms/step - accuracy: 0.9192 - loss: 0.2677 - val_accuracy: 0.9172 - val_loss: 0.2748\nEpoch 24/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9200 - loss: 0.2654 - val_accuracy: 0.9180 - val_loss: 0.2725\nEpoch 25/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9205 - loss: 0.2635 - val_accuracy: 0.9190 - val_loss: 0.2694\nEpoch 26/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9219 - loss: 0.2587 - val_accuracy: 0.9191 - val_loss: 0.2675\nEpoch 27/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9221 - loss: 0.2577 - val_accuracy: 0.9194 - val_loss: 0.2677\nEpoch 28/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9230 - loss: 0.2544 - val_accuracy: 0.9202 - val_loss: 0.2638\nEpoch 29/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9234 - loss: 0.2532 - val_accuracy: 0.9212 - val_loss: 0.2614\nEpoch 30/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9240 - loss: 0.2514 - val_accuracy: 0.9217 - val_loss: 0.2597\nEpoch 31/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9248 - loss: 0.2484 - val_accuracy: 0.9215 - val_loss: 0.2588\nEpoch 32/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9257 - loss: 0.2457 - val_accuracy: 0.9222 - val_loss: 0.2573\nEpoch 33/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m10s\u001B[0m 38ms/step - accuracy: 0.9258 - loss: 0.2445 - val_accuracy: 0.9229 - val_loss: 0.2552\nEpoch 34/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m10s\u001B[0m 38ms/step - accuracy: 0.9259 - loss: 0.2444 - val_accuracy: 0.9231 - val_loss: 0.2540\nEpoch 35/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9270 - loss: 0.2415 - val_accuracy: 0.9233 - val_loss: 0.2532\nEpoch 36/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9276 - loss: 0.2389 - val_accuracy: 0.9239 - val_loss: 0.2510\nEpoch 37/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9276 - loss: 0.2385 - val_accuracy: 0.9245 - val_loss: 0.2500\nEpoch 38/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9289 - loss: 0.2343 - val_accuracy: 0.9246 - val_loss: 0.2482\nEpoch 39/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9288 - loss: 0.2344 - val_accuracy: 0.9256 - val_loss: 0.2465\nEpoch 40/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m10s\u001B[0m 38ms/step - accuracy: 0.9291 - loss: 0.2334 - val_accuracy: 0.9255 - val_loss: 0.2454\nEpoch 41/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9293 - loss: 0.2322 - val_accuracy: 0.9258 - val_loss: 0.2444\nEpoch 42/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9300 - loss: 0.2298 - val_accuracy: 0.9258 - val_loss: 0.2439\nEpoch 43/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9301 - loss: 0.2292 - val_accuracy: 0.9262 - val_loss: 0.2432\nEpoch 44/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9305 - loss: 0.2282 - val_accuracy: 0.9261 - val_loss: 0.2432\nEpoch 45/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9309 - loss: 0.2276 - val_accuracy: 0.9269 - val_loss: 0.2411\nEpoch 46/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9316 - loss: 0.2246 - val_accuracy: 0.9270 - val_loss: 0.2410\nEpoch 47/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9318 - loss: 0.2240 - val_accuracy: 0.9268 - val_loss: 0.2406\nEpoch 48/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9321 - loss: 0.2229 - val_accuracy: 0.9276 - val_loss: 0.2384\nEpoch 49/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m10s\u001B[0m 38ms/step - accuracy: 0.9323 - loss: 0.2225 - val_accuracy: 0.9283 - val_loss: 0.2372\nEpoch 50/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9327 - loss: 0.2209 - val_accuracy: 0.9282 - val_loss: 0.2374\nEpoch 51/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9330 - loss: 0.2199 - val_accuracy: 0.9284 - val_loss: 0.2363\nEpoch 52/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9340 - loss: 0.2162 - val_accuracy: 0.9284 - val_loss: 0.2361\nEpoch 53/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9336 - loss: 0.2181 - val_accuracy: 0.9287 - val_loss: 0.2351\nEpoch 54/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9340 - loss: 0.2161 - val_accuracy: 0.9289 - val_loss: 0.2349\nEpoch 55/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9344 - loss: 0.2147 - val_accuracy: 0.9291 - val_loss: 0.2343\nEpoch 56/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9350 - loss: 0.2128 - val_accuracy: 0.9294 - val_loss: 0.2334\nEpoch 57/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9348 - loss: 0.2135 - val_accuracy: 0.9287 - val_loss: 0.2332\nEpoch 58/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9355 - loss: 0.2114 - val_accuracy: 0.9294 - val_loss: 0.2325\nEpoch 59/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9357 - loss: 0.2105 - val_accuracy: 0.9295 - val_loss: 0.2325\nEpoch 60/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9360 - loss: 0.2097 - val_accuracy: 0.9294 - val_loss: 0.2328\nEpoch 61/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9361 - loss: 0.2092 - val_accuracy: 0.9298 - val_loss: 0.2316\nEpoch 62/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9363 - loss: 0.2081 - val_accuracy: 0.9296 - val_loss: 0.2318\nEpoch 63/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9368 - loss: 0.2062 - val_accuracy: 0.9302 - val_loss: 0.2303\nEpoch 64/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9368 - loss: 0.2064 - val_accuracy: 0.9306 - val_loss: 0.2300\nEpoch 65/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9374 - loss: 0.2049 - val_accuracy: 0.9308 - val_loss: 0.2293\nEpoch 66/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9380 - loss: 0.2025 - val_accuracy: 0.9306 - val_loss: 0.2292\nEpoch 67/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9376 - loss: 0.2040 - val_accuracy: 0.9306 - val_loss: 0.2301\nEpoch 68/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9385 - loss: 0.2012 - val_accuracy: 0.9306 - val_loss: 0.2294\nEpoch 69/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9388 - loss: 0.1999 - val_accuracy: 0.9310 - val_loss: 0.2288\nEpoch 70/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9387 - loss: 0.1999 - val_accuracy: 0.9307 - val_loss: 0.2297\nEpoch 71/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9382 - loss: 0.2019 - val_accuracy: 0.9311 - val_loss: 0.2277\nEpoch 72/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9395 - loss: 0.1973 - val_accuracy: 0.9311 - val_loss: 0.2280\nEpoch 73/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9395 - loss: 0.1978 - val_accuracy: 0.9312 - val_loss: 0.2284\nEpoch 74/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9394 - loss: 0.1985 - val_accuracy: 0.9315 - val_loss: 0.2274\nEpoch 75/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m10s\u001B[0m 38ms/step - accuracy: 0.9400 - loss: 0.1959 - val_accuracy: 0.9315 - val_loss: 0.2273\nEpoch 76/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9400 - loss: 0.1959 - val_accuracy: 0.9315 - val_loss: 0.2269\nEpoch 77/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9406 - loss: 0.1942 - val_accuracy: 0.9310 - val_loss: 0.2284\nEpoch 78/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9406 - loss: 0.1933 - val_accuracy: 0.9314 - val_loss: 0.2278\nEpoch 79/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9407 - loss: 0.1928 - val_accuracy: 0.9316 - val_loss: 0.2272\nEpoch 80/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9409 - loss: 0.1930 - val_accuracy: 0.9318 - val_loss: 0.2273\nEpoch 81/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9413 - loss: 0.1915 - val_accuracy: 0.9316 - val_loss: 0.2271\nEpoch 82/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9417 - loss: 0.1903 - val_accuracy: 0.9316 - val_loss: 0.2278\nEpoch 83/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9418 - loss: 0.1897 - val_accuracy: 0.9316 - val_loss: 0.2265\nEpoch 84/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9423 - loss: 0.1883 - val_accuracy: 0.9317 - val_loss: 0.2274\nEpoch 85/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9426 - loss: 0.1868 - val_accuracy: 0.9319 - val_loss: 0.2275\nEpoch 86/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m10s\u001B[0m 38ms/step - accuracy: 0.9426 - loss: 0.1868 - val_accuracy: 0.9317 - val_loss: 0.2267\nEpoch 87/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9425 - loss: 0.1876 - val_accuracy: 0.9317 - val_loss: 0.2285\nEpoch 88/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9434 - loss: 0.1846 - val_accuracy: 0.9322 - val_loss: 0.2263\nEpoch 89/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9430 - loss: 0.1854 - val_accuracy: 0.9320 - val_loss: 0.2269\nEpoch 90/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9437 - loss: 0.1834 - val_accuracy: 0.9319 - val_loss: 0.2280\nEpoch 91/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9437 - loss: 0.1838 - val_accuracy: 0.9321 - val_loss: 0.2275\nEpoch 92/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9435 - loss: 0.1841 - val_accuracy: 0.9321 - val_loss: 0.2271\nEpoch 93/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9440 - loss: 0.1832 - val_accuracy: 0.9323 - val_loss: 0.2273\nEpoch 94/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9443 - loss: 0.1816 - val_accuracy: 0.9320 - val_loss: 0.2281\nEpoch 95/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9444 - loss: 0.1808 - val_accuracy: 0.9325 - val_loss: 0.2272\nEpoch 96/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9445 - loss: 0.1808 - val_accuracy: 0.9326 - val_loss: 0.2275\nEpoch 97/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9447 - loss: 0.1801 - val_accuracy: 0.9326 - val_loss: 0.2276\nEpoch 98/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9453 - loss: 0.1787 - val_accuracy: 0.9321 - val_loss: 0.2283\nEpoch 99/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9447 - loss: 0.1800 - val_accuracy: 0.9323 - val_loss: 0.2278\nEpoch 100/100\n\u001B[1m250/250\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m9s\u001B[0m 38ms/step - accuracy: 0.9452 - loss: 0.1782 - val_accuracy: 0.9322 - val_loss: 0.2289\n", + "output_type": "stream" + } + ] + }, + { + "cell_type": "code", + "source": [ + "encoder_inputs = model.input[0] # input_1\n", + "encoder_outputs, state_h_enc, state_c_enc = model.layers[2].output # lstm_1\n", + "encoder_states = [state_h_enc, state_c_enc]\n", + "encoder_model = keras.Model(encoder_inputs, encoder_states)\n", + "\n", + "decoder_inputs = model.input[1] # input_2\n", + "decoder_state_input_h = keras.Input(shape=(latent_dim,))\n", + "decoder_state_input_c = keras.Input(shape=(latent_dim,))\n", + "decoder_states_inputs = [decoder_state_input_h, decoder_state_input_c]\n", + "decoder_lstm = model.layers[3]\n", + "decoder_outputs, state_h_dec, state_c_dec = decoder_lstm(\n", + " decoder_inputs, initial_state=decoder_states_inputs\n", + ")\n", + "decoder_states = [state_h_dec, state_c_dec]\n", + "decoder_dense = model.layers[4]\n", + "decoder_outputs = decoder_dense(decoder_outputs)\n", + "decoder_model = keras.Model(\n", + " [decoder_inputs] + decoder_states_inputs, [decoder_outputs] + decoder_states\n", + ")\n", + "\n", + "# Reverse-lookup token index to decode sequences back to\n", + "# something readable.\n", + "reverse_input_char_index = dict((i, char) for char, i in input_token_index.items())\n", + "reverse_target_char_index = dict((i, char) for char, i in target_token_index.items())\n", + "\n", + "\n", + "def decode_sequence(input_seq):\n", + " # Encode the input as state vectors.\n", + " states_value = encoder_model.predict(input_seq, verbose=0)\n", + "\n", + " # Generate empty target sequence of length 1.\n", + " target_seq = np.zeros((1, 1, num_decoder_tokens))\n", + " # Populate the first character of target sequence with the start character.\n", + " target_seq[0, 0, target_token_index[\"\\t\"]] = 1.0\n", + "\n", + " # Sampling loop for a batch of sequences\n", + " # (to simplify, here we assume a batch of size 1).\n", + " stop_condition = False\n", + " decoded_sentence = \"\"\n", + " while not stop_condition:\n", + " output_tokens, h, c = decoder_model.predict(\n", + " [target_seq] + states_value, verbose=0\n", + " )\n", + "\n", + " # Sample a token\n", + " sampled_token_index = np.argmax(output_tokens[0, -1, :])\n", + " sampled_char = reverse_target_char_index[sampled_token_index]\n", + " decoded_sentence += sampled_char\n", + "\n", + " # Exit condition: either hit max length\n", + " # or find stop character.\n", + " if sampled_char == \"\\n\" or len(decoded_sentence) > max_decoder_seq_length:\n", + " stop_condition = True\n", + "\n", + " # Update the target sequence (of length 1).\n", + " target_seq = np.zeros((1, 1, num_decoder_tokens))\n", + " target_seq[0, 0, sampled_token_index] = 1.0\n", + "\n", + " # Update states\n", + " states_value = [h, c]\n", + " return decoded_sentence" + ], + "metadata": { + "execution": { + "iopub.status.busy": "2024-05-25T12:22:12.112360Z", + "iopub.execute_input": "2024-05-25T12:22:12.112779Z", + "iopub.status.idle": "2024-05-25T12:22:12.136002Z", + "shell.execute_reply.started": "2024-05-25T12:22:12.112743Z", + "shell.execute_reply": "2024-05-25T12:22:12.134980Z" + }, + "trusted": true + }, + "execution_count": 15, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "for seq_index in range(20):\n", + " # Take one sequence (part of the training set)\n", + " # for trying out decoding.\n", + " input_seq = encoder_input_data[seq_index : seq_index + 1]\n", + " decoded_sentence = decode_sequence(input_seq)\n", + " print(\"-\")\n", + " print(\"Input sentence:\", input_texts[seq_index])\n", + " print(\"Decoded sentence:\", decoded_sentence)" + ], + "metadata": { + "execution": { + "iopub.status.busy": "2024-05-25T12:22:18.063970Z", + "iopub.execute_input": "2024-05-25T12:22:18.064875Z", + "iopub.status.idle": "2024-05-25T12:22:47.061605Z", + "shell.execute_reply.started": "2024-05-25T12:22:18.064840Z", + "shell.execute_reply": "2024-05-25T12:22:47.060547Z" + }, + "trusted": true + }, + "execution_count": 16, + "outputs": [ + { + "name": "stdout", + "text": "-\nInput sentence: Olethan kohtelias.\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Meillä on isompiakin ongelmia.\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Miksi me valehtelisimme sinulle?\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Tomi antoi Marille palan suklaata.\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Etkö olekin hyvä tenniksessä?\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Se voi tapahtua.\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Minun äitini on todella hyvä golfaamaan.\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Olen tottunut puhumaan siitä.\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Sen edestään löytää mitä taakseen jättää.\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Olen pomosi.\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Tämä on kaiken loppu.\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Haluatko, että vakoilen Tomia puolestasi?\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Tavataan taas pian uudestaan.\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Kuka pelaa lätkää tänä iltana?\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Täällä on liian lämmintä.\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Tomi haluu kellon synttärilahjaks.\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Se on kaikki mitä minulla on.\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Antakaa minulle kaukosäädin.\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Tom oli ainoa, joka ei osannut puhua ranskaa.\nDecoded sentence: Tom is a good money.\n\n-\nInput sentence: Minä olen aika varma, että tulemme häviämään.\nDecoded sentence: Tom is a good money.\n\n", + "output_type": "stream" + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Model chyba znalazł jakiś \"środek\" w zbiorze danych jako target i tłumaczy każde zdanie na to (ma to trochę sens bo Tom występuje 36660 razy w zbiorze)" + ], + "metadata": {} + }, + { + "cell_type": "code", + "source": [ + "input_seq = encoder_input_data[0 : 1]\n", + "print(input_seq)\n", + "print(input_seq.shape)" + ], + "metadata": { + "execution": { + "iopub.status.busy": "2024-05-25T12:27:09.171551Z", + "iopub.execute_input": "2024-05-25T12:27:09.172423Z", + "iopub.status.idle": "2024-05-25T12:27:09.178406Z", + "shell.execute_reply.started": "2024-05-25T12:27:09.172388Z", + "shell.execute_reply": "2024-05-25T12:27:09.177384Z" + }, + "trusted": true + }, + "execution_count": 19, + "outputs": [ + { + "name": "stdout", + "text": "[[[0. 0. 0. ... 0. 0. 0.]\n [0. 0. 0. ... 0. 0. 0.]\n [0. 0. 0. ... 0. 0. 0.]\n ...\n [1. 0. 0. ... 0. 0. 0.]\n [1. 0. 0. ... 0. 0. 0.]\n [1. 0. 0. ... 0. 0. 0.]]]\n(1, 211, 87)\n", + "output_type": "stream" + } + ] + }, + { + "cell_type": "code", + "source": [ + "decoded_sentence = decode_sequence(input_seq)\n", + "print(decoded_sentence)" + ], + "metadata": { + "execution": { + "iopub.status.busy": "2024-05-25T12:26:51.601615Z", + "iopub.execute_input": "2024-05-25T12:26:51.602086Z", + "iopub.status.idle": "2024-05-25T12:26:53.227737Z", + "shell.execute_reply.started": "2024-05-25T12:26:51.602054Z", + "shell.execute_reply": "2024-05-25T12:26:53.226778Z" + }, + "trusted": true + }, + "execution_count": 18, + "outputs": [ + { + "name": "stdout", + "text": "Tom is a good money.\n\n", + "output_type": "stream" + } + ] + }, + { + "cell_type": "code", + "source": [ + "input_texts[0]" + ], + "metadata": { + "execution": { + "iopub.status.busy": "2024-05-25T12:32:02.521359Z", + "iopub.execute_input": "2024-05-25T12:32:02.522219Z", + "iopub.status.idle": "2024-05-25T12:32:02.528138Z", + "shell.execute_reply.started": "2024-05-25T12:32:02.522185Z", + "shell.execute_reply": "2024-05-25T12:32:02.527158Z" + }, + "trusted": true + }, + "execution_count": 20, + "outputs": [ + { + "execution_count": 20, + "output_type": "execute_result", + "data": { + "text/plain": "'Olethan kohtelias.'" + }, + "metadata": {} + } + ] + }, + { + "cell_type": "code", + "source": [ + "test_input = \"Se olen minä!\"\n", + "encoded_test_input = np.zeros_like(input_seq)\n", + "for t, char in enumerate(test_input):\n", + " encoded_test_input[0, t, input_token_index[char]] = 1.0\n", + "encoded_test_input[0, t + 1 :, input_token_index[\" \"]] = 1.0" + ], + "metadata": { + "execution": { + "iopub.status.busy": "2024-05-25T12:39:55.586780Z", + "iopub.execute_input": "2024-05-25T12:39:55.587565Z", + "iopub.status.idle": "2024-05-25T12:39:55.592991Z", + "shell.execute_reply.started": "2024-05-25T12:39:55.587530Z", + "shell.execute_reply": "2024-05-25T12:39:55.592058Z" + }, + "trusted": true + }, + "execution_count": 24, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "print(encoded_test_input)\n", + "print(encoded_test_input.shape)" + ], + "metadata": { + "execution": { + "iopub.status.busy": "2024-05-25T12:40:16.684956Z", + "iopub.execute_input": "2024-05-25T12:40:16.685323Z", + "iopub.status.idle": "2024-05-25T12:40:16.691354Z", + "shell.execute_reply.started": "2024-05-25T12:40:16.685291Z", + "shell.execute_reply": "2024-05-25T12:40:16.690354Z" + }, + "trusted": true + }, + "execution_count": 25, + "outputs": [ + { + "name": "stdout", + "text": "[[[0. 0. 0. ... 0. 0. 0.]\n [0. 0. 0. ... 0. 0. 0.]\n [1. 0. 0. ... 0. 0. 0.]\n ...\n [1. 0. 0. ... 0. 0. 0.]\n [1. 0. 0. ... 0. 0. 0.]\n [1. 0. 0. ... 0. 0. 0.]]]\n(1, 211, 87)\n", + "output_type": "stream" + } + ] + }, + { + "cell_type": "code", + "source": [ + "def translate(sentence):\n", + " encoded_in = np.zeros(shape=(1,211,87))\n", + " for t, char in enumerate(sentence):\n", + " encoded_in[0, t, input_token_index[char]] = 1.0\n", + " encoded_in[0, t + 1 :, input_token_index[\" \"]] = 1.0\n", + " decoded_sentence = decode_sequence(encoded_in)\n", + " print(\"Input sentence:\", sentence)\n", + " print(\"Decoded sentence:\", decoded_sentence)\n", + "translate(\"Se olen minä!\")" + ], + "metadata": { + "execution": { + "iopub.status.busy": "2024-05-25T12:43:21.442118Z", + "iopub.execute_input": "2024-05-25T12:43:21.442838Z", + "iopub.status.idle": "2024-05-25T12:43:22.884495Z", + "shell.execute_reply.started": "2024-05-25T12:43:21.442803Z", + "shell.execute_reply": "2024-05-25T12:43:22.883551Z" + }, + "trusted": true + }, + "execution_count": 27, + "outputs": [ + { + "name": "stdout", + "text": "Input sentence: Se olen minä!\nDecoded sentence: Tom is a good money.\n\n", + "output_type": "stream" + } + ] + }, + { + "cell_type": "code", + "source": [ + "translate(\"Mene.\")" + ], + "metadata": { + "execution": { + "iopub.status.busy": "2024-05-25T12:44:13.691710Z", + "iopub.execute_input": "2024-05-25T12:44:13.692549Z", + "iopub.status.idle": "2024-05-25T12:44:15.224604Z", + "shell.execute_reply.started": "2024-05-25T12:44:13.692514Z", + "shell.execute_reply": "2024-05-25T12:44:15.223700Z" + }, + "trusted": true + }, + "execution_count": 28, + "outputs": [ + { + "name": "stdout", + "text": "Input sentence: Mene.\nDecoded sentence: Tom is a good money.\n\n", + "output_type": "stream" + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "### Wynik jest dosyć mało zadowalający i stwierdziłem, iż spróbuję skorzystać z wersji przedstawionej w dokumentacji pytorch" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": null, + "outputs": [], + "source": [], + "metadata": { + "collapsed": false + } + } + ] +}