├── Course 1 - Introduction to Tensorflow, ML, DL
├── .ipynb_checkpoints
│ ├── Exercise3_MNIST_CNN-checkpoint.ipynb
│ └── Exercise4_Happy_Sad_CNN-checkpoint.ipynb
├── Exercise1_House_Prices.ipynb
├── Exercise2_Handwriting_Recognition.ipynb
├── Exercise3_MNIST_CNN.ipynb
├── Exercise4_Handling_Complex_Images.ipynb
├── Week 1 Quiz | Coursera.webarchive
├── Week 2 Quiz | Coursera.webarchive
├── Week 3 Quiz | Coursera.webarchive
└── Week 4 Quiz | Coursera.webarchive
├── Course 2 - CNNs in Tensorflow
├── .ipynb_checkpoints
│ ├── Exercise_5_Question-checkpoint.ipynb
│ ├── Exercise_6_CatsDogs_augment-checkpoint.ipynb
│ ├── Exercise_7_transferlearning-checkpoint.ipynb
│ ├── Exercise_8_sign_language_mnist-checkpoint.ipynb
│ ├── Transfer_Learning-checkpoint.ipynb
│ └── rock_paper_scissors-checkpoint.ipynb
├── Exercise5_CatsDogs.ipynb
├── Exercise6_CatsDogs_Augment.ipynb
├── Exercise7_TransferLearning.ipynb
├── Exercise8_Multiclass_Classifier.ipynb
├── ExerciseX_RockPaperScissors.ipynb
├── Week 1 Quiz | Coursera.webarchive
├── Week 2 Quiz | Coursera.webarchive
├── Week 3 Quiz | Coursera.webarchive
└── Week 4 Quiz | Coursera.webarchive
├── Course 3 - NLP in Tensorflow
├── .ipynb_checkpoints
│ ├── Course_3_Week_2_Lesson_1-checkpoint.ipynb
│ ├── Week2_Exercise_WordEmbeddings-checkpoint.ipynb
│ ├── Week3_Exercise-checkpoint.ipynb
│ ├── Week4_Exercise_Shakespeare-checkpoint.ipynb
│ └── week3_Exercise1_question-checkpoint.ipynb
├── Week 1 Quiz | Coursera.webarchive
├── Week 2 Quiz | Coursera.webarchive
├── Week 3 Quiz | Coursera.webarchive
├── Week 4 Quiz | Coursera.webarchive
├── Week1_Exercise_BBC_Explore.ipynb
├── Week2_Exercise_BBC_News_Archive.ipynb
├── Week3_Exercise_Exploring_Overfitting.ipynb
├── Week4_Exercise_LSTM_Shakespeare.ipynb
├── meta.tsv
└── vecs.tsv
├── Course 4 - Sequences, Time Series & Prediction
├── .ipynb_checkpoints
│ ├── Week1_Exercise_Naive_Forecast-checkpoint.ipynb
│ ├── Week2_Exercise_WindowedDataset_Dense-checkpoint.ipynb
│ ├── Week3_Exercise_WindowedDataset_RNN_simple-checkpoint.ipynb
│ └── Week4_Exercise_WondowedDataset_RNNwithConv1D-checkpoint.ipynb
├── Week 1 Quiz | Coursera.webarchive
├── Week 3 Quiz | Coursera.webarchive
├── Week 4 Quiz | Coursera.webarchive
├── Week1_Exercise_Create_Predict_Data.ipynb
├── Week2_Exercise_Predict_DNN.ipynb
├── Week3_Exercise_Mean_Absolute_Error.ipynb
└── Week4_Exercise_Sunspots.ipynb
├── LICENSE
└── README.md
/Course 1 - Introduction to Tensorflow, ML, DL/.ipynb_checkpoints/Exercise3_MNIST_CNN-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "colab_type": "text",
7 | "id": "iQjHqsmTAVLU"
8 | },
9 | "source": [
10 | "## Exercise 3\n",
11 | "In the videos you looked at how you would improve Fashion MNIST using Convolutions. For your exercise see if you can improve MNIST to 99.8% accuracy or more using only a single convolutional layer and a single MaxPooling 2D. You should stop training once the accuracy goes above this amount. It should happen in less than 20 epochs, so it's ok to hard code the number of epochs for training, but your training must end once it hits the above metric. If it doesn't, then you'll need to redesign your layers.\n",
12 | "\n",
13 | "I've started the code for you -- you need to finish it!\n",
14 | "\n",
15 | "When 99.8% accuracy has been hit, you should print out the string \"Reached 99.8% accuracy so cancelling training!\"\n"
16 | ]
17 | },
18 | {
19 | "cell_type": "code",
20 | "execution_count": 1,
21 | "metadata": {},
22 | "outputs": [],
23 | "source": [
24 | "import tensorflow as tf\n",
25 | "from os import path, getcwd, chdir\n",
26 | "\n",
27 | "# DO NOT CHANGE THE LINE BELOW. If you are developing in a local\n",
28 | "# environment, then grab mnist.npz from the Coursera Jupyter Notebook\n",
29 | "# and place it inside a local folder and edit the path to that location\n",
30 | "path = f\"{getcwd()}/../tmp2/mnist.npz\""
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": 2,
36 | "metadata": {},
37 | "outputs": [],
38 | "source": [
39 | "config = tf.ConfigProto()\n",
40 | "config.gpu_options.allow_growth = True\n",
41 | "sess = tf.Session(config=config)"
42 | ]
43 | },
44 | {
45 | "cell_type": "code",
46 | "execution_count": 10,
47 | "metadata": {},
48 | "outputs": [],
49 | "source": [
50 | "# GRADED FUNCTION: train_mnist_conv\n",
51 | "def train_mnist_conv():\n",
52 | " # Please write your code only where you are indicated.\n",
53 | " # please do not remove model fitting inline comments.\n",
54 | "\n",
55 | " # YOUR CODE STARTS HERE\n",
56 | " class myCallback(tf.keras.callbacks.Callback):\n",
57 | " def on_epoch_end(self, epoch, logs={}):\n",
58 | " if (logs.get('acc')>0.998):\n",
59 | " print(\"\\nReached 99.8% accuracy so cancelling training!\")\n",
60 | " self.model.stop_training = True\n",
61 | " callbacks = myCallback()\n",
62 | " # YOUR CODE ENDS HERE\n",
63 | "\n",
64 | " mnist = tf.keras.datasets.mnist\n",
65 | " (training_images, training_labels), (test_images, test_labels) = mnist.load_data(path=path)\n",
66 | " # YOUR CODE STARTS HERE\n",
67 | " training_images = training_images.reshape(60000, 28, 28, 1)\n",
68 | " training_images = training_images / 255.0\n",
69 | " test_images = test_images.reshape(10000, 28, 28, 1)\n",
70 | " test_images = test_images / 255.0\n",
71 | " # YOUR CODE ENDS HERE\n",
72 | "\n",
73 | " model = tf.keras.models.Sequential([\n",
74 | " # YOUR CODE STARTS HERE\n",
75 | " tf.keras.layers.Conv2D(32, (3,3), activation='relu', input_shape=(28, 28, 1)),\n",
76 | " tf.keras.layers.MaxPooling2D(2, 2),\n",
77 | " tf.keras.layers.Flatten(),\n",
78 | " tf.keras.layers.Dense(128, activation='relu'),\n",
79 | " tf.keras.layers.Dense(10, activation='softmax')\n",
80 | " # YOUR CODE ENDS HERE\n",
81 | " ])\n",
82 | "\n",
83 | " model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])\n",
84 | " # model fitting\n",
85 | " history = model.fit(\n",
86 | " # YOUR CODE STARTS HERE\n",
87 | " training_images, training_labels, epochs=20, callbacks=[callbacks]\n",
88 | " # YOUR CODE ENDS HERE\n",
89 | " )\n",
90 | " # model fitting\n",
91 | " return history.epoch, history.history['acc'][-1]\n",
92 | "\n"
93 | ]
94 | },
95 | {
96 | "cell_type": "code",
97 | "execution_count": 8,
98 | "metadata": {},
99 | "outputs": [
100 | {
101 | "name": "stdout",
102 | "output_type": "stream",
103 | "text": [
104 | "Epoch 1/20\n",
105 | "60000/60000 [==============================] - 21s 342us/sample - loss: 0.1462 - acc: 0.9568\n",
106 | "Epoch 2/20\n",
107 | "60000/60000 [==============================] - 17s 278us/sample - loss: 0.0509 - acc: 0.9842\n",
108 | "Epoch 3/20\n",
109 | "60000/60000 [==============================] - 17s 278us/sample - loss: 0.0311 - acc: 0.9902\n",
110 | "Epoch 4/20\n",
111 | "60000/60000 [==============================] - 17s 280us/sample - loss: 0.0202 - acc: 0.9936\n",
112 | "Epoch 5/20\n",
113 | "60000/60000 [==============================] - 17s 278us/sample - loss: 0.0137 - acc: 0.9954\n",
114 | "Epoch 6/20\n",
115 | "60000/60000 [==============================] - 17s 277us/sample - loss: 0.0106 - acc: 0.9965\n",
116 | "Epoch 7/20\n",
117 | "60000/60000 [==============================] - 17s 278us/sample - loss: 0.0081 - acc: 0.9973\n",
118 | "Epoch 8/20\n",
119 | "60000/60000 [==============================] - 17s 277us/sample - loss: 0.0068 - acc: 0.9976\n",
120 | "Epoch 9/20\n",
121 | "59840/60000 [============================>.] - ETA: 0s - loss: 0.0046 - acc: 0.9983\n",
122 | "Reached 99.8% accuracy so cancelling training!\n",
123 | "60000/60000 [==============================] - 17s 280us/sample - loss: 0.0046 - acc: 0.9983\n"
124 | ]
125 | }
126 | ],
127 | "source": [
128 | "_, _ = train_mnist_conv()"
129 | ]
130 | },
131 | {
132 | "cell_type": "code",
133 | "execution_count": null,
134 | "metadata": {},
135 | "outputs": [],
136 | "source": [
137 | "# Now click the 'Submit Assignment' button above.\n",
138 | "# Once that is complete, please run the following two cells to save your work and close the notebook"
139 | ]
140 | },
141 | {
142 | "cell_type": "code",
143 | "execution_count": null,
144 | "metadata": {},
145 | "outputs": [],
146 | "source": [
147 | "%%javascript\n",
148 | "\n",
149 | "IPython.notebook.save_checkpoint();"
150 | ]
151 | },
152 | {
153 | "cell_type": "code",
154 | "execution_count": null,
155 | "metadata": {},
156 | "outputs": [],
157 | "source": [
158 | "%%javascript\n",
159 | "\n",
160 | "window.onbeforeunload = null\n",
161 | "window.close();\n",
162 | "IPython.notebook.session.delete();"
163 | ]
164 | }
165 | ],
166 | "metadata": {
167 | "coursera": {
168 | "course_slug": "introduction-tensorflow",
169 | "graded_item_id": "ml06H",
170 | "launcher_item_id": "hQF8A"
171 | },
172 | "kernelspec": {
173 | "display_name": "Python 3",
174 | "language": "python",
175 | "name": "python3"
176 | },
177 | "language_info": {
178 | "codemirror_mode": {
179 | "name": "ipython",
180 | "version": 3
181 | },
182 | "file_extension": ".py",
183 | "mimetype": "text/x-python",
184 | "name": "python",
185 | "nbconvert_exporter": "python",
186 | "pygments_lexer": "ipython3",
187 | "version": "3.7.3"
188 | }
189 | },
190 | "nbformat": 4,
191 | "nbformat_minor": 1
192 | }
193 |
--------------------------------------------------------------------------------
/Course 1 - Introduction to Tensorflow, ML, DL/.ipynb_checkpoints/Exercise4_Happy_Sad_CNN-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "colab_type": "text",
7 | "id": "UncprnB0ymAE"
8 | },
9 | "source": [
10 | "Below is code with a link to a happy or sad dataset which contains 80 images, 40 happy and 40 sad. \n",
11 | "Create a convolutional neural network that trains to 100% accuracy on these images, which cancels training upon hitting training accuracy of >.999\n",
12 | "\n",
13 | "Hint -- it will work best with 3 convolutional layers."
14 | ]
15 | },
16 | {
17 | "cell_type": "code",
18 | "execution_count": 1,
19 | "metadata": {},
20 | "outputs": [],
21 | "source": [
22 | "import tensorflow as tf\n",
23 | "import os\n",
24 | "import zipfile\n",
25 | "from os import path, getcwd, chdir\n",
26 | "\n",
27 | "# DO NOT CHANGE THE LINE BELOW. If you are developing in a local\n",
28 | "# environment, then grab happy-or-sad.zip from the Coursera Jupyter Notebook\n",
29 | "# and place it inside a local folder and edit the path to that location\n",
30 | "path = f\"{getcwd()}/../tmp2/happy-or-sad.zip\"\n",
31 | "\n",
32 | "zip_ref = zipfile.ZipFile(path, 'r')\n",
33 | "zip_ref.extractall(\"/tmp/h-or-s\")\n",
34 | "zip_ref.close()"
35 | ]
36 | },
37 | {
38 | "cell_type": "code",
39 | "execution_count": 22,
40 | "metadata": {},
41 | "outputs": [],
42 | "source": [
43 | "# GRADED FUNCTION: train_happy_sad_model\n",
44 | "def train_happy_sad_model():\n",
45 | " # Please write your code only where you are indicated.\n",
46 | " # please do not remove # model fitting inline comments.\n",
47 | "\n",
48 | " DESIRED_ACCURACY = 0.999\n",
49 | "\n",
50 | " class myCallback(tf.keras.callbacks.Callback):\n",
51 | " def on_epoch_end(self, epoch, logs={}):\n",
52 | " if logs.get('acc')>0.999:\n",
53 | " print(\"\\nReached 99.9% accuracy so cancelling training!\")\n",
54 | " self.model.stop_training = True\n",
55 | " callbacks = myCallback()\n",
56 | " \n",
57 | " # This Code Block should Define and Compile the Model. Please assume the images are 150 X 150 in your implementation.\n",
58 | " model = tf.keras.models.Sequential([\n",
59 | " tf.keras.layers.Conv2D(16, (3,3), activation='relu', input_shape=(150,150,3)),\n",
60 | " tf.keras.layers.MaxPooling2D(2,2),\n",
61 | " tf.keras.layers.Conv2D(32, (3,3), activation='relu'),\n",
62 | " tf.keras.layers.MaxPooling2D(2,2),\n",
63 | " tf.keras.layers.Conv2D(64, (3,3), activation='relu'),\n",
64 | " tf.keras.layers.MaxPooling2D(2,2),\n",
65 | " tf.keras.layers.Flatten(),\n",
66 | " tf.keras.layers.Dense(512, activation='relu'),\n",
67 | " tf.keras.layers.Dense(1, activation='sigmoid')\n",
68 | " ])\n",
69 | "\n",
70 | " from tensorflow.keras.optimizers import RMSprop\n",
71 | "\n",
72 | " model.compile(loss='binary_crossentropy',\n",
73 | " optimizer=RMSprop(lr=0.001),\n",
74 | " metrics=['acc'])\n",
75 | "\n",
76 | " # This code block should create an instance of an ImageDataGenerator called train_datagen \n",
77 | " # And a train_generator by calling train_datagen.flow_from_directory\n",
78 | "\n",
79 | " from tensorflow.keras.preprocessing.image import ImageDataGenerator\n",
80 | "\n",
81 | " train_datagen = ImageDataGenerator(rescale=1./255)\n",
82 | "\n",
83 | " # Please use a target_size of 150 X 150.\n",
84 | " train_generator = train_datagen.flow_from_directory(\n",
85 | " \"/tmp/h-or-s/\",\n",
86 | " target_size=(150,150),\n",
87 | " batch_size=4,\n",
88 | " class_mode='binary')\n",
89 | " # Expected output: 'Found 80 images belonging to 2 classes'\n",
90 | "\n",
91 | " # This code block should call model.fit_generator and train for\n",
92 | " # a number of epochs.\n",
93 | " # model fitting\n",
94 | " history = model.fit_generator(\n",
95 | " train_generator,\n",
96 | " steps_per_epoch=20,\n",
97 | " epochs=15,\n",
98 | " callbacks=[callbacks],\n",
99 | " verbose=1)\n",
100 | " # model fitting\n",
101 | " return history.history['acc'][-1]"
102 | ]
103 | },
104 | {
105 | "cell_type": "code",
106 | "execution_count": 23,
107 | "metadata": {},
108 | "outputs": [
109 | {
110 | "name": "stdout",
111 | "output_type": "stream",
112 | "text": [
113 | "Found 80 images belonging to 2 classes.\n",
114 | "Epoch 1/15\n",
115 | "20/20 [==============================] - 3s 150ms/step - loss: 1.5894 - acc: 0.6750\n",
116 | "Epoch 2/15\n",
117 | "20/20 [==============================] - 1s 39ms/step - loss: 0.2161 - acc: 0.9250\n",
118 | "Epoch 3/15\n",
119 | "20/20 [==============================] - 1s 35ms/step - loss: 0.2755 - acc: 0.8875\n",
120 | "Epoch 4/15\n",
121 | "20/20 [==============================] - 1s 35ms/step - loss: 0.1063 - acc: 0.9250\n",
122 | "Epoch 5/15\n",
123 | "20/20 [==============================] - 1s 31ms/step - loss: 0.2442 - acc: 0.9500\n",
124 | "Epoch 6/15\n",
125 | "20/20 [==============================] - 1s 35ms/step - loss: 0.0424 - acc: 0.9875\n",
126 | "Epoch 7/15\n",
127 | "19/20 [===========================>..] - ETA: 0s - loss: 0.0026 - acc: 1.0000 \n",
128 | "Reached 99.9% accuracy so cancelling training!\n",
129 | "20/20 [==============================] - 1s 35ms/step - loss: 0.0026 - acc: 1.0000\n"
130 | ]
131 | },
132 | {
133 | "data": {
134 | "text/plain": [
135 | "1.0"
136 | ]
137 | },
138 | "execution_count": 23,
139 | "metadata": {},
140 | "output_type": "execute_result"
141 | }
142 | ],
143 | "source": [
144 | "# The Expected output: \"Reached 99.9% accuracy so cancelling training!\"\"\n",
145 | "train_happy_sad_model()"
146 | ]
147 | },
148 | {
149 | "cell_type": "code",
150 | "execution_count": null,
151 | "metadata": {},
152 | "outputs": [],
153 | "source": [
154 | "# Now click the 'Submit Assignment' button above.\n",
155 | "# Once that is complete, please run the following two cells to save your work and close the notebook"
156 | ]
157 | },
158 | {
159 | "cell_type": "code",
160 | "execution_count": null,
161 | "metadata": {},
162 | "outputs": [],
163 | "source": [
164 | "%%javascript\n",
165 | "\n",
166 | "IPython.notebook.save_checkpoint();"
167 | ]
168 | },
169 | {
170 | "cell_type": "code",
171 | "execution_count": null,
172 | "metadata": {},
173 | "outputs": [],
174 | "source": [
175 | "%%javascript\n",
176 | "\n",
177 | "window.onbeforeunload = null\n",
178 | "window.close();\n",
179 | "IPython.notebook.session.delete();"
180 | ]
181 | }
182 | ],
183 | "metadata": {
184 | "coursera": {
185 | "course_slug": "introduction-tensorflow",
186 | "graded_item_id": "1kAlw",
187 | "launcher_item_id": "PNLYD"
188 | },
189 | "kernelspec": {
190 | "display_name": "Python 3",
191 | "language": "python",
192 | "name": "python3"
193 | },
194 | "language_info": {
195 | "codemirror_mode": {
196 | "name": "ipython",
197 | "version": 3
198 | },
199 | "file_extension": ".py",
200 | "mimetype": "text/x-python",
201 | "name": "python",
202 | "nbconvert_exporter": "python",
203 | "pygments_lexer": "ipython3",
204 | "version": "3.7.3"
205 | }
206 | },
207 | "nbformat": 4,
208 | "nbformat_minor": 1
209 | }
210 |
--------------------------------------------------------------------------------
/Course 1 - Introduction to Tensorflow, ML, DL/Exercise2_Handwriting_Recognition.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "colab_type": "text",
7 | "id": "tOoyQ70H00_s"
8 | },
9 | "source": [
10 | "## Exercise 2\n",
11 | "In the course you learned how to do classificaiton using Fashion MNIST, a data set containing items of clothing. There's another, similar dataset called MNIST which has items of handwriting -- the digits 0 through 9.\n",
12 | "\n",
13 | "Write an MNIST classifier that trains to 99% accuracy or above, and does it without a fixed number of epochs -- i.e. you should stop training once you reach that level of accuracy.\n",
14 | "\n",
15 | "Some notes:\n",
16 | "1. It should succeed in less than 10 epochs, so it is okay to change epochs= to 10, but nothing larger\n",
17 | "2. When it reaches 99% or greater it should print out the string \"Reached 99% accuracy so cancelling training!\"\n",
18 | "3. If you add any additional variables, make sure you use the same names as the ones used in the class\n",
19 | "\n",
20 | "I've started the code for you below -- how would you finish it? "
21 | ]
22 | },
23 | {
24 | "cell_type": "code",
25 | "execution_count": 1,
26 | "metadata": {},
27 | "outputs": [
28 | {
29 | "name": "stdout",
30 | "output_type": "stream",
31 | "text": [
32 | "1.14.0\n"
33 | ]
34 | }
35 | ],
36 | "source": [
37 | "import tensorflow as tf\n",
38 | "print(tf.__version__)\n",
39 | "from os import path, getcwd, chdir\n",
40 | "\n",
41 | "# DO NOT CHANGE THE LINE BELOW. If you are developing in a local\n",
42 | "# environment, then grab mnist.npz from the Coursera Jupyter Notebook\n",
43 | "# and place it inside a local folder and edit the path to that location\n",
44 | "path = f\"{getcwd()}/../tmp2/mnist.npz\""
45 | ]
46 | },
47 | {
48 | "cell_type": "code",
49 | "execution_count": 4,
50 | "metadata": {
51 | "colab": {},
52 | "colab_type": "code",
53 | "id": "9rvXQGAA0ssC"
54 | },
55 | "outputs": [],
56 | "source": [
57 | "# GRADED FUNCTION: train_mnist\n",
58 | "def train_mnist():\n",
59 | " # Please write your code only where you are indicated.\n",
60 | " # please do not remove # model fitting inline comments.\n",
61 | "\n",
62 | " # YOUR CODE SHOULD START HERE\n",
63 | " \n",
64 | " class myCallback(tf.keras.callbacks.Callback):\n",
65 | " def on_epoch_end(self, epoch, logs={}):\n",
66 | " if(logs.get('acc')>0.99):\n",
67 | " print(\"\\nReached 99% accuracy so cancelling training!\")\n",
68 | " self.model.stop_training = True\n",
69 | " \n",
70 | " callbacks = myCallback()\n",
71 | " # YOUR CODE SHOULD END HERE\n",
72 | "\n",
73 | " mnist = tf.keras.datasets.mnist\n",
74 | "\n",
75 | " (x_train, y_train),(x_test, y_test) = mnist.load_data(path=path)\n",
76 | " \n",
77 | " # YOUR CODE SHOULD START HERE\n",
78 | " \n",
79 | " x_train = x_train / 255.0\n",
80 | " x_test = x_train / 255.0 \n",
81 | " \n",
82 | " # YOUR CODE SHOULD END HERE\n",
83 | " \n",
84 | " model = tf.keras.models.Sequential([\n",
85 | " # YOUR CODE SHOULD START HERE\n",
86 | " tf.keras.layers.Flatten(),\n",
87 | " tf.keras.layers.Dense(256, activation=tf.nn.relu),\n",
88 | " tf.keras.layers.Dense(128, activation=tf.nn.relu),\n",
89 | " tf.keras.layers.Dense(10, activation=tf.nn.softmax)\n",
90 | " # YOUR CODE SHOULD END HERE\n",
91 | " ])\n",
92 | "\n",
93 | " model.compile(optimizer='adam',\n",
94 | " loss='sparse_categorical_crossentropy',\n",
95 | " metrics=['accuracy'])\n",
96 | " \n",
97 | " # model fitting\n",
98 | " history = model.fit(# YOUR CODE SHOULD START HERE\n",
99 | " x_train, y_train, epochs=10, callbacks=[callbacks]\n",
100 | " # YOUR CODE SHOULD END HERE\n",
101 | " )\n",
102 | " # model fitting\n",
103 | " return history.epoch, history.history['acc'][-1]"
104 | ]
105 | },
106 | {
107 | "cell_type": "code",
108 | "execution_count": 5,
109 | "metadata": {
110 | "colab": {},
111 | "colab_type": "code",
112 | "id": "9rvXQGAA0ssC"
113 | },
114 | "outputs": [
115 | {
116 | "name": "stdout",
117 | "output_type": "stream",
118 | "text": [
119 | "Epoch 1/10\n",
120 | "60000/60000 [==============================] - 20s 340us/sample - loss: 0.2072 - acc: 0.9388\n",
121 | "Epoch 2/10\n",
122 | "60000/60000 [==============================] - 20s 326us/sample - loss: 0.0867 - acc: 0.9737\n",
123 | "Epoch 3/10\n",
124 | "60000/60000 [==============================] - 20s 325us/sample - loss: 0.0573 - acc: 0.9816\n",
125 | "Epoch 4/10\n",
126 | "60000/60000 [==============================] - 19s 310us/sample - loss: 0.0438 - acc: 0.9857\n",
127 | "Epoch 5/10\n",
128 | "60000/60000 [==============================] - 18s 300us/sample - loss: 0.0344 - acc: 0.9887\n",
129 | "Epoch 6/10\n",
130 | "59936/60000 [============================>.] - ETA: 0s - loss: 0.0275 - acc: 0.9910\n",
131 | "Reached 99% accuracy so cancelling training!\n",
132 | "60000/60000 [==============================] - 18s 302us/sample - loss: 0.0275 - acc: 0.9910\n"
133 | ]
134 | },
135 | {
136 | "data": {
137 | "text/plain": [
138 | "([0, 1, 2, 3, 4, 5], 0.991)"
139 | ]
140 | },
141 | "execution_count": 5,
142 | "metadata": {},
143 | "output_type": "execute_result"
144 | }
145 | ],
146 | "source": [
147 | "train_mnist()"
148 | ]
149 | },
150 | {
151 | "cell_type": "code",
152 | "execution_count": null,
153 | "metadata": {},
154 | "outputs": [],
155 | "source": [
156 | "# Now click the 'Submit Assignment' button above.\n",
157 | "# Once that is complete, please run the following two cells to save your work and close the notebook"
158 | ]
159 | },
160 | {
161 | "cell_type": "code",
162 | "execution_count": null,
163 | "metadata": {},
164 | "outputs": [],
165 | "source": [
166 | "%%javascript\n",
167 | "\n",
168 | "IPython.notebook.save_checkpoint();"
169 | ]
170 | },
171 | {
172 | "cell_type": "code",
173 | "execution_count": null,
174 | "metadata": {},
175 | "outputs": [],
176 | "source": [
177 | "%%javascript\n",
178 | "\n",
179 | "window.onbeforeunload = null\n",
180 | "window.close();\n",
181 | "IPython.notebook.session.delete();"
182 | ]
183 | }
184 | ],
185 | "metadata": {
186 | "coursera": {
187 | "course_slug": "introduction-tensorflow",
188 | "graded_item_id": "d6dew",
189 | "launcher_item_id": "FExZ4"
190 | },
191 | "kernelspec": {
192 | "display_name": "Python 3",
193 | "language": "python",
194 | "name": "python3"
195 | },
196 | "language_info": {
197 | "codemirror_mode": {
198 | "name": "ipython",
199 | "version": 3
200 | },
201 | "file_extension": ".py",
202 | "mimetype": "text/x-python",
203 | "name": "python",
204 | "nbconvert_exporter": "python",
205 | "pygments_lexer": "ipython3",
206 | "version": "3.7.3"
207 | }
208 | },
209 | "nbformat": 4,
210 | "nbformat_minor": 1
211 | }
212 |
--------------------------------------------------------------------------------
/Course 1 - Introduction to Tensorflow, ML, DL/Exercise3_MNIST_CNN.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "colab_type": "text",
7 | "id": "iQjHqsmTAVLU"
8 | },
9 | "source": [
10 | "## Exercise 3\n",
11 | "In the videos you looked at how you would improve Fashion MNIST using Convolutions. For your exercise see if you can improve MNIST to 99.8% accuracy or more using only a single convolutional layer and a single MaxPooling 2D. You should stop training once the accuracy goes above this amount. It should happen in less than 20 epochs, so it's ok to hard code the number of epochs for training, but your training must end once it hits the above metric. If it doesn't, then you'll need to redesign your layers.\n",
12 | "\n",
13 | "I've started the code for you -- you need to finish it!\n",
14 | "\n",
15 | "When 99.8% accuracy has been hit, you should print out the string \"Reached 99.8% accuracy so cancelling training!\"\n"
16 | ]
17 | },
18 | {
19 | "cell_type": "code",
20 | "execution_count": 1,
21 | "metadata": {},
22 | "outputs": [],
23 | "source": [
24 | "import tensorflow as tf\n",
25 | "from os import path, getcwd, chdir\n",
26 | "\n",
27 | "# DO NOT CHANGE THE LINE BELOW. If you are developing in a local\n",
28 | "# environment, then grab mnist.npz from the Coursera Jupyter Notebook\n",
29 | "# and place it inside a local folder and edit the path to that location\n",
30 | "path = f\"{getcwd()}/../tmp2/mnist.npz\""
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": 2,
36 | "metadata": {},
37 | "outputs": [],
38 | "source": [
39 | "config = tf.ConfigProto()\n",
40 | "config.gpu_options.allow_growth = True\n",
41 | "sess = tf.Session(config=config)"
42 | ]
43 | },
44 | {
45 | "cell_type": "code",
46 | "execution_count": 10,
47 | "metadata": {},
48 | "outputs": [],
49 | "source": [
50 | "# GRADED FUNCTION: train_mnist_conv\n",
51 | "def train_mnist_conv():\n",
52 | " # Please write your code only where you are indicated.\n",
53 | " # please do not remove model fitting inline comments.\n",
54 | "\n",
55 | " # YOUR CODE STARTS HERE\n",
56 | " class myCallback(tf.keras.callbacks.Callback):\n",
57 | " def on_epoch_end(self, epoch, logs={}):\n",
58 | " if (logs.get('acc')>0.998):\n",
59 | " print(\"\\nReached 99.8% accuracy so cancelling training!\")\n",
60 | " self.model.stop_training = True\n",
61 | " callbacks = myCallback()\n",
62 | " # YOUR CODE ENDS HERE\n",
63 | "\n",
64 | " mnist = tf.keras.datasets.mnist\n",
65 | " (training_images, training_labels), (test_images, test_labels) = mnist.load_data(path=path)\n",
66 | " # YOUR CODE STARTS HERE\n",
67 | " training_images = training_images.reshape(60000, 28, 28, 1)\n",
68 | " training_images = training_images / 255.0\n",
69 | " test_images = test_images.reshape(10000, 28, 28, 1)\n",
70 | " test_images = test_images / 255.0\n",
71 | " # YOUR CODE ENDS HERE\n",
72 | "\n",
73 | " model = tf.keras.models.Sequential([\n",
74 | " # YOUR CODE STARTS HERE\n",
75 | " tf.keras.layers.Conv2D(32, (3,3), activation='relu', input_shape=(28, 28, 1)),\n",
76 | " tf.keras.layers.MaxPooling2D(2, 2),\n",
77 | " tf.keras.layers.Flatten(),\n",
78 | " tf.keras.layers.Dense(128, activation='relu'),\n",
79 | " tf.keras.layers.Dense(10, activation='softmax')\n",
80 | " # YOUR CODE ENDS HERE\n",
81 | " ])\n",
82 | "\n",
83 | " model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])\n",
84 | " # model fitting\n",
85 | " history = model.fit(\n",
86 | " # YOUR CODE STARTS HERE\n",
87 | " training_images, training_labels, epochs=20, callbacks=[callbacks]\n",
88 | " # YOUR CODE ENDS HERE\n",
89 | " )\n",
90 | " # model fitting\n",
91 | " return history.epoch, history.history['acc'][-1]\n",
92 | "\n"
93 | ]
94 | },
95 | {
96 | "cell_type": "code",
97 | "execution_count": 8,
98 | "metadata": {},
99 | "outputs": [
100 | {
101 | "name": "stdout",
102 | "output_type": "stream",
103 | "text": [
104 | "Epoch 1/20\n",
105 | "60000/60000 [==============================] - 21s 342us/sample - loss: 0.1462 - acc: 0.9568\n",
106 | "Epoch 2/20\n",
107 | "60000/60000 [==============================] - 17s 278us/sample - loss: 0.0509 - acc: 0.9842\n",
108 | "Epoch 3/20\n",
109 | "60000/60000 [==============================] - 17s 278us/sample - loss: 0.0311 - acc: 0.9902\n",
110 | "Epoch 4/20\n",
111 | "60000/60000 [==============================] - 17s 280us/sample - loss: 0.0202 - acc: 0.9936\n",
112 | "Epoch 5/20\n",
113 | "60000/60000 [==============================] - 17s 278us/sample - loss: 0.0137 - acc: 0.9954\n",
114 | "Epoch 6/20\n",
115 | "60000/60000 [==============================] - 17s 277us/sample - loss: 0.0106 - acc: 0.9965\n",
116 | "Epoch 7/20\n",
117 | "60000/60000 [==============================] - 17s 278us/sample - loss: 0.0081 - acc: 0.9973\n",
118 | "Epoch 8/20\n",
119 | "60000/60000 [==============================] - 17s 277us/sample - loss: 0.0068 - acc: 0.9976\n",
120 | "Epoch 9/20\n",
121 | "59840/60000 [============================>.] - ETA: 0s - loss: 0.0046 - acc: 0.9983\n",
122 | "Reached 99.8% accuracy so cancelling training!\n",
123 | "60000/60000 [==============================] - 17s 280us/sample - loss: 0.0046 - acc: 0.9983\n"
124 | ]
125 | }
126 | ],
127 | "source": [
128 | "_, _ = train_mnist_conv()"
129 | ]
130 | },
131 | {
132 | "cell_type": "code",
133 | "execution_count": null,
134 | "metadata": {},
135 | "outputs": [],
136 | "source": [
137 | "# Now click the 'Submit Assignment' button above.\n",
138 | "# Once that is complete, please run the following two cells to save your work and close the notebook"
139 | ]
140 | },
141 | {
142 | "cell_type": "code",
143 | "execution_count": null,
144 | "metadata": {},
145 | "outputs": [],
146 | "source": [
147 | "%%javascript\n",
148 | "\n",
149 | "IPython.notebook.save_checkpoint();"
150 | ]
151 | },
152 | {
153 | "cell_type": "code",
154 | "execution_count": null,
155 | "metadata": {},
156 | "outputs": [],
157 | "source": [
158 | "%%javascript\n",
159 | "\n",
160 | "window.onbeforeunload = null\n",
161 | "window.close();\n",
162 | "IPython.notebook.session.delete();"
163 | ]
164 | }
165 | ],
166 | "metadata": {
167 | "coursera": {
168 | "course_slug": "introduction-tensorflow",
169 | "graded_item_id": "ml06H",
170 | "launcher_item_id": "hQF8A"
171 | },
172 | "kernelspec": {
173 | "display_name": "Python 3",
174 | "language": "python",
175 | "name": "python3"
176 | },
177 | "language_info": {
178 | "codemirror_mode": {
179 | "name": "ipython",
180 | "version": 3
181 | },
182 | "file_extension": ".py",
183 | "mimetype": "text/x-python",
184 | "name": "python",
185 | "nbconvert_exporter": "python",
186 | "pygments_lexer": "ipython3",
187 | "version": "3.7.3"
188 | }
189 | },
190 | "nbformat": 4,
191 | "nbformat_minor": 1
192 | }
193 |
--------------------------------------------------------------------------------
/Course 1 - Introduction to Tensorflow, ML, DL/Exercise4_Handling_Complex_Images.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "colab_type": "text",
7 | "id": "UncprnB0ymAE"
8 | },
9 | "source": [
10 | "Below is code with a link to a happy or sad dataset which contains 80 images, 40 happy and 40 sad. \n",
11 | "Create a convolutional neural network that trains to 100% accuracy on these images, which cancels training upon hitting training accuracy of >.999\n",
12 | "\n",
13 | "Hint -- it will work best with 3 convolutional layers."
14 | ]
15 | },
16 | {
17 | "cell_type": "code",
18 | "execution_count": 1,
19 | "metadata": {},
20 | "outputs": [],
21 | "source": [
22 | "import tensorflow as tf\n",
23 | "import os\n",
24 | "import zipfile\n",
25 | "from os import path, getcwd, chdir\n",
26 | "\n",
27 | "# DO NOT CHANGE THE LINE BELOW. If you are developing in a local\n",
28 | "# environment, then grab happy-or-sad.zip from the Coursera Jupyter Notebook\n",
29 | "# and place it inside a local folder and edit the path to that location\n",
30 | "path = f\"{getcwd()}/../tmp2/happy-or-sad.zip\"\n",
31 | "\n",
32 | "zip_ref = zipfile.ZipFile(path, 'r')\n",
33 | "zip_ref.extractall(\"/tmp/h-or-s\")\n",
34 | "zip_ref.close()"
35 | ]
36 | },
37 | {
38 | "cell_type": "code",
39 | "execution_count": 22,
40 | "metadata": {},
41 | "outputs": [],
42 | "source": [
43 | "# GRADED FUNCTION: train_happy_sad_model\n",
44 | "def train_happy_sad_model():\n",
45 | " # Please write your code only where you are indicated.\n",
46 | " # please do not remove # model fitting inline comments.\n",
47 | "\n",
48 | " DESIRED_ACCURACY = 0.999\n",
49 | "\n",
50 | " class myCallback(tf.keras.callbacks.Callback):\n",
51 | " def on_epoch_end(self, epoch, logs={}):\n",
52 | " if logs.get('acc')>0.999:\n",
53 | " print(\"\\nReached 99.9% accuracy so cancelling training!\")\n",
54 | " self.model.stop_training = True\n",
55 | " callbacks = myCallback()\n",
56 | " \n",
57 | " # This Code Block should Define and Compile the Model. Please assume the images are 150 X 150 in your implementation.\n",
58 | " model = tf.keras.models.Sequential([\n",
59 | " tf.keras.layers.Conv2D(16, (3,3), activation='relu', input_shape=(150,150,3)),\n",
60 | " tf.keras.layers.MaxPooling2D(2,2),\n",
61 | " tf.keras.layers.Conv2D(32, (3,3), activation='relu'),\n",
62 | " tf.keras.layers.MaxPooling2D(2,2),\n",
63 | " tf.keras.layers.Conv2D(64, (3,3), activation='relu'),\n",
64 | " tf.keras.layers.MaxPooling2D(2,2),\n",
65 | " tf.keras.layers.Flatten(),\n",
66 | " tf.keras.layers.Dense(512, activation='relu'),\n",
67 | " tf.keras.layers.Dense(1, activation='sigmoid')\n",
68 | " ])\n",
69 | "\n",
70 | " from tensorflow.keras.optimizers import RMSprop\n",
71 | "\n",
72 | " model.compile(loss='binary_crossentropy',\n",
73 | " optimizer=RMSprop(lr=0.001),\n",
74 | " metrics=['acc'])\n",
75 | "\n",
76 | " # This code block should create an instance of an ImageDataGenerator called train_datagen \n",
77 | " # And a train_generator by calling train_datagen.flow_from_directory\n",
78 | "\n",
79 | " from tensorflow.keras.preprocessing.image import ImageDataGenerator\n",
80 | "\n",
81 | " train_datagen = ImageDataGenerator(rescale=1./255)\n",
82 | "\n",
83 | " # Please use a target_size of 150 X 150.\n",
84 | " train_generator = train_datagen.flow_from_directory(\n",
85 | " \"/tmp/h-or-s/\",\n",
86 | " target_size=(150,150),\n",
87 | " batch_size=4,\n",
88 | " class_mode='binary')\n",
89 | " # Expected output: 'Found 80 images belonging to 2 classes'\n",
90 | "\n",
91 | " # This code block should call model.fit_generator and train for\n",
92 | " # a number of epochs.\n",
93 | " # model fitting\n",
94 | " history = model.fit_generator(\n",
95 | " train_generator,\n",
96 | " steps_per_epoch=20,\n",
97 | " epochs=15,\n",
98 | " callbacks=[callbacks],\n",
99 | " verbose=1)\n",
100 | " # model fitting\n",
101 | " return history.history['acc'][-1]"
102 | ]
103 | },
104 | {
105 | "cell_type": "code",
106 | "execution_count": 23,
107 | "metadata": {},
108 | "outputs": [
109 | {
110 | "name": "stdout",
111 | "output_type": "stream",
112 | "text": [
113 | "Found 80 images belonging to 2 classes.\n",
114 | "Epoch 1/15\n",
115 | "20/20 [==============================] - 3s 150ms/step - loss: 1.5894 - acc: 0.6750\n",
116 | "Epoch 2/15\n",
117 | "20/20 [==============================] - 1s 39ms/step - loss: 0.2161 - acc: 0.9250\n",
118 | "Epoch 3/15\n",
119 | "20/20 [==============================] - 1s 35ms/step - loss: 0.2755 - acc: 0.8875\n",
120 | "Epoch 4/15\n",
121 | "20/20 [==============================] - 1s 35ms/step - loss: 0.1063 - acc: 0.9250\n",
122 | "Epoch 5/15\n",
123 | "20/20 [==============================] - 1s 31ms/step - loss: 0.2442 - acc: 0.9500\n",
124 | "Epoch 6/15\n",
125 | "20/20 [==============================] - 1s 35ms/step - loss: 0.0424 - acc: 0.9875\n",
126 | "Epoch 7/15\n",
127 | "19/20 [===========================>..] - ETA: 0s - loss: 0.0026 - acc: 1.0000 \n",
128 | "Reached 99.9% accuracy so cancelling training!\n",
129 | "20/20 [==============================] - 1s 35ms/step - loss: 0.0026 - acc: 1.0000\n"
130 | ]
131 | },
132 | {
133 | "data": {
134 | "text/plain": [
135 | "1.0"
136 | ]
137 | },
138 | "execution_count": 23,
139 | "metadata": {},
140 | "output_type": "execute_result"
141 | }
142 | ],
143 | "source": [
144 | "# The Expected output: \"Reached 99.9% accuracy so cancelling training!\"\"\n",
145 | "train_happy_sad_model()"
146 | ]
147 | },
148 | {
149 | "cell_type": "code",
150 | "execution_count": null,
151 | "metadata": {},
152 | "outputs": [],
153 | "source": [
154 | "# Now click the 'Submit Assignment' button above.\n",
155 | "# Once that is complete, please run the following two cells to save your work and close the notebook"
156 | ]
157 | },
158 | {
159 | "cell_type": "code",
160 | "execution_count": null,
161 | "metadata": {},
162 | "outputs": [],
163 | "source": [
164 | "%%javascript\n",
165 | "\n",
166 | "IPython.notebook.save_checkpoint();"
167 | ]
168 | },
169 | {
170 | "cell_type": "code",
171 | "execution_count": null,
172 | "metadata": {},
173 | "outputs": [],
174 | "source": [
175 | "%%javascript\n",
176 | "\n",
177 | "window.onbeforeunload = null\n",
178 | "window.close();\n",
179 | "IPython.notebook.session.delete();"
180 | ]
181 | }
182 | ],
183 | "metadata": {
184 | "coursera": {
185 | "course_slug": "introduction-tensorflow",
186 | "graded_item_id": "1kAlw",
187 | "launcher_item_id": "PNLYD"
188 | },
189 | "kernelspec": {
190 | "display_name": "Python 3",
191 | "language": "python",
192 | "name": "python3"
193 | },
194 | "language_info": {
195 | "codemirror_mode": {
196 | "name": "ipython",
197 | "version": 3
198 | },
199 | "file_extension": ".py",
200 | "mimetype": "text/x-python",
201 | "name": "python",
202 | "nbconvert_exporter": "python",
203 | "pygments_lexer": "ipython3",
204 | "version": "3.7.3"
205 | }
206 | },
207 | "nbformat": 4,
208 | "nbformat_minor": 1
209 | }
210 |
--------------------------------------------------------------------------------
/Course 1 - Introduction to Tensorflow, ML, DL/Week 1 Quiz | Coursera.webarchive:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chrismartinis/tensorflow_developer_professional_certificate/e81bdc75b3b3cbd46911ca816445fa07061dcb7a/Course 1 - Introduction to Tensorflow, ML, DL/Week 1 Quiz | Coursera.webarchive
--------------------------------------------------------------------------------
/Course 1 - Introduction to Tensorflow, ML, DL/Week 2 Quiz | Coursera.webarchive:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chrismartinis/tensorflow_developer_professional_certificate/e81bdc75b3b3cbd46911ca816445fa07061dcb7a/Course 1 - Introduction to Tensorflow, ML, DL/Week 2 Quiz | Coursera.webarchive
--------------------------------------------------------------------------------
/Course 1 - Introduction to Tensorflow, ML, DL/Week 3 Quiz | Coursera.webarchive:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chrismartinis/tensorflow_developer_professional_certificate/e81bdc75b3b3cbd46911ca816445fa07061dcb7a/Course 1 - Introduction to Tensorflow, ML, DL/Week 3 Quiz | Coursera.webarchive
--------------------------------------------------------------------------------
/Course 1 - Introduction to Tensorflow, ML, DL/Week 4 Quiz | Coursera.webarchive:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chrismartinis/tensorflow_developer_professional_certificate/e81bdc75b3b3cbd46911ca816445fa07061dcb7a/Course 1 - Introduction to Tensorflow, ML, DL/Week 4 Quiz | Coursera.webarchive
--------------------------------------------------------------------------------
/Course 2 - CNNs in Tensorflow/Week 1 Quiz | Coursera.webarchive:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chrismartinis/tensorflow_developer_professional_certificate/e81bdc75b3b3cbd46911ca816445fa07061dcb7a/Course 2 - CNNs in Tensorflow/Week 1 Quiz | Coursera.webarchive
--------------------------------------------------------------------------------
/Course 2 - CNNs in Tensorflow/Week 2 Quiz | Coursera.webarchive:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chrismartinis/tensorflow_developer_professional_certificate/e81bdc75b3b3cbd46911ca816445fa07061dcb7a/Course 2 - CNNs in Tensorflow/Week 2 Quiz | Coursera.webarchive
--------------------------------------------------------------------------------
/Course 2 - CNNs in Tensorflow/Week 3 Quiz | Coursera.webarchive:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chrismartinis/tensorflow_developer_professional_certificate/e81bdc75b3b3cbd46911ca816445fa07061dcb7a/Course 2 - CNNs in Tensorflow/Week 3 Quiz | Coursera.webarchive
--------------------------------------------------------------------------------
/Course 2 - CNNs in Tensorflow/Week 4 Quiz | Coursera.webarchive:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chrismartinis/tensorflow_developer_professional_certificate/e81bdc75b3b3cbd46911ca816445fa07061dcb7a/Course 2 - CNNs in Tensorflow/Week 4 Quiz | Coursera.webarchive
--------------------------------------------------------------------------------
/Course 3 - NLP in Tensorflow/.ipynb_checkpoints/Course_3_Week_2_Lesson_1-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "metadata": {
7 | "colab": {
8 | "base_uri": "https://localhost:8080/",
9 | "height": 120
10 | },
11 | "colab_type": "code",
12 | "id": "P-AhVYeBWgQ3",
13 | "outputId": "44fd57da-946b-46ad-bcec-13c4ebab05fd"
14 | },
15 | "outputs": [
16 | {
17 | "data": {
18 | "text/html": [
19 | "
\n",
20 | "The default version of TensorFlow in Colab will soon switch to TensorFlow 2.x.
\n",
21 | "We recommend you upgrade now \n",
22 | "or ensure your notebook will continue to use TensorFlow 1.x via the %tensorflow_version 1.x
magic:\n",
23 | "more info.
\n"
24 | ],
25 | "text/plain": [
26 | ""
27 | ]
28 | },
29 | "metadata": {
30 | "tags": []
31 | },
32 | "output_type": "display_data"
33 | },
34 | {
35 | "name": "stdout",
36 | "output_type": "stream",
37 | "text": [
38 | "1.15.0\n"
39 | ]
40 | }
41 | ],
42 | "source": [
43 | "# NOTE: PLEASE MAKE SURE YOU ARE RUNNING THIS IN A PYTHON3 ENVIRONMENT\n",
44 | "\n",
45 | "import tensorflow as tf\n",
46 | "print(tf.__version__)\n",
47 | "\n",
48 | "# This is needed for the iterator over the data\n",
49 | "# But not necessary if you have TF 2.0 installed\n",
50 | "#!pip install tensorflow==2.0.0-beta0\n",
51 | "\n",
52 | "\n",
53 | "tf.enable_eager_execution()\n",
54 | "\n",
55 | "# !pip install -q tensorflow-datasets"
56 | ]
57 | },
58 | {
59 | "cell_type": "code",
60 | "execution_count": 2,
61 | "metadata": {
62 | "colab": {
63 | "base_uri": "https://localhost:8080/",
64 | "height": 178,
65 | "referenced_widgets": [
66 | "80efb775197e4a698556ca8e1c10f390",
67 | "507b451860864588896b19f81459f0a6",
68 | "452c84328cc44bd1b6de1523824ded8f",
69 | "907a77e198f24d21a70b9e92e99f520c",
70 | "e53846ebbdb04aff9050f09e4d90cf4e",
71 | "dc98c6583e1448e9915d79d4cec82828",
72 | "8cd3051f571f49bf8d0a43f2386dd80d",
73 | "187bd45a0fb449fd9d5496d16762cd7a"
74 | ]
75 | },
76 | "colab_type": "code",
77 | "id": "_IoM4VFxWpMR",
78 | "outputId": "6ee29d6c-d258-4cb7-c65f-b19eaeb92a6e"
79 | },
80 | "outputs": [
81 | {
82 | "name": "stdout",
83 | "output_type": "stream",
84 | "text": [
85 | "\u001b[1mDownloading and preparing dataset imdb_reviews (80.23 MiB) to /root/tensorflow_datasets/imdb_reviews/plain_text/1.0.0...\u001b[0m\n"
86 | ]
87 | },
88 | {
89 | "data": {
90 | "application/vnd.jupyter.widget-view+json": {
91 | "model_id": "80efb775197e4a698556ca8e1c10f390",
92 | "version_major": 2,
93 | "version_minor": 0
94 | },
95 | "text/plain": [
96 | "HBox(children=(IntProgress(value=1, bar_style='info', description='Dl Completed...', max=1, style=ProgressStyl…"
97 | ]
98 | },
99 | "metadata": {
100 | "tags": []
101 | },
102 | "output_type": "display_data"
103 | },
104 | {
105 | "data": {
106 | "application/vnd.jupyter.widget-view+json": {
107 | "model_id": "507b451860864588896b19f81459f0a6",
108 | "version_major": 2,
109 | "version_minor": 0
110 | },
111 | "text/plain": [
112 | "HBox(children=(IntProgress(value=1, bar_style='info', description='Dl Size...', max=1, style=ProgressStyle(des…"
113 | ]
114 | },
115 | "metadata": {
116 | "tags": []
117 | },
118 | "output_type": "display_data"
119 | },
120 | {
121 | "name": "stdout",
122 | "output_type": "stream",
123 | "text": [
124 | "\n",
125 | "\n",
126 | "\n"
127 | ]
128 | },
129 | {
130 | "data": {
131 | "application/vnd.jupyter.widget-view+json": {
132 | "model_id": "452c84328cc44bd1b6de1523824ded8f",
133 | "version_major": 2,
134 | "version_minor": 0
135 | },
136 | "text/plain": [
137 | "HBox(children=(IntProgress(value=1, bar_style='info', max=1), HTML(value='')))"
138 | ]
139 | },
140 | "metadata": {
141 | "tags": []
142 | },
143 | "output_type": "display_data"
144 | },
145 | {
146 | "name": "stdout",
147 | "output_type": "stream",
148 | "text": [
149 | "\r",
150 | "Shuffling and writing examples to /root/tensorflow_datasets/imdb_reviews/plain_text/1.0.0.incompleteL5RNYO/imdb_reviews-train.tfrecord\n"
151 | ]
152 | },
153 | {
154 | "data": {
155 | "application/vnd.jupyter.widget-view+json": {
156 | "model_id": "907a77e198f24d21a70b9e92e99f520c",
157 | "version_major": 2,
158 | "version_minor": 0
159 | },
160 | "text/plain": [
161 | "HBox(children=(IntProgress(value=0, max=25000), HTML(value='')))"
162 | ]
163 | },
164 | "metadata": {
165 | "tags": []
166 | },
167 | "output_type": "display_data"
168 | },
169 | {
170 | "name": "stdout",
171 | "output_type": "stream",
172 | "text": [
173 | "\r"
174 | ]
175 | },
176 | {
177 | "data": {
178 | "application/vnd.jupyter.widget-view+json": {
179 | "model_id": "e53846ebbdb04aff9050f09e4d90cf4e",
180 | "version_major": 2,
181 | "version_minor": 0
182 | },
183 | "text/plain": [
184 | "HBox(children=(IntProgress(value=1, bar_style='info', max=1), HTML(value='')))"
185 | ]
186 | },
187 | "metadata": {
188 | "tags": []
189 | },
190 | "output_type": "display_data"
191 | },
192 | {
193 | "name": "stdout",
194 | "output_type": "stream",
195 | "text": [
196 | "\r",
197 | "Shuffling and writing examples to /root/tensorflow_datasets/imdb_reviews/plain_text/1.0.0.incompleteL5RNYO/imdb_reviews-test.tfrecord\n"
198 | ]
199 | },
200 | {
201 | "data": {
202 | "application/vnd.jupyter.widget-view+json": {
203 | "model_id": "dc98c6583e1448e9915d79d4cec82828",
204 | "version_major": 2,
205 | "version_minor": 0
206 | },
207 | "text/plain": [
208 | "HBox(children=(IntProgress(value=0, max=25000), HTML(value='')))"
209 | ]
210 | },
211 | "metadata": {
212 | "tags": []
213 | },
214 | "output_type": "display_data"
215 | },
216 | {
217 | "name": "stdout",
218 | "output_type": "stream",
219 | "text": [
220 | "\r"
221 | ]
222 | },
223 | {
224 | "data": {
225 | "application/vnd.jupyter.widget-view+json": {
226 | "model_id": "8cd3051f571f49bf8d0a43f2386dd80d",
227 | "version_major": 2,
228 | "version_minor": 0
229 | },
230 | "text/plain": [
231 | "HBox(children=(IntProgress(value=1, bar_style='info', max=1), HTML(value='')))"
232 | ]
233 | },
234 | "metadata": {
235 | "tags": []
236 | },
237 | "output_type": "display_data"
238 | },
239 | {
240 | "name": "stdout",
241 | "output_type": "stream",
242 | "text": [
243 | "\r",
244 | "Shuffling and writing examples to /root/tensorflow_datasets/imdb_reviews/plain_text/1.0.0.incompleteL5RNYO/imdb_reviews-unsupervised.tfrecord\n"
245 | ]
246 | },
247 | {
248 | "data": {
249 | "application/vnd.jupyter.widget-view+json": {
250 | "model_id": "187bd45a0fb449fd9d5496d16762cd7a",
251 | "version_major": 2,
252 | "version_minor": 0
253 | },
254 | "text/plain": [
255 | "HBox(children=(IntProgress(value=0, max=50000), HTML(value='')))"
256 | ]
257 | },
258 | "metadata": {
259 | "tags": []
260 | },
261 | "output_type": "display_data"
262 | },
263 | {
264 | "name": "stdout",
265 | "output_type": "stream",
266 | "text": [
267 | "\r",
268 | "\u001b[1mDataset imdb_reviews downloaded and prepared to /root/tensorflow_datasets/imdb_reviews/plain_text/1.0.0. Subsequent calls will reuse this data.\u001b[0m\n"
269 | ]
270 | }
271 | ],
272 | "source": [
273 | "import tensorflow_datasets as tfds\n",
274 | "imdb, info = tfds.load(\"imdb_reviews\", with_info=True, as_supervised=True)\n"
275 | ]
276 | },
277 | {
278 | "cell_type": "code",
279 | "execution_count": 0,
280 | "metadata": {
281 | "colab": {},
282 | "colab_type": "code",
283 | "id": "wHQ2Ko0zl7M4"
284 | },
285 | "outputs": [],
286 | "source": [
287 | "import numpy as np\n",
288 | "\n",
289 | "train_data, test_data = imdb['train'], imdb['test']\n",
290 | "\n",
291 | "training_sentences = []\n",
292 | "training_labels = []\n",
293 | "\n",
294 | "testing_sentences = []\n",
295 | "testing_labels = []\n",
296 | "\n",
297 | "# str(s.tonumpy()) is needed in Python3 instead of just s.numpy()\n",
298 | "for s,l in train_data:\n",
299 | " training_sentences.append(str(s.numpy()))\n",
300 | " training_labels.append(l.numpy())\n",
301 | " \n",
302 | "for s,l in test_data:\n",
303 | " testing_sentences.append(str(s.numpy()))\n",
304 | " testing_labels.append(l.numpy())\n",
305 | " \n",
306 | "training_labels_final = np.array(training_labels)\n",
307 | "testing_labels_final = np.array(testing_labels)\n"
308 | ]
309 | },
310 | {
311 | "cell_type": "code",
312 | "execution_count": 0,
313 | "metadata": {
314 | "colab": {},
315 | "colab_type": "code",
316 | "id": "7n15yyMdmoH1"
317 | },
318 | "outputs": [],
319 | "source": [
320 | "vocab_size = 10000\n",
321 | "embedding_dim = 16\n",
322 | "max_length = 120\n",
323 | "trunc_type='post'\n",
324 | "oov_tok = \"\"\n",
325 | "\n",
326 | "\n",
327 | "from tensorflow.keras.preprocessing.text import Tokenizer\n",
328 | "from tensorflow.keras.preprocessing.sequence import pad_sequences\n",
329 | "\n",
330 | "tokenizer = Tokenizer(num_words = vocab_size, oov_token=oov_tok)\n",
331 | "tokenizer.fit_on_texts(training_sentences)\n",
332 | "word_index = tokenizer.word_index\n",
333 | "sequences = tokenizer.texts_to_sequences(training_sentences)\n",
334 | "padded = pad_sequences(sequences,maxlen=max_length, truncating=trunc_type)\n",
335 | "\n",
336 | "testing_sequences = tokenizer.texts_to_sequences(testing_sentences)\n",
337 | "testing_padded = pad_sequences(testing_sequences,maxlen=max_length)\n",
338 | "\n"
339 | ]
340 | },
341 | {
342 | "cell_type": "code",
343 | "execution_count": 5,
344 | "metadata": {
345 | "colab": {
346 | "base_uri": "https://localhost:8080/",
347 | "height": 72
348 | },
349 | "colab_type": "code",
350 | "id": "9axf0uIXVMhO",
351 | "outputId": "41a96a3b-cd30-4629-ec48-2c5584cca4f5"
352 | },
353 | "outputs": [
354 | {
355 | "name": "stdout",
356 | "output_type": "stream",
357 | "text": [
358 | "? ? ? ? ? ? ? b'i have been known to fall asleep during films but this is usually due to a combination of things including really tired being warm and comfortable on the and having just eaten a lot however on this occasion i fell asleep because the film was rubbish the plot development was constant constantly slow and boring things seemed to happen but with no explanation of what was causing them or why i admit i may have missed part of the film but i watched the majority of it and everything just seemed to happen of its own without any real concern for anything else i cant recommend this film at all '\n",
359 | "b'I have been known to fall asleep during films, but this is usually due to a combination of things including, really tired, being warm and comfortable on the sette and having just eaten a lot. However on this occasion I fell asleep because the film was rubbish. The plot development was constant. Constantly slow and boring. Things seemed to happen, but with no explanation of what was causing them or why. I admit, I may have missed part of the film, but i watched the majority of it and everything just seemed to happen of its own accord without any real concern for anything else. I cant recommend this film at all.'\n"
360 | ]
361 | }
362 | ],
363 | "source": [
364 | "reverse_word_index = dict([(value, key) for (key, value) in word_index.items()])\n",
365 | "\n",
366 | "def decode_review(text):\n",
367 | " return ' '.join([reverse_word_index.get(i, '?') for i in text])\n",
368 | "\n",
369 | "print(decode_review(padded[1]))\n",
370 | "print(training_sentences[1])"
371 | ]
372 | },
373 | {
374 | "cell_type": "code",
375 | "execution_count": 6,
376 | "metadata": {
377 | "colab": {
378 | "base_uri": "https://localhost:8080/",
379 | "height": 319
380 | },
381 | "colab_type": "code",
382 | "id": "5NEpdhb8AxID",
383 | "outputId": "25642b44-017d-4459-cd2d-25f5cb293ccc"
384 | },
385 | "outputs": [
386 | {
387 | "name": "stdout",
388 | "output_type": "stream",
389 | "text": [
390 | "Model: \"sequential\"\n",
391 | "_________________________________________________________________\n",
392 | "Layer (type) Output Shape Param # \n",
393 | "=================================================================\n",
394 | "embedding (Embedding) (None, 120, 16) 160000 \n",
395 | "_________________________________________________________________\n",
396 | "flatten (Flatten) (None, 1920) 0 \n",
397 | "_________________________________________________________________\n",
398 | "dense (Dense) (None, 6) 11526 \n",
399 | "_________________________________________________________________\n",
400 | "dense_1 (Dense) (None, 1) 7 \n",
401 | "=================================================================\n",
402 | "Total params: 171,533\n",
403 | "Trainable params: 171,533\n",
404 | "Non-trainable params: 0\n",
405 | "_________________________________________________________________\n"
406 | ]
407 | }
408 | ],
409 | "source": [
410 | "model = tf.keras.Sequential([\n",
411 | " tf.keras.layers.Embedding(vocab_size, embedding_dim, input_length=max_length),\n",
412 | " tf.keras.layers.Flatten(),\n",
413 | " tf.keras.layers.Dense(6, activation='relu'),\n",
414 | " tf.keras.layers.Dense(1, activation='sigmoid')\n",
415 | "])\n",
416 | "model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])\n",
417 | "model.summary()\n"
418 | ]
419 | },
420 | {
421 | "cell_type": "code",
422 | "execution_count": 7,
423 | "metadata": {
424 | "colab": {
425 | "base_uri": "https://localhost:8080/",
426 | "height": 530
427 | },
428 | "colab_type": "code",
429 | "id": "V5LLrXC-uNX6",
430 | "outputId": "f9531497-46b0-41fd-d109-bb957fc8278a"
431 | },
432 | "outputs": [
433 | {
434 | "name": "stdout",
435 | "output_type": "stream",
436 | "text": [
437 | "Train on 25000 samples, validate on 25000 samples\n",
438 | "Epoch 1/10\n",
439 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/nn_impl.py:183: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.\n",
440 | "Instructions for updating:\n",
441 | "Use tf.where in 2.0, which has the same broadcast rule as np.where\n"
442 | ]
443 | },
444 | {
445 | "name": "stderr",
446 | "output_type": "stream",
447 | "text": [
448 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/nn_impl.py:183: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.\n",
449 | "Instructions for updating:\n",
450 | "Use tf.where in 2.0, which has the same broadcast rule as np.where\n"
451 | ]
452 | },
453 | {
454 | "name": "stdout",
455 | "output_type": "stream",
456 | "text": [
457 | "25000/25000 [==============================] - 12s 479us/sample - loss: 0.4947 - acc: 0.7410 - val_loss: 0.3480 - val_acc: 0.8482\n",
458 | "Epoch 2/10\n",
459 | "25000/25000 [==============================] - 10s 381us/sample - loss: 0.2406 - acc: 0.9080 - val_loss: 0.3649 - val_acc: 0.8429\n",
460 | "Epoch 3/10\n",
461 | "25000/25000 [==============================] - 9s 377us/sample - loss: 0.0924 - acc: 0.9767 - val_loss: 0.4518 - val_acc: 0.8286\n",
462 | "Epoch 4/10\n",
463 | "25000/25000 [==============================] - 9s 376us/sample - loss: 0.0227 - acc: 0.9972 - val_loss: 0.5324 - val_acc: 0.8256\n",
464 | "Epoch 5/10\n",
465 | "25000/25000 [==============================] - 10s 380us/sample - loss: 0.0058 - acc: 0.9996 - val_loss: 0.5964 - val_acc: 0.8244\n",
466 | "Epoch 6/10\n",
467 | "25000/25000 [==============================] - 10s 381us/sample - loss: 0.0018 - acc: 1.0000 - val_loss: 0.6451 - val_acc: 0.8270\n",
468 | "Epoch 7/10\n",
469 | "25000/25000 [==============================] - 10s 381us/sample - loss: 8.4706e-04 - acc: 1.0000 - val_loss: 0.6886 - val_acc: 0.8279\n",
470 | "Epoch 8/10\n",
471 | "25000/25000 [==============================] - 9s 377us/sample - loss: 4.6582e-04 - acc: 1.0000 - val_loss: 0.7281 - val_acc: 0.8281\n",
472 | "Epoch 9/10\n",
473 | "25000/25000 [==============================] - 9s 377us/sample - loss: 3.0540e-04 - acc: 1.0000 - val_loss: 0.7702 - val_acc: 0.8268\n",
474 | "Epoch 10/10\n",
475 | "25000/25000 [==============================] - 9s 375us/sample - loss: 1.6152e-04 - acc: 1.0000 - val_loss: 0.8054 - val_acc: 0.8279\n"
476 | ]
477 | },
478 | {
479 | "data": {
480 | "text/plain": [
481 | ""
482 | ]
483 | },
484 | "execution_count": 7,
485 | "metadata": {
486 | "tags": []
487 | },
488 | "output_type": "execute_result"
489 | }
490 | ],
491 | "source": [
492 | "num_epochs = 10\n",
493 | "model.fit(padded, training_labels_final, epochs=num_epochs, validation_data=(testing_padded, testing_labels_final))"
494 | ]
495 | },
496 | {
497 | "cell_type": "code",
498 | "execution_count": 11,
499 | "metadata": {
500 | "colab": {
501 | "base_uri": "https://localhost:8080/",
502 | "height": 55
503 | },
504 | "colab_type": "code",
505 | "id": "yAmjJqEyCOF_",
506 | "outputId": "5f766549-3c70-4131-80aa-e6262e484c0f"
507 | },
508 | "outputs": [
509 | {
510 | "name": "stdout",
511 | "output_type": "stream",
512 | "text": [
513 | "(10000, 16)\n"
514 | ]
515 | }
516 | ],
517 | "source": [
518 | "e = model.layers[0]\n",
519 | "weights = e.get_weights()[0]\n",
520 | "print(weights.shape) # shape: (vocab_size, embedding_dim)"
521 | ]
522 | },
523 | {
524 | "cell_type": "code",
525 | "execution_count": 0,
526 | "metadata": {
527 | "colab": {},
528 | "colab_type": "code",
529 | "id": "jmB0Uxk0ycP6"
530 | },
531 | "outputs": [],
532 | "source": [
533 | "import io\n",
534 | "\n",
535 | "out_v = io.open('vecs.tsv', 'w', encoding='utf-8')\n",
536 | "out_m = io.open('meta.tsv', 'w', encoding='utf-8')\n",
537 | "for word_num in range(1, vocab_size):\n",
538 | " word = reverse_word_index[word_num]\n",
539 | " embeddings = weights[word_num]\n",
540 | " out_m.write(word + \"\\n\")\n",
541 | " out_v.write('\\t'.join([str(x) for x in embeddings]) + \"\\n\")\n",
542 | "out_v.close()\n",
543 | "out_m.close()"
544 | ]
545 | },
546 | {
547 | "cell_type": "code",
548 | "execution_count": 0,
549 | "metadata": {
550 | "colab": {},
551 | "colab_type": "code",
552 | "id": "VDeqpOCVydtq"
553 | },
554 | "outputs": [],
555 | "source": [
556 | "\n",
557 | "\n",
558 | "try:\n",
559 | " from google.colab import files\n",
560 | "except ImportError:\n",
561 | " pass\n",
562 | "else:\n",
563 | " files.download('vecs.tsv')\n",
564 | " files.download('meta.tsv')"
565 | ]
566 | },
567 | {
568 | "cell_type": "code",
569 | "execution_count": 14,
570 | "metadata": {
571 | "colab": {
572 | "base_uri": "https://localhost:8080/",
573 | "height": 55
574 | },
575 | "colab_type": "code",
576 | "id": "YRxoxc2apscY",
577 | "outputId": "7c091168-73f3-45f8-9ff2-6bf1ecdcb422"
578 | },
579 | "outputs": [
580 | {
581 | "name": "stdout",
582 | "output_type": "stream",
583 | "text": [
584 | "[[11], [], [1431], [966], [4], [1537], [1537], [4715], [], [790], [2019], [11], [2929], [2184], [], [790], [2019], [11], [579], [], [11], [579], [], [4], [1782], [4], [4517], [11], [2929], [1275], [], [], [2019], [1003], [2929], [966], [579], [790], []]\n"
585 | ]
586 | }
587 | ],
588 | "source": [
589 | "sentence = \"I really think this is amazing. honest.\"\n",
590 | "sequence = tokenizer.texts_to_sequences(sentence)\n",
591 | "print(sequence)"
592 | ]
593 | },
594 | {
595 | "cell_type": "code",
596 | "execution_count": 0,
597 | "metadata": {
598 | "colab": {},
599 | "colab_type": "code",
600 | "id": "qajfj2wxrlds"
601 | },
602 | "outputs": [],
603 | "source": []
604 | }
605 | ],
606 | "metadata": {
607 | "accelerator": "GPU",
608 | "colab": {
609 | "collapsed_sections": [],
610 | "name": "Course 3 - Week 2 - Lesson 1.ipynb",
611 | "provenance": []
612 | },
613 | "kernelspec": {
614 | "display_name": "Python 3",
615 | "language": "python",
616 | "name": "python3"
617 | },
618 | "language_info": {
619 | "codemirror_mode": {
620 | "name": "ipython",
621 | "version": 3
622 | },
623 | "file_extension": ".py",
624 | "mimetype": "text/x-python",
625 | "name": "python",
626 | "nbconvert_exporter": "python",
627 | "pygments_lexer": "ipython3",
628 | "version": "3.7.3"
629 | },
630 | "widgets": {
631 | "application/vnd.jupyter.widget-state+json": {
632 | "187bd45a0fb449fd9d5496d16762cd7a": {
633 | "model_module": "@jupyter-widgets/controls",
634 | "model_name": "HBoxModel",
635 | "state": {
636 | "_dom_classes": [],
637 | "_model_module": "@jupyter-widgets/controls",
638 | "_model_module_version": "1.5.0",
639 | "_model_name": "HBoxModel",
640 | "_view_count": null,
641 | "_view_module": "@jupyter-widgets/controls",
642 | "_view_module_version": "1.5.0",
643 | "_view_name": "HBoxView",
644 | "box_style": "",
645 | "children": [
646 | "IPY_MODEL_29e474efe99a4221bea6f1f0ff034556",
647 | "IPY_MODEL_213781a2b52f408899581549c3570c74"
648 | ],
649 | "layout": "IPY_MODEL_74ddb55e411c4127a34933602454d5a1"
650 | }
651 | },
652 | "452c84328cc44bd1b6de1523824ded8f": {
653 | "model_module": "@jupyter-widgets/controls",
654 | "model_name": "HBoxModel",
655 | "state": {
656 | "_dom_classes": [],
657 | "_model_module": "@jupyter-widgets/controls",
658 | "_model_module_version": "1.5.0",
659 | "_model_name": "HBoxModel",
660 | "_view_count": null,
661 | "_view_module": "@jupyter-widgets/controls",
662 | "_view_module_version": "1.5.0",
663 | "_view_name": "HBoxView",
664 | "box_style": "",
665 | "children": [
666 | "IPY_MODEL_b113d733d65843dbba71cb78ce5d7ab9",
667 | "IPY_MODEL_7ce2ec4309ce46c1979396fd1cbeb418"
668 | ],
669 | "layout": "IPY_MODEL_ee332f2a00c648d69e7f35214d75e855"
670 | }
671 | },
672 | "507b451860864588896b19f81459f0a6": {
673 | "model_module": "@jupyter-widgets/controls",
674 | "model_name": "HBoxModel",
675 | "state": {
676 | "_dom_classes": [],
677 | "_model_module": "@jupyter-widgets/controls",
678 | "_model_module_version": "1.5.0",
679 | "_model_name": "HBoxModel",
680 | "_view_count": null,
681 | "_view_module": "@jupyter-widgets/controls",
682 | "_view_module_version": "1.5.0",
683 | "_view_name": "HBoxView",
684 | "box_style": "",
685 | "children": [
686 | "IPY_MODEL_0a4d1c8847294831b4753f07473d5b7a",
687 | "IPY_MODEL_9d949ac3ef7748ed9112366f456a543f"
688 | ],
689 | "layout": "IPY_MODEL_6fddc24e1bc843ec95dea19857acbecc"
690 | }
691 | },
692 | "80efb775197e4a698556ca8e1c10f390": {
693 | "model_module": "@jupyter-widgets/controls",
694 | "model_name": "HBoxModel",
695 | "state": {
696 | "_dom_classes": [],
697 | "_model_module": "@jupyter-widgets/controls",
698 | "_model_module_version": "1.5.0",
699 | "_model_name": "HBoxModel",
700 | "_view_count": null,
701 | "_view_module": "@jupyter-widgets/controls",
702 | "_view_module_version": "1.5.0",
703 | "_view_name": "HBoxView",
704 | "box_style": "",
705 | "children": [
706 | "IPY_MODEL_c82f2d5a8a9146b890367c8251b26d13",
707 | "IPY_MODEL_4c23bb0e8b3141bba56f0ff303d5fa7e"
708 | ],
709 | "layout": "IPY_MODEL_a45938ffd70f4edb9bab657bfe95a95c"
710 | }
711 | },
712 | "8cd3051f571f49bf8d0a43f2386dd80d": {
713 | "model_module": "@jupyter-widgets/controls",
714 | "model_name": "HBoxModel",
715 | "state": {
716 | "_dom_classes": [],
717 | "_model_module": "@jupyter-widgets/controls",
718 | "_model_module_version": "1.5.0",
719 | "_model_name": "HBoxModel",
720 | "_view_count": null,
721 | "_view_module": "@jupyter-widgets/controls",
722 | "_view_module_version": "1.5.0",
723 | "_view_name": "HBoxView",
724 | "box_style": "",
725 | "children": [
726 | "IPY_MODEL_a86a0b98f0e64d58ace06a8084f8c51f",
727 | "IPY_MODEL_5c79c45461944752be0c6acbe233ed5a"
728 | ],
729 | "layout": "IPY_MODEL_3df2d79ef629461fa8a0d231d1ca5dd4"
730 | }
731 | },
732 | "907a77e198f24d21a70b9e92e99f520c": {
733 | "model_module": "@jupyter-widgets/controls",
734 | "model_name": "HBoxModel",
735 | "state": {
736 | "_dom_classes": [],
737 | "_model_module": "@jupyter-widgets/controls",
738 | "_model_module_version": "1.5.0",
739 | "_model_name": "HBoxModel",
740 | "_view_count": null,
741 | "_view_module": "@jupyter-widgets/controls",
742 | "_view_module_version": "1.5.0",
743 | "_view_name": "HBoxView",
744 | "box_style": "",
745 | "children": [
746 | "IPY_MODEL_6c6bc87e2a49411392c0a0bf9bcf1282",
747 | "IPY_MODEL_c6dfeb81a1d242c4a3ec01e6304e9f51"
748 | ],
749 | "layout": "IPY_MODEL_df18e30c64ef4332bfd8f3555b10e4e3"
750 | }
751 | },
752 | "dc98c6583e1448e9915d79d4cec82828": {
753 | "model_module": "@jupyter-widgets/controls",
754 | "model_name": "HBoxModel",
755 | "state": {
756 | "_dom_classes": [],
757 | "_model_module": "@jupyter-widgets/controls",
758 | "_model_module_version": "1.5.0",
759 | "_model_name": "HBoxModel",
760 | "_view_count": null,
761 | "_view_module": "@jupyter-widgets/controls",
762 | "_view_module_version": "1.5.0",
763 | "_view_name": "HBoxView",
764 | "box_style": "",
765 | "children": [
766 | "IPY_MODEL_26b836a3dee3458d88138e24fa28f54c",
767 | "IPY_MODEL_dae4d37502ec406cb7edb661ea6a4b17"
768 | ],
769 | "layout": "IPY_MODEL_4a32eec375e6459586690af483279942"
770 | }
771 | },
772 | "e53846ebbdb04aff9050f09e4d90cf4e": {
773 | "model_module": "@jupyter-widgets/controls",
774 | "model_name": "HBoxModel",
775 | "state": {
776 | "_dom_classes": [],
777 | "_model_module": "@jupyter-widgets/controls",
778 | "_model_module_version": "1.5.0",
779 | "_model_name": "HBoxModel",
780 | "_view_count": null,
781 | "_view_module": "@jupyter-widgets/controls",
782 | "_view_module_version": "1.5.0",
783 | "_view_name": "HBoxView",
784 | "box_style": "",
785 | "children": [
786 | "IPY_MODEL_9bf07899764d4edab95e5508ac4c61c7",
787 | "IPY_MODEL_a1aeae6a10e64063a52151dd8662a503"
788 | ],
789 | "layout": "IPY_MODEL_345a50a817b14137aba7b802f679ebe7"
790 | }
791 | }
792 | }
793 | }
794 | },
795 | "nbformat": 4,
796 | "nbformat_minor": 1
797 | }
798 |
--------------------------------------------------------------------------------
/Course 3 - NLP in Tensorflow/.ipynb_checkpoints/Week3_Exercise-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "metadata": {
7 | "colab": {
8 | "base_uri": "https://localhost:8080/",
9 | "height": 296
10 | },
11 | "colab_type": "code",
12 | "id": "zrZevCPJ92HG",
13 | "outputId": "efa1ee31-aac6-4f35-ef65-86a9095ebe4c"
14 | },
15 | "outputs": [
16 | {
17 | "name": "stdout",
18 | "output_type": "stream",
19 | "text": [
20 | "--2020-02-25 17:00:10-- https://storage.googleapis.com/laurencemoroney-blog.appspot.com/bbc-text.csv\n",
21 | "Resolving storage.googleapis.com (storage.googleapis.com)... 172.217.203.128, 2607:f8b0:400c:c13::80\n",
22 | "Connecting to storage.googleapis.com (storage.googleapis.com)|172.217.203.128|:443... connected.\n",
23 | "HTTP request sent, awaiting response... 200 OK\n",
24 | "Length: 5057493 (4.8M) [application/octet-stream]\n",
25 | "Saving to: ‘/tmp/bbc-text.csv’\n",
26 | "\n",
27 | "\r",
28 | "/tmp/bbc-text.csv 0%[ ] 0 --.-KB/s \r",
29 | "/tmp/bbc-text.csv 100%[===================>] 4.82M --.-KB/s in 0.03s \n",
30 | "\n",
31 | "2020-02-25 17:00:10 (145 MB/s) - ‘/tmp/bbc-text.csv’ saved [5057493/5057493]\n",
32 | "\n"
33 | ]
34 | },
35 | {
36 | "data": {
37 | "text/html": [
38 | "\n",
39 | "The default version of TensorFlow in Colab will soon switch to TensorFlow 2.x.
\n",
40 | "We recommend you upgrade now \n",
41 | "or ensure your notebook will continue to use TensorFlow 1.x via the %tensorflow_version 1.x
magic:\n",
42 | "more info.
\n"
43 | ],
44 | "text/plain": [
45 | ""
46 | ]
47 | },
48 | "metadata": {
49 | "tags": []
50 | },
51 | "output_type": "display_data"
52 | }
53 | ],
54 | "source": [
55 | "!wget --no-check-certificate \\\n",
56 | " https://storage.googleapis.com/laurencemoroney-blog.appspot.com/bbc-text.csv \\\n",
57 | " -O /tmp/bbc-text.csv\n",
58 | "\n",
59 | " \n",
60 | "import csv\n",
61 | "from tensorflow.keras.preprocessing.text import Tokenizer\n",
62 | "from tensorflow.keras.preprocessing.sequence import pad_sequences\n",
63 | "\n",
64 | "\n",
65 | "#Stopwords list from https://github.com/Yoast/YoastSEO.js/blob/develop/src/config/stopwords.js\n",
66 | "# Convert it to a Python list and paste it here\n",
67 | "stopwords = [ \"a\", \"about\", \"above\", \"after\", \"again\", \"against\", \"all\", \"am\", \"an\", \"and\", \"any\", \"are\", \"as\", \"at\", \"be\", \"because\", \"been\", \"before\", \"being\", \"below\", \"between\", \"both\", \"but\", \"by\", \"could\", \"did\", \"do\", \"does\", \"doing\", \"down\", \"during\", \"each\", \"few\", \"for\", \"from\", \"further\", \"had\", \"has\", \"have\", \"having\", \"he\", \"he'd\", \"he'll\", \"he's\", \"her\", \"here\", \"here's\", \"hers\", \"herself\", \"him\", \"himself\", \"his\", \"how\", \"how's\", \"i\", \"i'd\", \"i'll\", \"i'm\", \"i've\", \"if\", \"in\", \"into\", \"is\", \"it\", \"it's\", \"its\", \"itself\", \"let's\", \"me\", \"more\", \"most\", \"my\", \"myself\", \"nor\", \"of\", \"on\", \"once\", \"only\", \"or\", \"other\", \"ought\", \"our\", \"ours\", \"ourselves\", \"out\", \"over\", \"own\", \"same\", \"she\", \"she'd\", \"she'll\", \"she's\", \"should\", \"so\", \"some\", \"such\", \"than\", \"that\", \"that's\", \"the\", \"their\", \"theirs\", \"them\", \"themselves\", \"then\", \"there\", \"there's\", \"these\", \"they\", \"they'd\", \"they'll\", \"they're\", \"they've\", \"this\", \"those\", \"through\", \"to\", \"too\", \"under\", \"until\", \"up\", \"very\", \"was\", \"we\", \"we'd\", \"we'll\", \"we're\", \"we've\", \"were\", \"what\", \"what's\", \"when\", \"when's\", \"where\", \"where's\", \"which\", \"while\", \"who\", \"who's\", \"whom\", \"why\", \"why's\", \"with\", \"would\", \"you\", \"you'd\", \"you'll\", \"you're\", \"you've\", \"your\", \"yours\", \"yourself\", \"yourselves\" ]\n"
68 | ]
69 | },
70 | {
71 | "cell_type": "code",
72 | "execution_count": 9,
73 | "metadata": {
74 | "colab": {
75 | "base_uri": "https://localhost:8080/",
76 | "height": 72
77 | },
78 | "colab_type": "code",
79 | "id": "1rmYBjsyCv3K",
80 | "outputId": "03a933d5-d142-453e-8d85-c7c370952c00"
81 | },
82 | "outputs": [
83 | {
84 | "name": "stdout",
85 | "output_type": "stream",
86 | "text": [
87 | "2225\n",
88 | "tv future hands viewers home theatre systems plasma high-definition tvs digital video recorders moving living room way people watch tv will radically different five years time. according expert panel gathered annual consumer electronics show las vegas discuss new technologies will impact one favourite pastimes. us leading trend programmes content will delivered viewers via home networks cable satellite telecoms companies broadband service providers front rooms portable devices. one talked-about technologies ces digital personal video recorders (dvr pvr). set-top boxes like us s tivo uk s sky+ system allow people record store play pause forward wind tv programmes want. essentially technology allows much personalised tv. also built-in high-definition tv sets big business japan us slower take off europe lack high-definition programming. not can people forward wind adverts can also forget abiding network channel schedules putting together a-la-carte entertainment. us networks cable satellite companies worried means terms advertising revenues well brand identity viewer loyalty channels. although us leads technology moment also concern raised europe particularly growing uptake services like sky+. happens today will see nine months years time uk adam hume bbc broadcast s futurologist told bbc news website. likes bbc no issues lost advertising revenue yet. pressing issue moment commercial uk broadcasters brand loyalty important everyone. will talking content brands rather network brands said tim hanlon brand communications firm starcom mediavest. reality broadband connections anybody can producer content. added: challenge now hard promote programme much choice. means said stacey jolna senior vice president tv guide tv group way people find content want watch simplified tv viewers. means networks us terms channels take leaf google s book search engine future instead scheduler help people find want watch. kind channel model might work younger ipod generation used taking control gadgets play them. might not suit everyone panel recognised. older generations comfortable familiar schedules channel brands know getting. perhaps not want much choice put hands mr hanlon suggested. end kids just diapers pushing buttons already - everything possible available said mr hanlon. ultimately consumer will tell market want. 50 000 new gadgets technologies showcased ces many enhancing tv-watching experience. high-definition tv sets everywhere many new models lcd (liquid crystal display) tvs launched dvr capability built instead external boxes. one example launched show humax s 26-inch lcd tv 80-hour tivo dvr dvd recorder. one us s biggest satellite tv companies directtv even launched branded dvr show 100-hours recording capability instant replay search function. set can pause rewind tv 90 hours. microsoft chief bill gates announced pre-show keynote speech partnership tivo called tivotogo means people can play recorded programmes windows pcs mobile devices. reflect increasing trend freeing multimedia people can watch want want.\n"
89 | ]
90 | }
91 | ],
92 | "source": [
93 | "sentences = []\n",
94 | "labels = []\n",
95 | "with open(\"/tmp/bbc-text.csv\", 'r') as csvfile:\n",
96 | " csv_items = csv.reader(csvfile, delimiter=',')\n",
97 | "\n",
98 | " #skip csv header\n",
99 | " next(csv_items)\n",
100 | "\n",
101 | " for row in csv_items:\n",
102 | " labels.append(row[0])\n",
103 | " unfiltered_sentence = row[1].split()\n",
104 | " filtered_sentence = \" \"\n",
105 | " for word in unfiltered_sentence:\n",
106 | " if word not in stopwords:\n",
107 | " filtered_sentence = filtered_sentence + word + \" \"\n",
108 | " sentences.append(filtered_sentence.strip())\n",
109 | "\n",
110 | "print(len(sentences))\n",
111 | "print(sentences[0])\n",
112 | "\n",
113 | "#Expected output\n",
114 | "# 2225\n",
115 | "# tv future hands viewers home theatre systems plasma high-definition tvs digital video recorders moving living room way people watch tv will radically different five years time. according expert panel gathered annual consumer electronics show las vegas discuss new technologies will impact one favourite pastimes. us leading trend programmes content will delivered viewers via home networks cable satellite telecoms companies broadband service providers front rooms portable devices. one talked-about technologies ces digital personal video recorders (dvr pvr). set-top boxes like us s tivo uk s sky+ system allow people record store play pause forward wind tv programmes want. essentially technology allows much personalised tv. also built-in high-definition tv sets big business japan us slower take off europe lack high-definition programming. not can people forward wind adverts can also forget abiding network channel schedules putting together a-la-carte entertainment. us networks cable satellite companies worried means terms advertising revenues well brand identity viewer loyalty channels. although us leads technology moment also concern raised europe particularly growing uptake services like sky+. happens today will see nine months years time uk adam hume bbc broadcast s futurologist told bbc news website. likes bbc no issues lost advertising revenue yet. pressing issue moment commercial uk broadcasters brand loyalty important everyone. will talking content brands rather network brands said tim hanlon brand communications firm starcom mediavest. reality broadband connections anybody can producer content. added: challenge now hard promote programme much choice. means said stacey jolna senior vice president tv guide tv group way people find content want watch simplified tv viewers. means networks us terms channels take leaf google s book search engine future instead scheduler help people find want watch. kind channel model might work younger ipod generation used taking control gadgets play them. might not suit everyone panel recognised. older generations comfortable familiar schedules channel brands know getting. perhaps not want much choice put hands mr hanlon suggested. end kids just diapers pushing buttons already - everything possible available said mr hanlon. ultimately consumer will tell market want. 50 000 new gadgets technologies showcased ces many enhancing tv-watching experience. high-definition tv sets everywhere many new models lcd (liquid crystal display) tvs launched dvr capability built instead external boxes. one example launched show humax s 26-inch lcd tv 80-hour tivo dvr dvd recorder. one us s biggest satellite tv companies directtv even launched branded dvr show 100-hours recording capability instant replay search function. set can pause rewind tv 90 hours. microsoft chief bill gates announced pre-show keynote speech partnership tivo called tivotogo means people can play recorded programmes windows pcs mobile devices. reflect increasing trend freeing multimedia people can watch want want."
116 | ]
117 | },
118 | {
119 | "cell_type": "code",
120 | "execution_count": 10,
121 | "metadata": {
122 | "colab": {
123 | "base_uri": "https://localhost:8080/",
124 | "height": 55
125 | },
126 | "colab_type": "code",
127 | "id": "9LhzBBgSC3S5",
128 | "outputId": "0102c264-a5af-4e30-8f54-1e0c6801ee22"
129 | },
130 | "outputs": [
131 | {
132 | "name": "stdout",
133 | "output_type": "stream",
134 | "text": [
135 | "29714\n"
136 | ]
137 | }
138 | ],
139 | "source": [
140 | "tokenizer = Tokenizer(oov_token=\"\")\n",
141 | "tokenizer.fit_on_texts(sentences)\n",
142 | "word_index = tokenizer.word_index\n",
143 | "print(len(word_index))\n",
144 | "# Expected output\n",
145 | "# 29714"
146 | ]
147 | },
148 | {
149 | "cell_type": "code",
150 | "execution_count": 11,
151 | "metadata": {
152 | "colab": {
153 | "base_uri": "https://localhost:8080/",
154 | "height": 72
155 | },
156 | "colab_type": "code",
157 | "id": "1Gr3dbQfC5VR",
158 | "outputId": "3bea2352-078f-4d62-e861-0e2f487cafd4"
159 | },
160 | "outputs": [
161 | {
162 | "name": "stdout",
163 | "output_type": "stream",
164 | "text": [
165 | "[ 96 176 1157 ... 0 0 0]\n",
166 | "(2225, 2438)\n"
167 | ]
168 | }
169 | ],
170 | "source": [
171 | "sequences = tokenizer.texts_to_sequences(sentences)\n",
172 | "padded = pad_sequences(sequences, padding='post')\n",
173 | "print(padded[0])\n",
174 | "print(padded.shape)\n",
175 | "\n",
176 | "# Expected output\n",
177 | "# [ 96 176 1158 ... 0 0 0]\n",
178 | "# (2225, 2442)"
179 | ]
180 | },
181 | {
182 | "cell_type": "code",
183 | "execution_count": 12,
184 | "metadata": {
185 | "colab": {
186 | "base_uri": "https://localhost:8080/",
187 | "height": 72
188 | },
189 | "colab_type": "code",
190 | "id": "fZufOahzC6yx",
191 | "outputId": "be7eef17-de0d-4af2-9691-4af4e6f02fda"
192 | },
193 | "outputs": [
194 | {
195 | "name": "stdout",
196 | "output_type": "stream",
197 | "text": [
198 | "[[4], [2], [1], [1], [5], [3], [3], [1], [1], [5], [5], [2], [2], [3], [1], [2], [3], [1], [2], [4], [4], [4], [1], [1], [4], [1], [5], [4], [3], [5], [3], [4], [5], [5], [2], [3], [4], [5], [3], [2], [3], [1], [2], [1], [4], [5], [3], [3], [3], [2], [1], [3], [2], [2], [1], [3], [2], [1], [1], [2], [2], [1], [2], [1], [2], [4], [2], [5], [4], [2], [3], [2], [3], [1], [2], [4], [2], [1], [1], [2], [2], [1], [3], [2], [5], [3], [3], [2], [5], [2], [1], [1], [3], [1], [3], [1], [2], [1], [2], [5], [5], [1], [2], [3], [3], [4], [1], [5], [1], [4], [2], [5], [1], [5], [1], [5], [5], [3], [1], [1], [5], [3], [2], [4], [2], [2], [4], [1], [3], [1], [4], [5], [1], [2], [2], [4], [5], [4], [1], [2], [2], [2], [4], [1], [4], [2], [1], [5], [1], [4], [1], [4], [3], [2], [4], [5], [1], [2], [3], [2], [5], [3], [3], [5], [3], [2], [5], [3], [3], [5], [3], [1], [2], [3], [3], [2], [5], [1], [2], [2], [1], [4], [1], [4], [4], [1], [2], [1], [3], [5], [3], [2], [3], [2], [4], [3], [5], [3], [4], [2], [1], [2], [1], [4], [5], [2], [3], [3], [5], [1], [5], [3], [1], [5], [1], [1], [5], [1], [3], [3], [5], [4], [1], [3], [2], [5], [4], [1], [4], [1], [5], [3], [1], [5], [4], [2], [4], [2], [2], [4], [2], [1], [2], [1], [2], [1], [5], [2], [2], [5], [1], [1], [3], [4], [3], [3], [3], [4], [1], [4], [3], [2], [4], [5], [4], [1], [1], [2], [2], [3], [2], [4], [1], [5], [1], [3], [4], [5], [2], [1], [5], [1], [4], [3], [4], [2], [2], [3], [3], [1], [2], [4], [5], [3], [4], [2], [5], [1], [5], [1], [5], [3], [2], [1], [2], [1], [1], [5], [1], [3], [3], [2], [5], [4], [2], [1], [2], [5], [2], [2], [2], [3], [2], [3], [5], [5], [2], [1], [2], [3], [2], [4], [5], [2], [1], [1], [5], [2], [2], [3], [4], [5], [4], [3], [2], [1], [3], [2], [5], [4], [5], [4], [3], [1], [5], [2], [3], [2], [2], [3], [1], [4], [2], [2], [5], [5], [4], [1], [2], [5], [4], [4], [5], [5], [5], [3], [1], [3], [4], [2], [5], [3], [2], [5], [3], [3], [1], [1], [2], [3], [5], [2], [1], [2], [2], [1], [2], [3], [3], [3], [1], [4], [4], [2], [4], [1], [5], [2], [3], [2], [5], [2], [3], [5], [3], [2], [4], [2], [1], [1], [2], [1], [1], [5], [1], [1], [1], [4], [2], [2], [2], [3], [1], [1], [2], [4], [2], [3], [1], [3], [4], [2], [1], [5], [2], [3], [4], [2], [1], [2], [3], [2], [2], [1], [5], [4], [3], [4], [2], [1], [2], [5], [4], [4], [2], [1], [1], [5], [3], [3], [3], [1], [3], [4], [4], [5], [3], [4], [5], [2], [1], [1], [4], [2], [1], [1], [3], [1], [1], [2], [1], [5], [4], [3], [1], [3], [4], [2], [2], [2], [4], [2], [2], [1], [1], [1], [1], [2], [4], [5], [1], [1], [4], [2], [4], [5], [3], [1], [2], [3], [2], [4], [4], [3], [4], [2], [1], [2], [5], [1], [3], [5], [1], [1], [3], [4], [5], [4], [1], [3], [2], [5], [3], [2], [5], [1], [1], [4], [3], [5], [3], [5], [3], [4], [3], [5], [1], [2], [1], [5], [1], [5], [4], [2], [1], [3], [5], [3], [5], [5], [5], [3], [5], [4], [3], [4], [4], [1], [1], [4], [4], [1], [5], [5], [1], [4], [5], [1], [1], [4], [2], [3], [4], [2], [1], [5], [1], [5], [3], [4], [5], [5], [2], [5], [5], [1], [4], [4], [3], [1], [4], [1], [3], [3], [5], [4], [2], [4], [4], [4], [2], [3], [3], [1], [4], [2], [2], [5], [5], [1], [4], [2], [4], [5], [1], [4], [3], [4], [3], [2], [3], [3], [2], [1], [4], [1], [4], [3], [5], [4], [1], [5], [4], [1], [3], [5], [1], [4], [1], [1], [3], [5], [2], [3], [5], [2], [2], [4], [2], [5], [4], [1], [4], [3], [4], [3], [2], [3], [5], [1], [2], [2], [2], [5], [1], [2], [5], [5], [1], [5], [3], [3], [3], [1], [1], [1], [4], [3], [1], [3], [3], [4], [3], [1], [2], [5], [1], [2], [2], [4], [2], [5], [5], [5], [2], [5], [5], [3], [4], [2], [1], [4], [1], [1], [3], [2], [1], [4], [2], [1], [4], [1], [1], [5], [1], [2], [1], [2], [4], [3], [4], [2], [1], [1], [2], [2], [2], [2], [3], [1], [2], [4], [2], [1], [3], [2], [4], [2], [1], [2], [3], [5], [1], [2], [3], [2], [5], [2], [2], [2], [1], [3], [5], [1], [3], [1], [3], [3], [2], [2], [1], [4], [5], [1], [5], [2], [2], [2], [4], [1], [4], [3], [4], [4], [4], [1], [4], [4], [5], [5], [4], [1], [5], [4], [1], [1], [2], [5], [4], [2], [1], [2], [3], [2], [5], [4], [2], [3], [2], [4], [1], [2], [5], [2], [3], [1], [5], [3], [1], [2], [1], [3], [3], [1], [5], [5], [2], [2], [1], [4], [4], [1], [5], [4], [4], [2], [1], [5], [4], [1], [1], [2], [5], [2], [2], [2], [5], [1], [5], [4], [4], [4], [3], [4], [4], [5], [5], [1], [1], [3], [2], [5], [1], [3], [5], [4], [3], [4], [4], [2], [5], [3], [4], [3], [3], [1], [3], [3], [5], [4], [1], [3], [1], [5], [3], [2], [2], [3], [1], [1], [1], [5], [4], [4], [2], [5], [1], [3], [4], [3], [5], [4], [4], [2], [2], [1], [2], [2], [4], [3], [5], [2], [2], [2], [2], [2], [4], [1], [3], [4], [4], [2], [2], [5], [3], [5], [1], [4], [1], [5], [1], [4], [1], [2], [1], [3], [3], [5], [2], [1], [3], [3], [1], [5], [3], [2], [4], [1], [2], [2], [2], [5], [5], [4], [4], [2], [2], [5], [1], [2], [5], [4], [4], [2], [2], [1], [1], [1], [3], [3], [1], [3], [1], [2], [5], [1], [4], [5], [1], [1], [2], [2], [4], [4], [1], [5], [1], [5], [1], [5], [3], [5], [5], [4], [5], [2], [2], [3], [1], [3], [4], [2], [3], [1], [3], [1], [5], [1], [3], [1], [1], [4], [5], [1], [3], [1], [1], [2], [4], [5], [3], [4], [5], [3], [5], [3], [5], [5], [4], [5], [3], [5], [5], [4], [4], [1], [1], [5], [5], [4], [5], [3], [4], [5], [2], [4], [1], [2], [5], [5], [4], [5], [4], [2], [5], [1], [5], [2], [1], [2], [1], [3], [4], [5], [3], [2], [5], [5], [3], [2], [5], [1], [3], [1], [2], [2], [2], [2], [2], [5], [4], [1], [5], [5], [2], [1], [4], [4], [5], [1], [2], [3], [2], [3], [2], [2], [5], [3], [2], [2], [4], [3], [1], [4], [5], [3], [2], [2], [1], [5], [3], [4], [2], [2], [3], [2], [1], [5], [1], [5], [4], [3], [2], [2], [4], [2], [2], [1], [2], [4], [5], [3], [2], [3], [2], [1], [4], [2], [3], [5], [4], [2], [5], [1], [3], [3], [1], [3], [2], [4], [5], [1], [1], [4], [2], [1], [5], [4], [1], [3], [1], [2], [2], [2], [3], [5], [1], [3], [4], [2], [2], [4], [5], [5], [4], [4], [1], [1], [5], [4], [5], [1], [3], [4], [2], [1], [5], [2], [2], [5], [1], [2], [1], [4], [3], [3], [4], [5], [3], [5], [2], [2], [3], [1], [4], [1], [1], [1], [3], [2], [1], [2], [4], [1], [2], [2], [1], [3], [4], [1], [2], [4], [1], [1], [2], [2], [2], [2], [3], [5], [4], [2], [2], [1], [2], [5], [2], [5], [1], [3], [2], [2], [4], [5], [2], [2], [2], [3], [2], [3], [4], [5], [3], [5], [1], [4], [3], [2], [4], [1], [2], [2], [5], [4], [2], [2], [1], [1], [5], [1], [3], [1], [2], [1], [2], [3], [3], [2], [3], [4], [5], [1], [2], [5], [1], [3], [3], [4], [5], [2], [3], [3], [1], [4], [2], [1], [5], [1], [5], [1], [2], [1], [3], [5], [4], [2], [1], [3], [4], [1], [5], [2], [1], [5], [1], [4], [1], [4], [3], [1], [2], [5], [4], [4], [3], [4], [5], [4], [1], [2], [4], [2], [5], [1], [4], [3], [3], [3], [3], [5], [5], [5], [2], [3], [3], [1], [1], [4], [1], [3], [2], [2], [4], [1], [4], [2], [4], [3], [3], [1], [2], [3], [1], [2], [4], [2], [2], [5], [5], [1], [2], [4], [4], [3], [2], [3], [1], [5], [5], [3], [3], [2], [2], [4], [4], [1], [1], [3], [4], [1], [4], [2], [1], [2], [3], [1], [5], [2], [4], [3], [5], [4], [2], [1], [5], [4], [4], [5], [3], [4], [5], [1], [5], [1], [1], [1], [3], [4], [1], [2], [1], [1], [2], [4], [1], [2], [5], [3], [4], [1], [3], [4], [5], [3], [1], [3], [4], [2], [5], [1], [3], [2], [4], [4], [4], [3], [2], [1], [3], [5], [4], [5], [1], [4], [2], [3], [5], [4], [3], [1], [1], [2], [5], [2], [2], [3], [2], [2], [3], [4], [5], [3], [5], [5], [2], [3], [1], [3], [5], [1], [5], [3], [5], [5], [5], [2], [1], [3], [1], [5], [4], [4], [2], [3], [5], [2], [1], [2], [3], [3], [2], [1], [4], [4], [4], [2], [3], [3], [2], [1], [1], [5], [2], [1], [1], [3], [3], [3], [5], [3], [2], [4], [2], [3], [5], [5], [2], [1], [3], [5], [1], [5], [3], [3], [2], [3], [1], [5], [5], [4], [4], [4], [4], [3], [4], [2], [4], [1], [1], [5], [2], [4], [5], [2], [4], [1], [4], [5], [5], [3], [3], [1], [2], [2], [4], [5], [1], [3], [2], [4], [5], [3], [1], [5], [3], [3], [4], [1], [3], [2], [3], [5], [4], [1], [3], [5], [5], [2], [1], [4], [4], [1], [5], [4], [3], [4], [1], [3], [3], [1], [5], [1], [3], [1], [4], [5], [1], [5], [2], [2], [5], [5], [5], [4], [1], [2], [2], [3], [3], [2], [3], [5], [1], [1], [4], [3], [1], [2], [1], [2], [4], [1], [1], [2], [5], [1], [1], [4], [1], [2], [3], [2], [5], [4], [5], [3], [2], [5], [3], [5], [3], [3], [2], [1], [1], [1], [4], [4], [1], [3], [5], [4], [1], [5], [2], [5], [3], [2], [1], [4], [2], [1], [3], [2], [5], [5], [5], [3], [5], [3], [5], [1], [5], [1], [3], [3], [2], [3], [4], [1], [4], [1], [2], [3], [4], [5], [5], [3], [5], [3], [1], [1], [3], [2], [4], [1], [3], [3], [5], [1], [3], [3], [2], [4], [4], [2], [4], [1], [1], [2], [3], [2], [4], [1], [4], [3], [5], [1], [2], [1], [5], [4], [4], [1], [3], [1], [2], [1], [2], [1], [1], [5], [5], [2], [4], [4], [2], [4], [2], [2], [1], [1], [3], [1], [4], [1], [4], [1], [1], [2], [2], [4], [1], [2], [4], [4], [3], [1], [2], [5], [5], [4], [3], [1], [1], [4], [2], [4], [5], [5], [3], [3], [2], [5], [1], [5], [5], [2], [1], [3], [4], [2], [1], [5], [4], [3], [3], [1], [1], [2], [2], [2], [2], [2], [5], [2], [3], [3], [4], [4], [5], [3], [5], [2], [3], [1], [1], [2], [4], [2], [4], [1], [2], [2], [3], [1], [1], [3], [3], [5], [5], [3], [2], [3], [3], [2], [4], [3], [3], [3], [3], [3], [5], [5], [4], [3], [1], [3], [1], [4], [1], [1], [1], [5], [4], [5], [4], [1], [4], [1], [1], [5], [5], [2], [5], [5], [3], [2], [1], [4], [4], [3], [2], [1], [2], [5], [1], [3], [5], [1], [1], [2], [3], [4], [4], [2], [2], [1], [3], [5], [1], [1], [3], [5], [4], [1], [5], [2], [3], [1], [3], [4], [5], [1], [3], [2], [5], [3], [5], [3], [1], [3], [2], [2], [3], [2], [4], [1], [2], [5], [2], [1], [1], [5], [4], [3], [4], [3], [3], [1], [1], [1], [2], [4], [5], [2], [1], [2], [1], [2], [4], [2], [2], [2], [2], [1], [1], [1], [2], [2], [5], [2], [2], [2], [1], [1], [1], [4], [2], [1], [1], [1], [2], [5], [4], [4], [4], [3], [2], [2], [4], [2], [4], [1], [1], [3], [3], [3], [1], [1], [3], [3], [4], [2], [1], [1], [1], [1], [2], [1], [2], [2], [2], [2], [1], [3], [1], [4], [4], [1], [4], [2], [5], [2], [1], [2], [4], [4], [3], [5], [2], [5], [2], [4], [3], [5], [3], [5], [5], [4], [2], [4], [4], [2], [3], [1], [5], [2], [3], [5], [2], [4], [1], [4], [3], [1], [3], [2], [3], [3], [2], [2], [2], [4], [3], [2], [3], [2], [5], [3], [1], [3], [3], [1], [5], [4], [4], [2], [4], [1], [2], [2], [3], [1], [4], [4], [4], [1], [5], [1], [3], [2], [3], [3], [5], [4], [2], [4], [1], [5], [5], [1], [2], [5], [4], [4], [1], [5], [2], [3], [3], [3], [4], [4], [2], [3], [2], [3], [3], [5], [1], [4], [2], [4], [5], [4], [4], [1], [3], [1], [1], [3], [5], [5], [2], [3], [3], [1], [2], [2], [4], [2], [4], [4], [1], [2], [3], [1], [2], [2], [1], [4], [1], [4], [5], [1], [1], [5], [2], [4], [1], [1], [3], [4], [2], [3], [1], [1], [3], [5], [4], [4], [4], [2], [1], [5], [5], [4], [2], [3], [4], [1], [1], [4], [4], [3], [2], [1], [5], [5], [1], [5], [4], [4], [2], [2], [2], [1], [1], [4], [1], [2], [4], [2], [2], [1], [2], [3], [2], [2], [4], [2], [4], [3], [4], [5], [3], [4], [5], [1], [3], [5], [2], [4], [2], [4], [5], [4], [1], [2], [2], [3], [5], [3], [1]]\n",
199 | "{'sport': 1, 'business': 2, 'politics': 3, 'tech': 4, 'entertainment': 5}\n"
200 | ]
201 | }
202 | ],
203 | "source": [
204 | "label_tokenizer = Tokenizer()\n",
205 | "label_tokenizer.fit_on_texts(labels)\n",
206 | "label_word_index = label_tokenizer.word_index\n",
207 | "label_seq = label_tokenizer.texts_to_sequences(labels)\n",
208 | "print(label_seq)\n",
209 | "print(label_word_index)\n",
210 | "\n",
211 | "# Expected Output\n",
212 | "# [[4], [2], [1], [1], [5], [3], [3], [1], [1], [5], [5], [2], [2], [3], [1], [2], [3], [1], [2], [4], [4], [4], [1], [1], [4], [1], [5], [4], [3], [5], [3], [4], [5], [5], [2], [3], [4], [5], [3], [2], [3], [1], [2], [1], [4], [5], [3], [3], [3], [2], [1], [3], [2], [2], [1], [3], [2], [1], [1], [2], [2], [1], [2], [1], [2], [4], [2], [5], [4], [2], [3], [2], [3], [1], [2], [4], [2], [1], [1], [2], [2], [1], [3], [2], [5], [3], [3], [2], [5], [2], [1], [1], [3], [1], [3], [1], [2], [1], [2], [5], [5], [1], [2], [3], [3], [4], [1], [5], [1], [4], [2], [5], [1], [5], [1], [5], [5], [3], [1], [1], [5], [3], [2], [4], [2], [2], [4], [1], [3], [1], [4], [5], [1], [2], [2], [4], [5], [4], [1], [2], [2], [2], [4], [1], [4], [2], [1], [5], [1], [4], [1], [4], [3], [2], [4], [5], [1], [2], [3], [2], [5], [3], [3], [5], [3], [2], [5], [3], [3], [5], [3], [1], [2], [3], [3], [2], [5], [1], [2], [2], [1], [4], [1], [4], [4], [1], [2], [1], [3], [5], [3], [2], [3], [2], [4], [3], [5], [3], [4], [2], [1], [2], [1], [4], [5], [2], [3], [3], [5], [1], [5], [3], [1], [5], [1], [1], [5], [1], [3], [3], [5], [4], [1], [3], [2], [5], [4], [1], [4], [1], [5], [3], [1], [5], [4], [2], [4], [2], [2], [4], [2], [1], [2], [1], [2], [1], [5], [2], [2], [5], [1], [1], [3], [4], [3], [3], [3], [4], [1], [4], [3], [2], [4], [5], [4], [1], [1], [2], [2], [3], [2], [4], [1], [5], [1], [3], [4], [5], [2], [1], [5], [1], [4], [3], [4], [2], [2], [3], [3], [1], [2], [4], [5], [3], [4], [2], [5], [1], [5], [1], [5], [3], [2], [1], [2], [1], [1], [5], [1], [3], [3], [2], [5], [4], [2], [1], [2], [5], [2], [2], [2], [3], [2], [3], [5], [5], [2], [1], [2], [3], [2], [4], [5], [2], [1], [1], [5], [2], [2], [3], [4], [5], [4], [3], [2], [1], [3], [2], [5], [4], [5], [4], [3], [1], [5], [2], [3], [2], [2], [3], [1], [4], [2], [2], [5], [5], [4], [1], [2], [5], [4], [4], [5], [5], [5], [3], [1], [3], [4], [2], [5], [3], [2], [5], [3], [3], [1], [1], [2], [3], [5], [2], [1], [2], [2], [1], [2], [3], [3], [3], [1], [4], [4], [2], [4], [1], [5], [2], [3], [2], [5], [2], [3], [5], [3], [2], [4], [2], [1], [1], [2], [1], [1], [5], [1], [1], [1], [4], [2], [2], [2], [3], [1], [1], [2], [4], [2], [3], [1], [3], [4], [2], [1], [5], [2], [3], [4], [2], [1], [2], [3], [2], [2], [1], [5], [4], [3], [4], [2], [1], [2], [5], [4], [4], [2], [1], [1], [5], [3], [3], [3], [1], [3], [4], [4], [5], [3], [4], [5], [2], [1], [1], [4], [2], [1], [1], [3], [1], [1], [2], [1], [5], [4], [3], [1], [3], [4], [2], [2], [2], [4], [2], [2], [1], [1], [1], [1], [2], [4], [5], [1], [1], [4], [2], [4], [5], [3], [1], [2], [3], [2], [4], [4], [3], [4], [2], [1], [2], [5], [1], [3], [5], [1], [1], [3], [4], [5], [4], [1], [3], [2], [5], [3], [2], [5], [1], [1], [4], [3], [5], [3], [5], [3], [4], [3], [5], [1], [2], [1], [5], [1], [5], [4], [2], [1], [3], [5], [3], [5], [5], [5], [3], [5], [4], [3], [4], [4], [1], [1], [4], [4], [1], [5], [5], [1], [4], [5], [1], [1], [4], [2], [3], [4], [2], [1], [5], [1], [5], [3], [4], [5], [5], [2], [5], [5], [1], [4], [4], [3], [1], [4], [1], [3], [3], [5], [4], [2], [4], [4], [4], [2], [3], [3], [1], [4], [2], [2], [5], [5], [1], [4], [2], [4], [5], [1], [4], [3], [4], [3], [2], [3], [3], [2], [1], [4], [1], [4], [3], [5], [4], [1], [5], [4], [1], [3], [5], [1], [4], [1], [1], [3], [5], [2], [3], [5], [2], [2], [4], [2], [5], [4], [1], [4], [3], [4], [3], [2], [3], [5], [1], [2], [2], [2], [5], [1], [2], [5], [5], [1], [5], [3], [3], [3], [1], [1], [1], [4], [3], [1], [3], [3], [4], [3], [1], [2], [5], [1], [2], [2], [4], [2], [5], [5], [5], [2], [5], [5], [3], [4], [2], [1], [4], [1], [1], [3], [2], [1], [4], [2], [1], [4], [1], [1], [5], [1], [2], [1], [2], [4], [3], [4], [2], [1], [1], [2], [2], [2], [2], [3], [1], [2], [4], [2], [1], [3], [2], [4], [2], [1], [2], [3], [5], [1], [2], [3], [2], [5], [2], [2], [2], [1], [3], [5], [1], [3], [1], [3], [3], [2], [2], [1], [4], [5], [1], [5], [2], [2], [2], [4], [1], [4], [3], [4], [4], [4], [1], [4], [4], [5], [5], [4], [1], [5], [4], [1], [1], [2], [5], [4], [2], [1], [2], [3], [2], [5], [4], [2], [3], [2], [4], [1], [2], [5], [2], [3], [1], [5], [3], [1], [2], [1], [3], [3], [1], [5], [5], [2], [2], [1], [4], [4], [1], [5], [4], [4], [2], [1], [5], [4], [1], [1], [2], [5], [2], [2], [2], [5], [1], [5], [4], [4], [4], [3], [4], [4], [5], [5], [1], [1], [3], [2], [5], [1], [3], [5], [4], [3], [4], [4], [2], [5], [3], [4], [3], [3], [1], [3], [3], [5], [4], [1], [3], [1], [5], [3], [2], [2], [3], [1], [1], [1], [5], [4], [4], [2], [5], [1], [3], [4], [3], [5], [4], [4], [2], [2], [1], [2], [2], [4], [3], [5], [2], [2], [2], [2], [2], [4], [1], [3], [4], [4], [2], [2], [5], [3], [5], [1], [4], [1], [5], [1], [4], [1], [2], [1], [3], [3], [5], [2], [1], [3], [3], [1], [5], [3], [2], [4], [1], [2], [2], [2], [5], [5], [4], [4], [2], [2], [5], [1], [2], [5], [4], [4], [2], [2], [1], [1], [1], [3], [3], [1], [3], [1], [2], [5], [1], [4], [5], [1], [1], [2], [2], [4], [4], [1], [5], [1], [5], [1], [5], [3], [5], [5], [4], [5], [2], [2], [3], [1], [3], [4], [2], [3], [1], [3], [1], [5], [1], [3], [1], [1], [4], [5], [1], [3], [1], [1], [2], [4], [5], [3], [4], [5], [3], [5], [3], [5], [5], [4], [5], [3], [5], [5], [4], [4], [1], [1], [5], [5], [4], [5], [3], [4], [5], [2], [4], [1], [2], [5], [5], [4], [5], [4], [2], [5], [1], [5], [2], [1], [2], [1], [3], [4], [5], [3], [2], [5], [5], [3], [2], [5], [1], [3], [1], [2], [2], [2], [2], [2], [5], [4], [1], [5], [5], [2], [1], [4], [4], [5], [1], [2], [3], [2], [3], [2], [2], [5], [3], [2], [2], [4], [3], [1], [4], [5], [3], [2], [2], [1], [5], [3], [4], [2], [2], [3], [2], [1], [5], [1], [5], [4], [3], [2], [2], [4], [2], [2], [1], [2], [4], [5], [3], [2], [3], [2], [1], [4], [2], [3], [5], [4], [2], [5], [1], [3], [3], [1], [3], [2], [4], [5], [1], [1], [4], [2], [1], [5], [4], [1], [3], [1], [2], [2], [2], [3], [5], [1], [3], [4], [2], [2], [4], [5], [5], [4], [4], [1], [1], [5], [4], [5], [1], [3], [4], [2], [1], [5], [2], [2], [5], [1], [2], [1], [4], [3], [3], [4], [5], [3], [5], [2], [2], [3], [1], [4], [1], [1], [1], [3], [2], [1], [2], [4], [1], [2], [2], [1], [3], [4], [1], [2], [4], [1], [1], [2], [2], [2], [2], [3], [5], [4], [2], [2], [1], [2], [5], [2], [5], [1], [3], [2], [2], [4], [5], [2], [2], [2], [3], [2], [3], [4], [5], [3], [5], [1], [4], [3], [2], [4], [1], [2], [2], [5], [4], [2], [2], [1], [1], [5], [1], [3], [1], [2], [1], [2], [3], [3], [2], [3], [4], [5], [1], [2], [5], [1], [3], [3], [4], [5], [2], [3], [3], [1], [4], [2], [1], [5], [1], [5], [1], [2], [1], [3], [5], [4], [2], [1], [3], [4], [1], [5], [2], [1], [5], [1], [4], [1], [4], [3], [1], [2], [5], [4], [4], [3], [4], [5], [4], [1], [2], [4], [2], [5], [1], [4], [3], [3], [3], [3], [5], [5], [5], [2], [3], [3], [1], [1], [4], [1], [3], [2], [2], [4], [1], [4], [2], [4], [3], [3], [1], [2], [3], [1], [2], [4], [2], [2], [5], [5], [1], [2], [4], [4], [3], [2], [3], [1], [5], [5], [3], [3], [2], [2], [4], [4], [1], [1], [3], [4], [1], [4], [2], [1], [2], [3], [1], [5], [2], [4], [3], [5], [4], [2], [1], [5], [4], [4], [5], [3], [4], [5], [1], [5], [1], [1], [1], [3], [4], [1], [2], [1], [1], [2], [4], [1], [2], [5], [3], [4], [1], [3], [4], [5], [3], [1], [3], [4], [2], [5], [1], [3], [2], [4], [4], [4], [3], [2], [1], [3], [5], [4], [5], [1], [4], [2], [3], [5], [4], [3], [1], [1], [2], [5], [2], [2], [3], [2], [2], [3], [4], [5], [3], [5], [5], [2], [3], [1], [3], [5], [1], [5], [3], [5], [5], [5], [2], [1], [3], [1], [5], [4], [4], [2], [3], [5], [2], [1], [2], [3], [3], [2], [1], [4], [4], [4], [2], [3], [3], [2], [1], [1], [5], [2], [1], [1], [3], [3], [3], [5], [3], [2], [4], [2], [3], [5], [5], [2], [1], [3], [5], [1], [5], [3], [3], [2], [3], [1], [5], [5], [4], [4], [4], [4], [3], [4], [2], [4], [1], [1], [5], [2], [4], [5], [2], [4], [1], [4], [5], [5], [3], [3], [1], [2], [2], [4], [5], [1], [3], [2], [4], [5], [3], [1], [5], [3], [3], [4], [1], [3], [2], [3], [5], [4], [1], [3], [5], [5], [2], [1], [4], [4], [1], [5], [4], [3], [4], [1], [3], [3], [1], [5], [1], [3], [1], [4], [5], [1], [5], [2], [2], [5], [5], [5], [4], [1], [2], [2], [3], [3], [2], [3], [5], [1], [1], [4], [3], [1], [2], [1], [2], [4], [1], [1], [2], [5], [1], [1], [4], [1], [2], [3], [2], [5], [4], [5], [3], [2], [5], [3], [5], [3], [3], [2], [1], [1], [1], [4], [4], [1], [3], [5], [4], [1], [5], [2], [5], [3], [2], [1], [4], [2], [1], [3], [2], [5], [5], [5], [3], [5], [3], [5], [1], [5], [1], [3], [3], [2], [3], [4], [1], [4], [1], [2], [3], [4], [5], [5], [3], [5], [3], [1], [1], [3], [2], [4], [1], [3], [3], [5], [1], [3], [3], [2], [4], [4], [2], [4], [1], [1], [2], [3], [2], [4], [1], [4], [3], [5], [1], [2], [1], [5], [4], [4], [1], [3], [1], [2], [1], [2], [1], [1], [5], [5], [2], [4], [4], [2], [4], [2], [2], [1], [1], [3], [1], [4], [1], [4], [1], [1], [2], [2], [4], [1], [2], [4], [4], [3], [1], [2], [5], [5], [4], [3], [1], [1], [4], [2], [4], [5], [5], [3], [3], [2], [5], [1], [5], [5], [2], [1], [3], [4], [2], [1], [5], [4], [3], [3], [1], [1], [2], [2], [2], [2], [2], [5], [2], [3], [3], [4], [4], [5], [3], [5], [2], [3], [1], [1], [2], [4], [2], [4], [1], [2], [2], [3], [1], [1], [3], [3], [5], [5], [3], [2], [3], [3], [2], [4], [3], [3], [3], [3], [3], [5], [5], [4], [3], [1], [3], [1], [4], [1], [1], [1], [5], [4], [5], [4], [1], [4], [1], [1], [5], [5], [2], [5], [5], [3], [2], [1], [4], [4], [3], [2], [1], [2], [5], [1], [3], [5], [1], [1], [2], [3], [4], [4], [2], [2], [1], [3], [5], [1], [1], [3], [5], [4], [1], [5], [2], [3], [1], [3], [4], [5], [1], [3], [2], [5], [3], [5], [3], [1], [3], [2], [2], [3], [2], [4], [1], [2], [5], [2], [1], [1], [5], [4], [3], [4], [3], [3], [1], [1], [1], [2], [4], [5], [2], [1], [2], [1], [2], [4], [2], [2], [2], [2], [1], [1], [1], [2], [2], [5], [2], [2], [2], [1], [1], [1], [4], [2], [1], [1], [1], [2], [5], [4], [4], [4], [3], [2], [2], [4], [2], [4], [1], [1], [3], [3], [3], [1], [1], [3], [3], [4], [2], [1], [1], [1], [1], [2], [1], [2], [2], [2], [2], [1], [3], [1], [4], [4], [1], [4], [2], [5], [2], [1], [2], [4], [4], [3], [5], [2], [5], [2], [4], [3], [5], [3], [5], [5], [4], [2], [4], [4], [2], [3], [1], [5], [2], [3], [5], [2], [4], [1], [4], [3], [1], [3], [2], [3], [3], [2], [2], [2], [4], [3], [2], [3], [2], [5], [3], [1], [3], [3], [1], [5], [4], [4], [2], [4], [1], [2], [2], [3], [1], [4], [4], [4], [1], [5], [1], [3], [2], [3], [3], [5], [4], [2], [4], [1], [5], [5], [1], [2], [5], [4], [4], [1], [5], [2], [3], [3], [3], [4], [4], [2], [3], [2], [3], [3], [5], [1], [4], [2], [4], [5], [4], [4], [1], [3], [1], [1], [3], [5], [5], [2], [3], [3], [1], [2], [2], [4], [2], [4], [4], [1], [2], [3], [1], [2], [2], [1], [4], [1], [4], [5], [1], [1], [5], [2], [4], [1], [1], [3], [4], [2], [3], [1], [1], [3], [5], [4], [4], [4], [2], [1], [5], [5], [4], [2], [3], [4], [1], [1], [4], [4], [3], [2], [1], [5], [5], [1], [5], [4], [4], [2], [2], [2], [1], [1], [4], [1], [2], [4], [2], [2], [1], [2], [3], [2], [2], [4], [2], [4], [3], [4], [5], [3], [4], [5], [1], [3], [5], [2], [4], [2], [4], [5], [4], [1], [2], [2], [3], [5], [3], [1]]\n",
213 | "# {'sport': 1, 'business': 2, 'politics': 3, 'tech': 4, 'entertainment': 5}"
214 | ]
215 | },
216 | {
217 | "cell_type": "code",
218 | "execution_count": 0,
219 | "metadata": {
220 | "colab": {},
221 | "colab_type": "code",
222 | "id": "E7WuGkVJWjdk"
223 | },
224 | "outputs": [],
225 | "source": []
226 | }
227 | ],
228 | "metadata": {
229 | "colab": {
230 | "machine_shape": "hm",
231 | "name": "Exercise-question.ipynb",
232 | "provenance": []
233 | },
234 | "kernelspec": {
235 | "display_name": "Python 3",
236 | "language": "python",
237 | "name": "python3"
238 | },
239 | "language_info": {
240 | "codemirror_mode": {
241 | "name": "ipython",
242 | "version": 3
243 | },
244 | "file_extension": ".py",
245 | "mimetype": "text/x-python",
246 | "name": "python",
247 | "nbconvert_exporter": "python",
248 | "pygments_lexer": "ipython3",
249 | "version": "3.7.3"
250 | }
251 | },
252 | "nbformat": 4,
253 | "nbformat_minor": 1
254 | }
255 |
--------------------------------------------------------------------------------
/Course 3 - NLP in Tensorflow/.ipynb_checkpoints/week3_Exercise1_question-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "metadata": {
7 | "colab": {
8 | "base_uri": "https://localhost:8080/",
9 | "height": 296
10 | },
11 | "colab_type": "code",
12 | "id": "zrZevCPJ92HG",
13 | "outputId": "efa1ee31-aac6-4f35-ef65-86a9095ebe4c"
14 | },
15 | "outputs": [
16 | {
17 | "name": "stdout",
18 | "output_type": "stream",
19 | "text": [
20 | "--2020-02-25 17:00:10-- https://storage.googleapis.com/laurencemoroney-blog.appspot.com/bbc-text.csv\n",
21 | "Resolving storage.googleapis.com (storage.googleapis.com)... 172.217.203.128, 2607:f8b0:400c:c13::80\n",
22 | "Connecting to storage.googleapis.com (storage.googleapis.com)|172.217.203.128|:443... connected.\n",
23 | "HTTP request sent, awaiting response... 200 OK\n",
24 | "Length: 5057493 (4.8M) [application/octet-stream]\n",
25 | "Saving to: ‘/tmp/bbc-text.csv’\n",
26 | "\n",
27 | "\r",
28 | "/tmp/bbc-text.csv 0%[ ] 0 --.-KB/s \r",
29 | "/tmp/bbc-text.csv 100%[===================>] 4.82M --.-KB/s in 0.03s \n",
30 | "\n",
31 | "2020-02-25 17:00:10 (145 MB/s) - ‘/tmp/bbc-text.csv’ saved [5057493/5057493]\n",
32 | "\n"
33 | ]
34 | },
35 | {
36 | "data": {
37 | "text/html": [
38 | "\n",
39 | "The default version of TensorFlow in Colab will soon switch to TensorFlow 2.x.
\n",
40 | "We recommend you upgrade now \n",
41 | "or ensure your notebook will continue to use TensorFlow 1.x via the %tensorflow_version 1.x
magic:\n",
42 | "more info.
\n"
43 | ],
44 | "text/plain": [
45 | ""
46 | ]
47 | },
48 | "metadata": {
49 | "tags": []
50 | },
51 | "output_type": "display_data"
52 | }
53 | ],
54 | "source": [
55 | "!wget --no-check-certificate \\\n",
56 | " https://storage.googleapis.com/laurencemoroney-blog.appspot.com/bbc-text.csv \\\n",
57 | " -O /tmp/bbc-text.csv\n",
58 | "\n",
59 | " \n",
60 | "import csv\n",
61 | "from tensorflow.keras.preprocessing.text import Tokenizer\n",
62 | "from tensorflow.keras.preprocessing.sequence import pad_sequences\n",
63 | "\n",
64 | "\n",
65 | "#Stopwords list from https://github.com/Yoast/YoastSEO.js/blob/develop/src/config/stopwords.js\n",
66 | "# Convert it to a Python list and paste it here\n",
67 | "stopwords = [ \"a\", \"about\", \"above\", \"after\", \"again\", \"against\", \"all\", \"am\", \"an\", \"and\", \"any\", \"are\", \"as\", \"at\", \"be\", \"because\", \"been\", \"before\", \"being\", \"below\", \"between\", \"both\", \"but\", \"by\", \"could\", \"did\", \"do\", \"does\", \"doing\", \"down\", \"during\", \"each\", \"few\", \"for\", \"from\", \"further\", \"had\", \"has\", \"have\", \"having\", \"he\", \"he'd\", \"he'll\", \"he's\", \"her\", \"here\", \"here's\", \"hers\", \"herself\", \"him\", \"himself\", \"his\", \"how\", \"how's\", \"i\", \"i'd\", \"i'll\", \"i'm\", \"i've\", \"if\", \"in\", \"into\", \"is\", \"it\", \"it's\", \"its\", \"itself\", \"let's\", \"me\", \"more\", \"most\", \"my\", \"myself\", \"nor\", \"of\", \"on\", \"once\", \"only\", \"or\", \"other\", \"ought\", \"our\", \"ours\", \"ourselves\", \"out\", \"over\", \"own\", \"same\", \"she\", \"she'd\", \"she'll\", \"she's\", \"should\", \"so\", \"some\", \"such\", \"than\", \"that\", \"that's\", \"the\", \"their\", \"theirs\", \"them\", \"themselves\", \"then\", \"there\", \"there's\", \"these\", \"they\", \"they'd\", \"they'll\", \"they're\", \"they've\", \"this\", \"those\", \"through\", \"to\", \"too\", \"under\", \"until\", \"up\", \"very\", \"was\", \"we\", \"we'd\", \"we'll\", \"we're\", \"we've\", \"were\", \"what\", \"what's\", \"when\", \"when's\", \"where\", \"where's\", \"which\", \"while\", \"who\", \"who's\", \"whom\", \"why\", \"why's\", \"with\", \"would\", \"you\", \"you'd\", \"you'll\", \"you're\", \"you've\", \"your\", \"yours\", \"yourself\", \"yourselves\" ]\n"
68 | ]
69 | },
70 | {
71 | "cell_type": "code",
72 | "execution_count": 9,
73 | "metadata": {
74 | "colab": {
75 | "base_uri": "https://localhost:8080/",
76 | "height": 72
77 | },
78 | "colab_type": "code",
79 | "id": "1rmYBjsyCv3K",
80 | "outputId": "03a933d5-d142-453e-8d85-c7c370952c00"
81 | },
82 | "outputs": [
83 | {
84 | "name": "stdout",
85 | "output_type": "stream",
86 | "text": [
87 | "2225\n",
88 | "tv future hands viewers home theatre systems plasma high-definition tvs digital video recorders moving living room way people watch tv will radically different five years time. according expert panel gathered annual consumer electronics show las vegas discuss new technologies will impact one favourite pastimes. us leading trend programmes content will delivered viewers via home networks cable satellite telecoms companies broadband service providers front rooms portable devices. one talked-about technologies ces digital personal video recorders (dvr pvr). set-top boxes like us s tivo uk s sky+ system allow people record store play pause forward wind tv programmes want. essentially technology allows much personalised tv. also built-in high-definition tv sets big business japan us slower take off europe lack high-definition programming. not can people forward wind adverts can also forget abiding network channel schedules putting together a-la-carte entertainment. us networks cable satellite companies worried means terms advertising revenues well brand identity viewer loyalty channels. although us leads technology moment also concern raised europe particularly growing uptake services like sky+. happens today will see nine months years time uk adam hume bbc broadcast s futurologist told bbc news website. likes bbc no issues lost advertising revenue yet. pressing issue moment commercial uk broadcasters brand loyalty important everyone. will talking content brands rather network brands said tim hanlon brand communications firm starcom mediavest. reality broadband connections anybody can producer content. added: challenge now hard promote programme much choice. means said stacey jolna senior vice president tv guide tv group way people find content want watch simplified tv viewers. means networks us terms channels take leaf google s book search engine future instead scheduler help people find want watch. kind channel model might work younger ipod generation used taking control gadgets play them. might not suit everyone panel recognised. older generations comfortable familiar schedules channel brands know getting. perhaps not want much choice put hands mr hanlon suggested. end kids just diapers pushing buttons already - everything possible available said mr hanlon. ultimately consumer will tell market want. 50 000 new gadgets technologies showcased ces many enhancing tv-watching experience. high-definition tv sets everywhere many new models lcd (liquid crystal display) tvs launched dvr capability built instead external boxes. one example launched show humax s 26-inch lcd tv 80-hour tivo dvr dvd recorder. one us s biggest satellite tv companies directtv even launched branded dvr show 100-hours recording capability instant replay search function. set can pause rewind tv 90 hours. microsoft chief bill gates announced pre-show keynote speech partnership tivo called tivotogo means people can play recorded programmes windows pcs mobile devices. reflect increasing trend freeing multimedia people can watch want want.\n"
89 | ]
90 | }
91 | ],
92 | "source": [
93 | "sentences = []\n",
94 | "labels = []\n",
95 | "with open(\"/tmp/bbc-text.csv\", 'r') as csvfile:\n",
96 | " csv_items = csv.reader(csvfile, delimiter=',')\n",
97 | "\n",
98 | " #skip csv header\n",
99 | " next(csv_items)\n",
100 | "\n",
101 | " for row in csv_items:\n",
102 | " labels.append(row[0])\n",
103 | " unfiltered_sentence = row[1].split()\n",
104 | " filtered_sentence = \" \"\n",
105 | " for word in unfiltered_sentence:\n",
106 | " if word not in stopwords:\n",
107 | " # filtered_sentence.append(word)\n",
108 | " filtered_sentence = filtered_sentence + word + \" \"\n",
109 | " sentences.append(filtered_sentence.strip())\n",
110 | "\n",
111 | "print(len(sentences))\n",
112 | "print(sentences[0])\n",
113 | "\n",
114 | "#Expected output\n",
115 | "# 2225\n",
116 | "# tv future hands viewers home theatre systems plasma high-definition tvs digital video recorders moving living room way people watch tv will radically different five years time. according expert panel gathered annual consumer electronics show las vegas discuss new technologies will impact one favourite pastimes. us leading trend programmes content will delivered viewers via home networks cable satellite telecoms companies broadband service providers front rooms portable devices. one talked-about technologies ces digital personal video recorders (dvr pvr). set-top boxes like us s tivo uk s sky+ system allow people record store play pause forward wind tv programmes want. essentially technology allows much personalised tv. also built-in high-definition tv sets big business japan us slower take off europe lack high-definition programming. not can people forward wind adverts can also forget abiding network channel schedules putting together a-la-carte entertainment. us networks cable satellite companies worried means terms advertising revenues well brand identity viewer loyalty channels. although us leads technology moment also concern raised europe particularly growing uptake services like sky+. happens today will see nine months years time uk adam hume bbc broadcast s futurologist told bbc news website. likes bbc no issues lost advertising revenue yet. pressing issue moment commercial uk broadcasters brand loyalty important everyone. will talking content brands rather network brands said tim hanlon brand communications firm starcom mediavest. reality broadband connections anybody can producer content. added: challenge now hard promote programme much choice. means said stacey jolna senior vice president tv guide tv group way people find content want watch simplified tv viewers. means networks us terms channels take leaf google s book search engine future instead scheduler help people find want watch. kind channel model might work younger ipod generation used taking control gadgets play them. might not suit everyone panel recognised. older generations comfortable familiar schedules channel brands know getting. perhaps not want much choice put hands mr hanlon suggested. end kids just diapers pushing buttons already - everything possible available said mr hanlon. ultimately consumer will tell market want. 50 000 new gadgets technologies showcased ces many enhancing tv-watching experience. high-definition tv sets everywhere many new models lcd (liquid crystal display) tvs launched dvr capability built instead external boxes. one example launched show humax s 26-inch lcd tv 80-hour tivo dvr dvd recorder. one us s biggest satellite tv companies directtv even launched branded dvr show 100-hours recording capability instant replay search function. set can pause rewind tv 90 hours. microsoft chief bill gates announced pre-show keynote speech partnership tivo called tivotogo means people can play recorded programmes windows pcs mobile devices. reflect increasing trend freeing multimedia people can watch want want."
117 | ]
118 | },
119 | {
120 | "cell_type": "code",
121 | "execution_count": 10,
122 | "metadata": {
123 | "colab": {
124 | "base_uri": "https://localhost:8080/",
125 | "height": 55
126 | },
127 | "colab_type": "code",
128 | "id": "9LhzBBgSC3S5",
129 | "outputId": "0102c264-a5af-4e30-8f54-1e0c6801ee22"
130 | },
131 | "outputs": [
132 | {
133 | "name": "stdout",
134 | "output_type": "stream",
135 | "text": [
136 | "29714\n"
137 | ]
138 | }
139 | ],
140 | "source": [
141 | "tokenizer = Tokenizer(oov_token=\"\")\n",
142 | "tokenizer.fit_on_texts(sentences)\n",
143 | "word_index = tokenizer.word_index\n",
144 | "print(len(word_index))\n",
145 | "# Expected output\n",
146 | "# 29714"
147 | ]
148 | },
149 | {
150 | "cell_type": "code",
151 | "execution_count": 11,
152 | "metadata": {
153 | "colab": {
154 | "base_uri": "https://localhost:8080/",
155 | "height": 72
156 | },
157 | "colab_type": "code",
158 | "id": "1Gr3dbQfC5VR",
159 | "outputId": "3bea2352-078f-4d62-e861-0e2f487cafd4"
160 | },
161 | "outputs": [
162 | {
163 | "name": "stdout",
164 | "output_type": "stream",
165 | "text": [
166 | "[ 96 176 1157 ... 0 0 0]\n",
167 | "(2225, 2438)\n"
168 | ]
169 | }
170 | ],
171 | "source": [
172 | "sequences = tokenizer.texts_to_sequences(sentences)\n",
173 | "padded = pad_sequences(sequences, padding='post')\n",
174 | "print(padded[0])\n",
175 | "print(padded.shape)\n",
176 | "\n",
177 | "# Expected output\n",
178 | "# [ 96 176 1158 ... 0 0 0]\n",
179 | "# (2225, 2442)"
180 | ]
181 | },
182 | {
183 | "cell_type": "code",
184 | "execution_count": 12,
185 | "metadata": {
186 | "colab": {
187 | "base_uri": "https://localhost:8080/",
188 | "height": 72
189 | },
190 | "colab_type": "code",
191 | "id": "fZufOahzC6yx",
192 | "outputId": "be7eef17-de0d-4af2-9691-4af4e6f02fda"
193 | },
194 | "outputs": [
195 | {
196 | "name": "stdout",
197 | "output_type": "stream",
198 | "text": [
199 | "[[4], [2], [1], [1], [5], [3], [3], [1], [1], [5], [5], [2], [2], [3], [1], [2], [3], [1], [2], [4], [4], [4], [1], [1], [4], [1], [5], [4], [3], [5], [3], [4], [5], [5], [2], [3], [4], [5], [3], [2], [3], [1], [2], [1], [4], [5], [3], [3], [3], [2], [1], [3], [2], [2], [1], [3], [2], [1], [1], [2], [2], [1], [2], [1], [2], [4], [2], [5], [4], [2], [3], [2], [3], [1], [2], [4], [2], [1], [1], [2], [2], [1], [3], [2], [5], [3], [3], [2], [5], [2], [1], [1], [3], [1], [3], [1], [2], [1], [2], [5], [5], [1], [2], [3], [3], [4], [1], [5], [1], [4], [2], [5], [1], [5], [1], [5], [5], [3], [1], [1], [5], [3], [2], [4], [2], [2], [4], [1], [3], [1], [4], [5], [1], [2], [2], [4], [5], [4], [1], [2], [2], [2], [4], [1], [4], [2], [1], [5], [1], [4], [1], [4], [3], [2], [4], [5], [1], [2], [3], [2], [5], [3], [3], [5], [3], [2], [5], [3], [3], [5], [3], [1], [2], [3], [3], [2], [5], [1], [2], [2], [1], [4], [1], [4], [4], [1], [2], [1], [3], [5], [3], [2], [3], [2], [4], [3], [5], [3], [4], [2], [1], [2], [1], [4], [5], [2], [3], [3], [5], [1], [5], [3], [1], [5], [1], [1], [5], [1], [3], [3], [5], [4], [1], [3], [2], [5], [4], [1], [4], [1], [5], [3], [1], [5], [4], [2], [4], [2], [2], [4], [2], [1], [2], [1], [2], [1], [5], [2], [2], [5], [1], [1], [3], [4], [3], [3], [3], [4], [1], [4], [3], [2], [4], [5], [4], [1], [1], [2], [2], [3], [2], [4], [1], [5], [1], [3], [4], [5], [2], [1], [5], [1], [4], [3], [4], [2], [2], [3], [3], [1], [2], [4], [5], [3], [4], [2], [5], [1], [5], [1], [5], [3], [2], [1], [2], [1], [1], [5], [1], [3], [3], [2], [5], [4], [2], [1], [2], [5], [2], [2], [2], [3], [2], [3], [5], [5], [2], [1], [2], [3], [2], [4], [5], [2], [1], [1], [5], [2], [2], [3], [4], [5], [4], [3], [2], [1], [3], [2], [5], [4], [5], [4], [3], [1], [5], [2], [3], [2], [2], [3], [1], [4], [2], [2], [5], [5], [4], [1], [2], [5], [4], [4], [5], [5], [5], [3], [1], [3], [4], [2], [5], [3], [2], [5], [3], [3], [1], [1], [2], [3], [5], [2], [1], [2], [2], [1], [2], [3], [3], [3], [1], [4], [4], [2], [4], [1], [5], [2], [3], [2], [5], [2], [3], [5], [3], [2], [4], [2], [1], [1], [2], [1], [1], [5], [1], [1], [1], [4], [2], [2], [2], [3], [1], [1], [2], [4], [2], [3], [1], [3], [4], [2], [1], [5], [2], [3], [4], [2], [1], [2], [3], [2], [2], [1], [5], [4], [3], [4], [2], [1], [2], [5], [4], [4], [2], [1], [1], [5], [3], [3], [3], [1], [3], [4], [4], [5], [3], [4], [5], [2], [1], [1], [4], [2], [1], [1], [3], [1], [1], [2], [1], [5], [4], [3], [1], [3], [4], [2], [2], [2], [4], [2], [2], [1], [1], [1], [1], [2], [4], [5], [1], [1], [4], [2], [4], [5], [3], [1], [2], [3], [2], [4], [4], [3], [4], [2], [1], [2], [5], [1], [3], [5], [1], [1], [3], [4], [5], [4], [1], [3], [2], [5], [3], [2], [5], [1], [1], [4], [3], [5], [3], [5], [3], [4], [3], [5], [1], [2], [1], [5], [1], [5], [4], [2], [1], [3], [5], [3], [5], [5], [5], [3], [5], [4], [3], [4], [4], [1], [1], [4], [4], [1], [5], [5], [1], [4], [5], [1], [1], [4], [2], [3], [4], [2], [1], [5], [1], [5], [3], [4], [5], [5], [2], [5], [5], [1], [4], [4], [3], [1], [4], [1], [3], [3], [5], [4], [2], [4], [4], [4], [2], [3], [3], [1], [4], [2], [2], [5], [5], [1], [4], [2], [4], [5], [1], [4], [3], [4], [3], [2], [3], [3], [2], [1], [4], [1], [4], [3], [5], [4], [1], [5], [4], [1], [3], [5], [1], [4], [1], [1], [3], [5], [2], [3], [5], [2], [2], [4], [2], [5], [4], [1], [4], [3], [4], [3], [2], [3], [5], [1], [2], [2], [2], [5], [1], [2], [5], [5], [1], [5], [3], [3], [3], [1], [1], [1], [4], [3], [1], [3], [3], [4], [3], [1], [2], [5], [1], [2], [2], [4], [2], [5], [5], [5], [2], [5], [5], [3], [4], [2], [1], [4], [1], [1], [3], [2], [1], [4], [2], [1], [4], [1], [1], [5], [1], [2], [1], [2], [4], [3], [4], [2], [1], [1], [2], [2], [2], [2], [3], [1], [2], [4], [2], [1], [3], [2], [4], [2], [1], [2], [3], [5], [1], [2], [3], [2], [5], [2], [2], [2], [1], [3], [5], [1], [3], [1], [3], [3], [2], [2], [1], [4], [5], [1], [5], [2], [2], [2], [4], [1], [4], [3], [4], [4], [4], [1], [4], [4], [5], [5], [4], [1], [5], [4], [1], [1], [2], [5], [4], [2], [1], [2], [3], [2], [5], [4], [2], [3], [2], [4], [1], [2], [5], [2], [3], [1], [5], [3], [1], [2], [1], [3], [3], [1], [5], [5], [2], [2], [1], [4], [4], [1], [5], [4], [4], [2], [1], [5], [4], [1], [1], [2], [5], [2], [2], [2], [5], [1], [5], [4], [4], [4], [3], [4], [4], [5], [5], [1], [1], [3], [2], [5], [1], [3], [5], [4], [3], [4], [4], [2], [5], [3], [4], [3], [3], [1], [3], [3], [5], [4], [1], [3], [1], [5], [3], [2], [2], [3], [1], [1], [1], [5], [4], [4], [2], [5], [1], [3], [4], [3], [5], [4], [4], [2], [2], [1], [2], [2], [4], [3], [5], [2], [2], [2], [2], [2], [4], [1], [3], [4], [4], [2], [2], [5], [3], [5], [1], [4], [1], [5], [1], [4], [1], [2], [1], [3], [3], [5], [2], [1], [3], [3], [1], [5], [3], [2], [4], [1], [2], [2], [2], [5], [5], [4], [4], [2], [2], [5], [1], [2], [5], [4], [4], [2], [2], [1], [1], [1], [3], [3], [1], [3], [1], [2], [5], [1], [4], [5], [1], [1], [2], [2], [4], [4], [1], [5], [1], [5], [1], [5], [3], [5], [5], [4], [5], [2], [2], [3], [1], [3], [4], [2], [3], [1], [3], [1], [5], [1], [3], [1], [1], [4], [5], [1], [3], [1], [1], [2], [4], [5], [3], [4], [5], [3], [5], [3], [5], [5], [4], [5], [3], [5], [5], [4], [4], [1], [1], [5], [5], [4], [5], [3], [4], [5], [2], [4], [1], [2], [5], [5], [4], [5], [4], [2], [5], [1], [5], [2], [1], [2], [1], [3], [4], [5], [3], [2], [5], [5], [3], [2], [5], [1], [3], [1], [2], [2], [2], [2], [2], [5], [4], [1], [5], [5], [2], [1], [4], [4], [5], [1], [2], [3], [2], [3], [2], [2], [5], [3], [2], [2], [4], [3], [1], [4], [5], [3], [2], [2], [1], [5], [3], [4], [2], [2], [3], [2], [1], [5], [1], [5], [4], [3], [2], [2], [4], [2], [2], [1], [2], [4], [5], [3], [2], [3], [2], [1], [4], [2], [3], [5], [4], [2], [5], [1], [3], [3], [1], [3], [2], [4], [5], [1], [1], [4], [2], [1], [5], [4], [1], [3], [1], [2], [2], [2], [3], [5], [1], [3], [4], [2], [2], [4], [5], [5], [4], [4], [1], [1], [5], [4], [5], [1], [3], [4], [2], [1], [5], [2], [2], [5], [1], [2], [1], [4], [3], [3], [4], [5], [3], [5], [2], [2], [3], [1], [4], [1], [1], [1], [3], [2], [1], [2], [4], [1], [2], [2], [1], [3], [4], [1], [2], [4], [1], [1], [2], [2], [2], [2], [3], [5], [4], [2], [2], [1], [2], [5], [2], [5], [1], [3], [2], [2], [4], [5], [2], [2], [2], [3], [2], [3], [4], [5], [3], [5], [1], [4], [3], [2], [4], [1], [2], [2], [5], [4], [2], [2], [1], [1], [5], [1], [3], [1], [2], [1], [2], [3], [3], [2], [3], [4], [5], [1], [2], [5], [1], [3], [3], [4], [5], [2], [3], [3], [1], [4], [2], [1], [5], [1], [5], [1], [2], [1], [3], [5], [4], [2], [1], [3], [4], [1], [5], [2], [1], [5], [1], [4], [1], [4], [3], [1], [2], [5], [4], [4], [3], [4], [5], [4], [1], [2], [4], [2], [5], [1], [4], [3], [3], [3], [3], [5], [5], [5], [2], [3], [3], [1], [1], [4], [1], [3], [2], [2], [4], [1], [4], [2], [4], [3], [3], [1], [2], [3], [1], [2], [4], [2], [2], [5], [5], [1], [2], [4], [4], [3], [2], [3], [1], [5], [5], [3], [3], [2], [2], [4], [4], [1], [1], [3], [4], [1], [4], [2], [1], [2], [3], [1], [5], [2], [4], [3], [5], [4], [2], [1], [5], [4], [4], [5], [3], [4], [5], [1], [5], [1], [1], [1], [3], [4], [1], [2], [1], [1], [2], [4], [1], [2], [5], [3], [4], [1], [3], [4], [5], [3], [1], [3], [4], [2], [5], [1], [3], [2], [4], [4], [4], [3], [2], [1], [3], [5], [4], [5], [1], [4], [2], [3], [5], [4], [3], [1], [1], [2], [5], [2], [2], [3], [2], [2], [3], [4], [5], [3], [5], [5], [2], [3], [1], [3], [5], [1], [5], [3], [5], [5], [5], [2], [1], [3], [1], [5], [4], [4], [2], [3], [5], [2], [1], [2], [3], [3], [2], [1], [4], [4], [4], [2], [3], [3], [2], [1], [1], [5], [2], [1], [1], [3], [3], [3], [5], [3], [2], [4], [2], [3], [5], [5], [2], [1], [3], [5], [1], [5], [3], [3], [2], [3], [1], [5], [5], [4], [4], [4], [4], [3], [4], [2], [4], [1], [1], [5], [2], [4], [5], [2], [4], [1], [4], [5], [5], [3], [3], [1], [2], [2], [4], [5], [1], [3], [2], [4], [5], [3], [1], [5], [3], [3], [4], [1], [3], [2], [3], [5], [4], [1], [3], [5], [5], [2], [1], [4], [4], [1], [5], [4], [3], [4], [1], [3], [3], [1], [5], [1], [3], [1], [4], [5], [1], [5], [2], [2], [5], [5], [5], [4], [1], [2], [2], [3], [3], [2], [3], [5], [1], [1], [4], [3], [1], [2], [1], [2], [4], [1], [1], [2], [5], [1], [1], [4], [1], [2], [3], [2], [5], [4], [5], [3], [2], [5], [3], [5], [3], [3], [2], [1], [1], [1], [4], [4], [1], [3], [5], [4], [1], [5], [2], [5], [3], [2], [1], [4], [2], [1], [3], [2], [5], [5], [5], [3], [5], [3], [5], [1], [5], [1], [3], [3], [2], [3], [4], [1], [4], [1], [2], [3], [4], [5], [5], [3], [5], [3], [1], [1], [3], [2], [4], [1], [3], [3], [5], [1], [3], [3], [2], [4], [4], [2], [4], [1], [1], [2], [3], [2], [4], [1], [4], [3], [5], [1], [2], [1], [5], [4], [4], [1], [3], [1], [2], [1], [2], [1], [1], [5], [5], [2], [4], [4], [2], [4], [2], [2], [1], [1], [3], [1], [4], [1], [4], [1], [1], [2], [2], [4], [1], [2], [4], [4], [3], [1], [2], [5], [5], [4], [3], [1], [1], [4], [2], [4], [5], [5], [3], [3], [2], [5], [1], [5], [5], [2], [1], [3], [4], [2], [1], [5], [4], [3], [3], [1], [1], [2], [2], [2], [2], [2], [5], [2], [3], [3], [4], [4], [5], [3], [5], [2], [3], [1], [1], [2], [4], [2], [4], [1], [2], [2], [3], [1], [1], [3], [3], [5], [5], [3], [2], [3], [3], [2], [4], [3], [3], [3], [3], [3], [5], [5], [4], [3], [1], [3], [1], [4], [1], [1], [1], [5], [4], [5], [4], [1], [4], [1], [1], [5], [5], [2], [5], [5], [3], [2], [1], [4], [4], [3], [2], [1], [2], [5], [1], [3], [5], [1], [1], [2], [3], [4], [4], [2], [2], [1], [3], [5], [1], [1], [3], [5], [4], [1], [5], [2], [3], [1], [3], [4], [5], [1], [3], [2], [5], [3], [5], [3], [1], [3], [2], [2], [3], [2], [4], [1], [2], [5], [2], [1], [1], [5], [4], [3], [4], [3], [3], [1], [1], [1], [2], [4], [5], [2], [1], [2], [1], [2], [4], [2], [2], [2], [2], [1], [1], [1], [2], [2], [5], [2], [2], [2], [1], [1], [1], [4], [2], [1], [1], [1], [2], [5], [4], [4], [4], [3], [2], [2], [4], [2], [4], [1], [1], [3], [3], [3], [1], [1], [3], [3], [4], [2], [1], [1], [1], [1], [2], [1], [2], [2], [2], [2], [1], [3], [1], [4], [4], [1], [4], [2], [5], [2], [1], [2], [4], [4], [3], [5], [2], [5], [2], [4], [3], [5], [3], [5], [5], [4], [2], [4], [4], [2], [3], [1], [5], [2], [3], [5], [2], [4], [1], [4], [3], [1], [3], [2], [3], [3], [2], [2], [2], [4], [3], [2], [3], [2], [5], [3], [1], [3], [3], [1], [5], [4], [4], [2], [4], [1], [2], [2], [3], [1], [4], [4], [4], [1], [5], [1], [3], [2], [3], [3], [5], [4], [2], [4], [1], [5], [5], [1], [2], [5], [4], [4], [1], [5], [2], [3], [3], [3], [4], [4], [2], [3], [2], [3], [3], [5], [1], [4], [2], [4], [5], [4], [4], [1], [3], [1], [1], [3], [5], [5], [2], [3], [3], [1], [2], [2], [4], [2], [4], [4], [1], [2], [3], [1], [2], [2], [1], [4], [1], [4], [5], [1], [1], [5], [2], [4], [1], [1], [3], [4], [2], [3], [1], [1], [3], [5], [4], [4], [4], [2], [1], [5], [5], [4], [2], [3], [4], [1], [1], [4], [4], [3], [2], [1], [5], [5], [1], [5], [4], [4], [2], [2], [2], [1], [1], [4], [1], [2], [4], [2], [2], [1], [2], [3], [2], [2], [4], [2], [4], [3], [4], [5], [3], [4], [5], [1], [3], [5], [2], [4], [2], [4], [5], [4], [1], [2], [2], [3], [5], [3], [1]]\n",
200 | "{'sport': 1, 'business': 2, 'politics': 3, 'tech': 4, 'entertainment': 5}\n"
201 | ]
202 | }
203 | ],
204 | "source": [
205 | "label_tokenizer = Tokenizer()\n",
206 | "label_tokenizer.fit_on_texts(labels)\n",
207 | "label_word_index = label_tokenizer.word_index\n",
208 | "label_seq = label_tokenizer.texts_to_sequences(labels)\n",
209 | "print(label_seq)\n",
210 | "print(label_word_index)\n",
211 | "\n",
212 | "# Expected Output\n",
213 | "# [[4], [2], [1], [1], [5], [3], [3], [1], [1], [5], [5], [2], [2], [3], [1], [2], [3], [1], [2], [4], [4], [4], [1], [1], [4], [1], [5], [4], [3], [5], [3], [4], [5], [5], [2], [3], [4], [5], [3], [2], [3], [1], [2], [1], [4], [5], [3], [3], [3], [2], [1], [3], [2], [2], [1], [3], [2], [1], [1], [2], [2], [1], [2], [1], [2], [4], [2], [5], [4], [2], [3], [2], [3], [1], [2], [4], [2], [1], [1], [2], [2], [1], [3], [2], [5], [3], [3], [2], [5], [2], [1], [1], [3], [1], [3], [1], [2], [1], [2], [5], [5], [1], [2], [3], [3], [4], [1], [5], [1], [4], [2], [5], [1], [5], [1], [5], [5], [3], [1], [1], [5], [3], [2], [4], [2], [2], [4], [1], [3], [1], [4], [5], [1], [2], [2], [4], [5], [4], [1], [2], [2], [2], [4], [1], [4], [2], [1], [5], [1], [4], [1], [4], [3], [2], [4], [5], [1], [2], [3], [2], [5], [3], [3], [5], [3], [2], [5], [3], [3], [5], [3], [1], [2], [3], [3], [2], [5], [1], [2], [2], [1], [4], [1], [4], [4], [1], [2], [1], [3], [5], [3], [2], [3], [2], [4], [3], [5], [3], [4], [2], [1], [2], [1], [4], [5], [2], [3], [3], [5], [1], [5], [3], [1], [5], [1], [1], [5], [1], [3], [3], [5], [4], [1], [3], [2], [5], [4], [1], [4], [1], [5], [3], [1], [5], [4], [2], [4], [2], [2], [4], [2], [1], [2], [1], [2], [1], [5], [2], [2], [5], [1], [1], [3], [4], [3], [3], [3], [4], [1], [4], [3], [2], [4], [5], [4], [1], [1], [2], [2], [3], [2], [4], [1], [5], [1], [3], [4], [5], [2], [1], [5], [1], [4], [3], [4], [2], [2], [3], [3], [1], [2], [4], [5], [3], [4], [2], [5], [1], [5], [1], [5], [3], [2], [1], [2], [1], [1], [5], [1], [3], [3], [2], [5], [4], [2], [1], [2], [5], [2], [2], [2], [3], [2], [3], [5], [5], [2], [1], [2], [3], [2], [4], [5], [2], [1], [1], [5], [2], [2], [3], [4], [5], [4], [3], [2], [1], [3], [2], [5], [4], [5], [4], [3], [1], [5], [2], [3], [2], [2], [3], [1], [4], [2], [2], [5], [5], [4], [1], [2], [5], [4], [4], [5], [5], [5], [3], [1], [3], [4], [2], [5], [3], [2], [5], [3], [3], [1], [1], [2], [3], [5], [2], [1], [2], [2], [1], [2], [3], [3], [3], [1], [4], [4], [2], [4], [1], [5], [2], [3], [2], [5], [2], [3], [5], [3], [2], [4], [2], [1], [1], [2], [1], [1], [5], [1], [1], [1], [4], [2], [2], [2], [3], [1], [1], [2], [4], [2], [3], [1], [3], [4], [2], [1], [5], [2], [3], [4], [2], [1], [2], [3], [2], [2], [1], [5], [4], [3], [4], [2], [1], [2], [5], [4], [4], [2], [1], [1], [5], [3], [3], [3], [1], [3], [4], [4], [5], [3], [4], [5], [2], [1], [1], [4], [2], [1], [1], [3], [1], [1], [2], [1], [5], [4], [3], [1], [3], [4], [2], [2], [2], [4], [2], [2], [1], [1], [1], [1], [2], [4], [5], [1], [1], [4], [2], [4], [5], [3], [1], [2], [3], [2], [4], [4], [3], [4], [2], [1], [2], [5], [1], [3], [5], [1], [1], [3], [4], [5], [4], [1], [3], [2], [5], [3], [2], [5], [1], [1], [4], [3], [5], [3], [5], [3], [4], [3], [5], [1], [2], [1], [5], [1], [5], [4], [2], [1], [3], [5], [3], [5], [5], [5], [3], [5], [4], [3], [4], [4], [1], [1], [4], [4], [1], [5], [5], [1], [4], [5], [1], [1], [4], [2], [3], [4], [2], [1], [5], [1], [5], [3], [4], [5], [5], [2], [5], [5], [1], [4], [4], [3], [1], [4], [1], [3], [3], [5], [4], [2], [4], [4], [4], [2], [3], [3], [1], [4], [2], [2], [5], [5], [1], [4], [2], [4], [5], [1], [4], [3], [4], [3], [2], [3], [3], [2], [1], [4], [1], [4], [3], [5], [4], [1], [5], [4], [1], [3], [5], [1], [4], [1], [1], [3], [5], [2], [3], [5], [2], [2], [4], [2], [5], [4], [1], [4], [3], [4], [3], [2], [3], [5], [1], [2], [2], [2], [5], [1], [2], [5], [5], [1], [5], [3], [3], [3], [1], [1], [1], [4], [3], [1], [3], [3], [4], [3], [1], [2], [5], [1], [2], [2], [4], [2], [5], [5], [5], [2], [5], [5], [3], [4], [2], [1], [4], [1], [1], [3], [2], [1], [4], [2], [1], [4], [1], [1], [5], [1], [2], [1], [2], [4], [3], [4], [2], [1], [1], [2], [2], [2], [2], [3], [1], [2], [4], [2], [1], [3], [2], [4], [2], [1], [2], [3], [5], [1], [2], [3], [2], [5], [2], [2], [2], [1], [3], [5], [1], [3], [1], [3], [3], [2], [2], [1], [4], [5], [1], [5], [2], [2], [2], [4], [1], [4], [3], [4], [4], [4], [1], [4], [4], [5], [5], [4], [1], [5], [4], [1], [1], [2], [5], [4], [2], [1], [2], [3], [2], [5], [4], [2], [3], [2], [4], [1], [2], [5], [2], [3], [1], [5], [3], [1], [2], [1], [3], [3], [1], [5], [5], [2], [2], [1], [4], [4], [1], [5], [4], [4], [2], [1], [5], [4], [1], [1], [2], [5], [2], [2], [2], [5], [1], [5], [4], [4], [4], [3], [4], [4], [5], [5], [1], [1], [3], [2], [5], [1], [3], [5], [4], [3], [4], [4], [2], [5], [3], [4], [3], [3], [1], [3], [3], [5], [4], [1], [3], [1], [5], [3], [2], [2], [3], [1], [1], [1], [5], [4], [4], [2], [5], [1], [3], [4], [3], [5], [4], [4], [2], [2], [1], [2], [2], [4], [3], [5], [2], [2], [2], [2], [2], [4], [1], [3], [4], [4], [2], [2], [5], [3], [5], [1], [4], [1], [5], [1], [4], [1], [2], [1], [3], [3], [5], [2], [1], [3], [3], [1], [5], [3], [2], [4], [1], [2], [2], [2], [5], [5], [4], [4], [2], [2], [5], [1], [2], [5], [4], [4], [2], [2], [1], [1], [1], [3], [3], [1], [3], [1], [2], [5], [1], [4], [5], [1], [1], [2], [2], [4], [4], [1], [5], [1], [5], [1], [5], [3], [5], [5], [4], [5], [2], [2], [3], [1], [3], [4], [2], [3], [1], [3], [1], [5], [1], [3], [1], [1], [4], [5], [1], [3], [1], [1], [2], [4], [5], [3], [4], [5], [3], [5], [3], [5], [5], [4], [5], [3], [5], [5], [4], [4], [1], [1], [5], [5], [4], [5], [3], [4], [5], [2], [4], [1], [2], [5], [5], [4], [5], [4], [2], [5], [1], [5], [2], [1], [2], [1], [3], [4], [5], [3], [2], [5], [5], [3], [2], [5], [1], [3], [1], [2], [2], [2], [2], [2], [5], [4], [1], [5], [5], [2], [1], [4], [4], [5], [1], [2], [3], [2], [3], [2], [2], [5], [3], [2], [2], [4], [3], [1], [4], [5], [3], [2], [2], [1], [5], [3], [4], [2], [2], [3], [2], [1], [5], [1], [5], [4], [3], [2], [2], [4], [2], [2], [1], [2], [4], [5], [3], [2], [3], [2], [1], [4], [2], [3], [5], [4], [2], [5], [1], [3], [3], [1], [3], [2], [4], [5], [1], [1], [4], [2], [1], [5], [4], [1], [3], [1], [2], [2], [2], [3], [5], [1], [3], [4], [2], [2], [4], [5], [5], [4], [4], [1], [1], [5], [4], [5], [1], [3], [4], [2], [1], [5], [2], [2], [5], [1], [2], [1], [4], [3], [3], [4], [5], [3], [5], [2], [2], [3], [1], [4], [1], [1], [1], [3], [2], [1], [2], [4], [1], [2], [2], [1], [3], [4], [1], [2], [4], [1], [1], [2], [2], [2], [2], [3], [5], [4], [2], [2], [1], [2], [5], [2], [5], [1], [3], [2], [2], [4], [5], [2], [2], [2], [3], [2], [3], [4], [5], [3], [5], [1], [4], [3], [2], [4], [1], [2], [2], [5], [4], [2], [2], [1], [1], [5], [1], [3], [1], [2], [1], [2], [3], [3], [2], [3], [4], [5], [1], [2], [5], [1], [3], [3], [4], [5], [2], [3], [3], [1], [4], [2], [1], [5], [1], [5], [1], [2], [1], [3], [5], [4], [2], [1], [3], [4], [1], [5], [2], [1], [5], [1], [4], [1], [4], [3], [1], [2], [5], [4], [4], [3], [4], [5], [4], [1], [2], [4], [2], [5], [1], [4], [3], [3], [3], [3], [5], [5], [5], [2], [3], [3], [1], [1], [4], [1], [3], [2], [2], [4], [1], [4], [2], [4], [3], [3], [1], [2], [3], [1], [2], [4], [2], [2], [5], [5], [1], [2], [4], [4], [3], [2], [3], [1], [5], [5], [3], [3], [2], [2], [4], [4], [1], [1], [3], [4], [1], [4], [2], [1], [2], [3], [1], [5], [2], [4], [3], [5], [4], [2], [1], [5], [4], [4], [5], [3], [4], [5], [1], [5], [1], [1], [1], [3], [4], [1], [2], [1], [1], [2], [4], [1], [2], [5], [3], [4], [1], [3], [4], [5], [3], [1], [3], [4], [2], [5], [1], [3], [2], [4], [4], [4], [3], [2], [1], [3], [5], [4], [5], [1], [4], [2], [3], [5], [4], [3], [1], [1], [2], [5], [2], [2], [3], [2], [2], [3], [4], [5], [3], [5], [5], [2], [3], [1], [3], [5], [1], [5], [3], [5], [5], [5], [2], [1], [3], [1], [5], [4], [4], [2], [3], [5], [2], [1], [2], [3], [3], [2], [1], [4], [4], [4], [2], [3], [3], [2], [1], [1], [5], [2], [1], [1], [3], [3], [3], [5], [3], [2], [4], [2], [3], [5], [5], [2], [1], [3], [5], [1], [5], [3], [3], [2], [3], [1], [5], [5], [4], [4], [4], [4], [3], [4], [2], [4], [1], [1], [5], [2], [4], [5], [2], [4], [1], [4], [5], [5], [3], [3], [1], [2], [2], [4], [5], [1], [3], [2], [4], [5], [3], [1], [5], [3], [3], [4], [1], [3], [2], [3], [5], [4], [1], [3], [5], [5], [2], [1], [4], [4], [1], [5], [4], [3], [4], [1], [3], [3], [1], [5], [1], [3], [1], [4], [5], [1], [5], [2], [2], [5], [5], [5], [4], [1], [2], [2], [3], [3], [2], [3], [5], [1], [1], [4], [3], [1], [2], [1], [2], [4], [1], [1], [2], [5], [1], [1], [4], [1], [2], [3], [2], [5], [4], [5], [3], [2], [5], [3], [5], [3], [3], [2], [1], [1], [1], [4], [4], [1], [3], [5], [4], [1], [5], [2], [5], [3], [2], [1], [4], [2], [1], [3], [2], [5], [5], [5], [3], [5], [3], [5], [1], [5], [1], [3], [3], [2], [3], [4], [1], [4], [1], [2], [3], [4], [5], [5], [3], [5], [3], [1], [1], [3], [2], [4], [1], [3], [3], [5], [1], [3], [3], [2], [4], [4], [2], [4], [1], [1], [2], [3], [2], [4], [1], [4], [3], [5], [1], [2], [1], [5], [4], [4], [1], [3], [1], [2], [1], [2], [1], [1], [5], [5], [2], [4], [4], [2], [4], [2], [2], [1], [1], [3], [1], [4], [1], [4], [1], [1], [2], [2], [4], [1], [2], [4], [4], [3], [1], [2], [5], [5], [4], [3], [1], [1], [4], [2], [4], [5], [5], [3], [3], [2], [5], [1], [5], [5], [2], [1], [3], [4], [2], [1], [5], [4], [3], [3], [1], [1], [2], [2], [2], [2], [2], [5], [2], [3], [3], [4], [4], [5], [3], [5], [2], [3], [1], [1], [2], [4], [2], [4], [1], [2], [2], [3], [1], [1], [3], [3], [5], [5], [3], [2], [3], [3], [2], [4], [3], [3], [3], [3], [3], [5], [5], [4], [3], [1], [3], [1], [4], [1], [1], [1], [5], [4], [5], [4], [1], [4], [1], [1], [5], [5], [2], [5], [5], [3], [2], [1], [4], [4], [3], [2], [1], [2], [5], [1], [3], [5], [1], [1], [2], [3], [4], [4], [2], [2], [1], [3], [5], [1], [1], [3], [5], [4], [1], [5], [2], [3], [1], [3], [4], [5], [1], [3], [2], [5], [3], [5], [3], [1], [3], [2], [2], [3], [2], [4], [1], [2], [5], [2], [1], [1], [5], [4], [3], [4], [3], [3], [1], [1], [1], [2], [4], [5], [2], [1], [2], [1], [2], [4], [2], [2], [2], [2], [1], [1], [1], [2], [2], [5], [2], [2], [2], [1], [1], [1], [4], [2], [1], [1], [1], [2], [5], [4], [4], [4], [3], [2], [2], [4], [2], [4], [1], [1], [3], [3], [3], [1], [1], [3], [3], [4], [2], [1], [1], [1], [1], [2], [1], [2], [2], [2], [2], [1], [3], [1], [4], [4], [1], [4], [2], [5], [2], [1], [2], [4], [4], [3], [5], [2], [5], [2], [4], [3], [5], [3], [5], [5], [4], [2], [4], [4], [2], [3], [1], [5], [2], [3], [5], [2], [4], [1], [4], [3], [1], [3], [2], [3], [3], [2], [2], [2], [4], [3], [2], [3], [2], [5], [3], [1], [3], [3], [1], [5], [4], [4], [2], [4], [1], [2], [2], [3], [1], [4], [4], [4], [1], [5], [1], [3], [2], [3], [3], [5], [4], [2], [4], [1], [5], [5], [1], [2], [5], [4], [4], [1], [5], [2], [3], [3], [3], [4], [4], [2], [3], [2], [3], [3], [5], [1], [4], [2], [4], [5], [4], [4], [1], [3], [1], [1], [3], [5], [5], [2], [3], [3], [1], [2], [2], [4], [2], [4], [4], [1], [2], [3], [1], [2], [2], [1], [4], [1], [4], [5], [1], [1], [5], [2], [4], [1], [1], [3], [4], [2], [3], [1], [1], [3], [5], [4], [4], [4], [2], [1], [5], [5], [4], [2], [3], [4], [1], [1], [4], [4], [3], [2], [1], [5], [5], [1], [5], [4], [4], [2], [2], [2], [1], [1], [4], [1], [2], [4], [2], [2], [1], [2], [3], [2], [2], [4], [2], [4], [3], [4], [5], [3], [4], [5], [1], [3], [5], [2], [4], [2], [4], [5], [4], [1], [2], [2], [3], [5], [3], [1]]\n",
214 | "# {'sport': 1, 'business': 2, 'politics': 3, 'tech': 4, 'entertainment': 5}"
215 | ]
216 | },
217 | {
218 | "cell_type": "code",
219 | "execution_count": 0,
220 | "metadata": {
221 | "colab": {},
222 | "colab_type": "code",
223 | "id": "E7WuGkVJWjdk"
224 | },
225 | "outputs": [],
226 | "source": []
227 | }
228 | ],
229 | "metadata": {
230 | "colab": {
231 | "machine_shape": "hm",
232 | "name": "Exercise-question.ipynb",
233 | "provenance": []
234 | },
235 | "kernelspec": {
236 | "display_name": "Python 3",
237 | "language": "python",
238 | "name": "python3"
239 | },
240 | "language_info": {
241 | "codemirror_mode": {
242 | "name": "ipython",
243 | "version": 3
244 | },
245 | "file_extension": ".py",
246 | "mimetype": "text/x-python",
247 | "name": "python",
248 | "nbconvert_exporter": "python",
249 | "pygments_lexer": "ipython3",
250 | "version": "3.7.3"
251 | }
252 | },
253 | "nbformat": 4,
254 | "nbformat_minor": 1
255 | }
256 |
--------------------------------------------------------------------------------
/Course 3 - NLP in Tensorflow/Week 1 Quiz | Coursera.webarchive:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chrismartinis/tensorflow_developer_professional_certificate/e81bdc75b3b3cbd46911ca816445fa07061dcb7a/Course 3 - NLP in Tensorflow/Week 1 Quiz | Coursera.webarchive
--------------------------------------------------------------------------------
/Course 3 - NLP in Tensorflow/Week 2 Quiz | Coursera.webarchive:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chrismartinis/tensorflow_developer_professional_certificate/e81bdc75b3b3cbd46911ca816445fa07061dcb7a/Course 3 - NLP in Tensorflow/Week 2 Quiz | Coursera.webarchive
--------------------------------------------------------------------------------
/Course 3 - NLP in Tensorflow/Week 3 Quiz | Coursera.webarchive:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chrismartinis/tensorflow_developer_professional_certificate/e81bdc75b3b3cbd46911ca816445fa07061dcb7a/Course 3 - NLP in Tensorflow/Week 3 Quiz | Coursera.webarchive
--------------------------------------------------------------------------------
/Course 3 - NLP in Tensorflow/Week 4 Quiz | Coursera.webarchive:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chrismartinis/tensorflow_developer_professional_certificate/e81bdc75b3b3cbd46911ca816445fa07061dcb7a/Course 3 - NLP in Tensorflow/Week 4 Quiz | Coursera.webarchive
--------------------------------------------------------------------------------
/Course 3 - NLP in Tensorflow/Week1_Exercise_BBC_Explore.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "metadata": {
7 | "colab": {
8 | "base_uri": "https://localhost:8080/",
9 | "height": 296
10 | },
11 | "colab_type": "code",
12 | "id": "zrZevCPJ92HG",
13 | "outputId": "efa1ee31-aac6-4f35-ef65-86a9095ebe4c"
14 | },
15 | "outputs": [
16 | {
17 | "name": "stdout",
18 | "output_type": "stream",
19 | "text": [
20 | "--2020-02-25 17:00:10-- https://storage.googleapis.com/laurencemoroney-blog.appspot.com/bbc-text.csv\n",
21 | "Resolving storage.googleapis.com (storage.googleapis.com)... 172.217.203.128, 2607:f8b0:400c:c13::80\n",
22 | "Connecting to storage.googleapis.com (storage.googleapis.com)|172.217.203.128|:443... connected.\n",
23 | "HTTP request sent, awaiting response... 200 OK\n",
24 | "Length: 5057493 (4.8M) [application/octet-stream]\n",
25 | "Saving to: ‘/tmp/bbc-text.csv’\n",
26 | "\n",
27 | "\r",
28 | "/tmp/bbc-text.csv 0%[ ] 0 --.-KB/s \r",
29 | "/tmp/bbc-text.csv 100%[===================>] 4.82M --.-KB/s in 0.03s \n",
30 | "\n",
31 | "2020-02-25 17:00:10 (145 MB/s) - ‘/tmp/bbc-text.csv’ saved [5057493/5057493]\n",
32 | "\n"
33 | ]
34 | },
35 | {
36 | "data": {
37 | "text/html": [
38 | "\n",
39 | "The default version of TensorFlow in Colab will soon switch to TensorFlow 2.x.
\n",
40 | "We recommend you upgrade now \n",
41 | "or ensure your notebook will continue to use TensorFlow 1.x via the %tensorflow_version 1.x
magic:\n",
42 | "more info.
\n"
43 | ],
44 | "text/plain": [
45 | ""
46 | ]
47 | },
48 | "metadata": {
49 | "tags": []
50 | },
51 | "output_type": "display_data"
52 | }
53 | ],
54 | "source": [
55 | "!wget --no-check-certificate \\\n",
56 | " https://storage.googleapis.com/laurencemoroney-blog.appspot.com/bbc-text.csv \\\n",
57 | " -O /tmp/bbc-text.csv\n",
58 | "\n",
59 | " \n",
60 | "import csv\n",
61 | "from tensorflow.keras.preprocessing.text import Tokenizer\n",
62 | "from tensorflow.keras.preprocessing.sequence import pad_sequences\n",
63 | "\n",
64 | "\n",
65 | "#Stopwords list from https://github.com/Yoast/YoastSEO.js/blob/develop/src/config/stopwords.js\n",
66 | "# Convert it to a Python list and paste it here\n",
67 | "stopwords = [ \"a\", \"about\", \"above\", \"after\", \"again\", \"against\", \"all\", \"am\", \"an\", \"and\", \"any\", \"are\", \"as\", \"at\", \"be\", \"because\", \"been\", \"before\", \"being\", \"below\", \"between\", \"both\", \"but\", \"by\", \"could\", \"did\", \"do\", \"does\", \"doing\", \"down\", \"during\", \"each\", \"few\", \"for\", \"from\", \"further\", \"had\", \"has\", \"have\", \"having\", \"he\", \"he'd\", \"he'll\", \"he's\", \"her\", \"here\", \"here's\", \"hers\", \"herself\", \"him\", \"himself\", \"his\", \"how\", \"how's\", \"i\", \"i'd\", \"i'll\", \"i'm\", \"i've\", \"if\", \"in\", \"into\", \"is\", \"it\", \"it's\", \"its\", \"itself\", \"let's\", \"me\", \"more\", \"most\", \"my\", \"myself\", \"nor\", \"of\", \"on\", \"once\", \"only\", \"or\", \"other\", \"ought\", \"our\", \"ours\", \"ourselves\", \"out\", \"over\", \"own\", \"same\", \"she\", \"she'd\", \"she'll\", \"she's\", \"should\", \"so\", \"some\", \"such\", \"than\", \"that\", \"that's\", \"the\", \"their\", \"theirs\", \"them\", \"themselves\", \"then\", \"there\", \"there's\", \"these\", \"they\", \"they'd\", \"they'll\", \"they're\", \"they've\", \"this\", \"those\", \"through\", \"to\", \"too\", \"under\", \"until\", \"up\", \"very\", \"was\", \"we\", \"we'd\", \"we'll\", \"we're\", \"we've\", \"were\", \"what\", \"what's\", \"when\", \"when's\", \"where\", \"where's\", \"which\", \"while\", \"who\", \"who's\", \"whom\", \"why\", \"why's\", \"with\", \"would\", \"you\", \"you'd\", \"you'll\", \"you're\", \"you've\", \"your\", \"yours\", \"yourself\", \"yourselves\" ]\n"
68 | ]
69 | },
70 | {
71 | "cell_type": "code",
72 | "execution_count": 9,
73 | "metadata": {
74 | "colab": {
75 | "base_uri": "https://localhost:8080/",
76 | "height": 72
77 | },
78 | "colab_type": "code",
79 | "id": "1rmYBjsyCv3K",
80 | "outputId": "03a933d5-d142-453e-8d85-c7c370952c00"
81 | },
82 | "outputs": [
83 | {
84 | "name": "stdout",
85 | "output_type": "stream",
86 | "text": [
87 | "2225\n",
88 | "tv future hands viewers home theatre systems plasma high-definition tvs digital video recorders moving living room way people watch tv will radically different five years time. according expert panel gathered annual consumer electronics show las vegas discuss new technologies will impact one favourite pastimes. us leading trend programmes content will delivered viewers via home networks cable satellite telecoms companies broadband service providers front rooms portable devices. one talked-about technologies ces digital personal video recorders (dvr pvr). set-top boxes like us s tivo uk s sky+ system allow people record store play pause forward wind tv programmes want. essentially technology allows much personalised tv. also built-in high-definition tv sets big business japan us slower take off europe lack high-definition programming. not can people forward wind adverts can also forget abiding network channel schedules putting together a-la-carte entertainment. us networks cable satellite companies worried means terms advertising revenues well brand identity viewer loyalty channels. although us leads technology moment also concern raised europe particularly growing uptake services like sky+. happens today will see nine months years time uk adam hume bbc broadcast s futurologist told bbc news website. likes bbc no issues lost advertising revenue yet. pressing issue moment commercial uk broadcasters brand loyalty important everyone. will talking content brands rather network brands said tim hanlon brand communications firm starcom mediavest. reality broadband connections anybody can producer content. added: challenge now hard promote programme much choice. means said stacey jolna senior vice president tv guide tv group way people find content want watch simplified tv viewers. means networks us terms channels take leaf google s book search engine future instead scheduler help people find want watch. kind channel model might work younger ipod generation used taking control gadgets play them. might not suit everyone panel recognised. older generations comfortable familiar schedules channel brands know getting. perhaps not want much choice put hands mr hanlon suggested. end kids just diapers pushing buttons already - everything possible available said mr hanlon. ultimately consumer will tell market want. 50 000 new gadgets technologies showcased ces many enhancing tv-watching experience. high-definition tv sets everywhere many new models lcd (liquid crystal display) tvs launched dvr capability built instead external boxes. one example launched show humax s 26-inch lcd tv 80-hour tivo dvr dvd recorder. one us s biggest satellite tv companies directtv even launched branded dvr show 100-hours recording capability instant replay search function. set can pause rewind tv 90 hours. microsoft chief bill gates announced pre-show keynote speech partnership tivo called tivotogo means people can play recorded programmes windows pcs mobile devices. reflect increasing trend freeing multimedia people can watch want want.\n"
89 | ]
90 | }
91 | ],
92 | "source": [
93 | "sentences = []\n",
94 | "labels = []\n",
95 | "with open(\"/tmp/bbc-text.csv\", 'r') as csvfile:\n",
96 | " csv_items = csv.reader(csvfile, delimiter=',')\n",
97 | "\n",
98 | " #skip csv header\n",
99 | " next(csv_items)\n",
100 | "\n",
101 | " for row in csv_items:\n",
102 | " labels.append(row[0])\n",
103 | " unfiltered_sentence = row[1].split()\n",
104 | " filtered_sentence = \" \"\n",
105 | " for word in unfiltered_sentence:\n",
106 | " if word not in stopwords:\n",
107 | " filtered_sentence = filtered_sentence + word + \" \"\n",
108 | " sentences.append(filtered_sentence.strip())\n",
109 | "\n",
110 | "print(len(sentences))\n",
111 | "print(sentences[0])\n",
112 | "\n",
113 | "#Expected output\n",
114 | "# 2225\n",
115 | "# tv future hands viewers home theatre systems plasma high-definition tvs digital video recorders moving living room way people watch tv will radically different five years time. according expert panel gathered annual consumer electronics show las vegas discuss new technologies will impact one favourite pastimes. us leading trend programmes content will delivered viewers via home networks cable satellite telecoms companies broadband service providers front rooms portable devices. one talked-about technologies ces digital personal video recorders (dvr pvr). set-top boxes like us s tivo uk s sky+ system allow people record store play pause forward wind tv programmes want. essentially technology allows much personalised tv. also built-in high-definition tv sets big business japan us slower take off europe lack high-definition programming. not can people forward wind adverts can also forget abiding network channel schedules putting together a-la-carte entertainment. us networks cable satellite companies worried means terms advertising revenues well brand identity viewer loyalty channels. although us leads technology moment also concern raised europe particularly growing uptake services like sky+. happens today will see nine months years time uk adam hume bbc broadcast s futurologist told bbc news website. likes bbc no issues lost advertising revenue yet. pressing issue moment commercial uk broadcasters brand loyalty important everyone. will talking content brands rather network brands said tim hanlon brand communications firm starcom mediavest. reality broadband connections anybody can producer content. added: challenge now hard promote programme much choice. means said stacey jolna senior vice president tv guide tv group way people find content want watch simplified tv viewers. means networks us terms channels take leaf google s book search engine future instead scheduler help people find want watch. kind channel model might work younger ipod generation used taking control gadgets play them. might not suit everyone panel recognised. older generations comfortable familiar schedules channel brands know getting. perhaps not want much choice put hands mr hanlon suggested. end kids just diapers pushing buttons already - everything possible available said mr hanlon. ultimately consumer will tell market want. 50 000 new gadgets technologies showcased ces many enhancing tv-watching experience. high-definition tv sets everywhere many new models lcd (liquid crystal display) tvs launched dvr capability built instead external boxes. one example launched show humax s 26-inch lcd tv 80-hour tivo dvr dvd recorder. one us s biggest satellite tv companies directtv even launched branded dvr show 100-hours recording capability instant replay search function. set can pause rewind tv 90 hours. microsoft chief bill gates announced pre-show keynote speech partnership tivo called tivotogo means people can play recorded programmes windows pcs mobile devices. reflect increasing trend freeing multimedia people can watch want want."
116 | ]
117 | },
118 | {
119 | "cell_type": "code",
120 | "execution_count": 10,
121 | "metadata": {
122 | "colab": {
123 | "base_uri": "https://localhost:8080/",
124 | "height": 55
125 | },
126 | "colab_type": "code",
127 | "id": "9LhzBBgSC3S5",
128 | "outputId": "0102c264-a5af-4e30-8f54-1e0c6801ee22"
129 | },
130 | "outputs": [
131 | {
132 | "name": "stdout",
133 | "output_type": "stream",
134 | "text": [
135 | "29714\n"
136 | ]
137 | }
138 | ],
139 | "source": [
140 | "tokenizer = Tokenizer(oov_token=\"\")\n",
141 | "tokenizer.fit_on_texts(sentences)\n",
142 | "word_index = tokenizer.word_index\n",
143 | "print(len(word_index))\n",
144 | "# Expected output\n",
145 | "# 29714"
146 | ]
147 | },
148 | {
149 | "cell_type": "code",
150 | "execution_count": 11,
151 | "metadata": {
152 | "colab": {
153 | "base_uri": "https://localhost:8080/",
154 | "height": 72
155 | },
156 | "colab_type": "code",
157 | "id": "1Gr3dbQfC5VR",
158 | "outputId": "3bea2352-078f-4d62-e861-0e2f487cafd4"
159 | },
160 | "outputs": [
161 | {
162 | "name": "stdout",
163 | "output_type": "stream",
164 | "text": [
165 | "[ 96 176 1157 ... 0 0 0]\n",
166 | "(2225, 2438)\n"
167 | ]
168 | }
169 | ],
170 | "source": [
171 | "sequences = tokenizer.texts_to_sequences(sentences)\n",
172 | "padded = pad_sequences(sequences, padding='post')\n",
173 | "print(padded[0])\n",
174 | "print(padded.shape)\n",
175 | "\n",
176 | "# Expected output\n",
177 | "# [ 96 176 1158 ... 0 0 0]\n",
178 | "# (2225, 2442)"
179 | ]
180 | },
181 | {
182 | "cell_type": "code",
183 | "execution_count": 12,
184 | "metadata": {
185 | "colab": {
186 | "base_uri": "https://localhost:8080/",
187 | "height": 72
188 | },
189 | "colab_type": "code",
190 | "id": "fZufOahzC6yx",
191 | "outputId": "be7eef17-de0d-4af2-9691-4af4e6f02fda"
192 | },
193 | "outputs": [
194 | {
195 | "name": "stdout",
196 | "output_type": "stream",
197 | "text": [
198 | "[[4], [2], [1], [1], [5], [3], [3], [1], [1], [5], [5], [2], [2], [3], [1], [2], [3], [1], [2], [4], [4], [4], [1], [1], [4], [1], [5], [4], [3], [5], [3], [4], [5], [5], [2], [3], [4], [5], [3], [2], [3], [1], [2], [1], [4], [5], [3], [3], [3], [2], [1], [3], [2], [2], [1], [3], [2], [1], [1], [2], [2], [1], [2], [1], [2], [4], [2], [5], [4], [2], [3], [2], [3], [1], [2], [4], [2], [1], [1], [2], [2], [1], [3], [2], [5], [3], [3], [2], [5], [2], [1], [1], [3], [1], [3], [1], [2], [1], [2], [5], [5], [1], [2], [3], [3], [4], [1], [5], [1], [4], [2], [5], [1], [5], [1], [5], [5], [3], [1], [1], [5], [3], [2], [4], [2], [2], [4], [1], [3], [1], [4], [5], [1], [2], [2], [4], [5], [4], [1], [2], [2], [2], [4], [1], [4], [2], [1], [5], [1], [4], [1], [4], [3], [2], [4], [5], [1], [2], [3], [2], [5], [3], [3], [5], [3], [2], [5], [3], [3], [5], [3], [1], [2], [3], [3], [2], [5], [1], [2], [2], [1], [4], [1], [4], [4], [1], [2], [1], [3], [5], [3], [2], [3], [2], [4], [3], [5], [3], [4], [2], [1], [2], [1], [4], [5], [2], [3], [3], [5], [1], [5], [3], [1], [5], [1], [1], [5], [1], [3], [3], [5], [4], [1], [3], [2], [5], [4], [1], [4], [1], [5], [3], [1], [5], [4], [2], [4], [2], [2], [4], [2], [1], [2], [1], [2], [1], [5], [2], [2], [5], [1], [1], [3], [4], [3], [3], [3], [4], [1], [4], [3], [2], [4], [5], [4], [1], [1], [2], [2], [3], [2], [4], [1], [5], [1], [3], [4], [5], [2], [1], [5], [1], [4], [3], [4], [2], [2], [3], [3], [1], [2], [4], [5], [3], [4], [2], [5], [1], [5], [1], [5], [3], [2], [1], [2], [1], [1], [5], [1], [3], [3], [2], [5], [4], [2], [1], [2], [5], [2], [2], [2], [3], [2], [3], [5], [5], [2], [1], [2], [3], [2], [4], [5], [2], [1], [1], [5], [2], [2], [3], [4], [5], [4], [3], [2], [1], [3], [2], [5], [4], [5], [4], [3], [1], [5], [2], [3], [2], [2], [3], [1], [4], [2], [2], [5], [5], [4], [1], [2], [5], [4], [4], [5], [5], [5], [3], [1], [3], [4], [2], [5], [3], [2], [5], [3], [3], [1], [1], [2], [3], [5], [2], [1], [2], [2], [1], [2], [3], [3], [3], [1], [4], [4], [2], [4], [1], [5], [2], [3], [2], [5], [2], [3], [5], [3], [2], [4], [2], [1], [1], [2], [1], [1], [5], [1], [1], [1], [4], [2], [2], [2], [3], [1], [1], [2], [4], [2], [3], [1], [3], [4], [2], [1], [5], [2], [3], [4], [2], [1], [2], [3], [2], [2], [1], [5], [4], [3], [4], [2], [1], [2], [5], [4], [4], [2], [1], [1], [5], [3], [3], [3], [1], [3], [4], [4], [5], [3], [4], [5], [2], [1], [1], [4], [2], [1], [1], [3], [1], [1], [2], [1], [5], [4], [3], [1], [3], [4], [2], [2], [2], [4], [2], [2], [1], [1], [1], [1], [2], [4], [5], [1], [1], [4], [2], [4], [5], [3], [1], [2], [3], [2], [4], [4], [3], [4], [2], [1], [2], [5], [1], [3], [5], [1], [1], [3], [4], [5], [4], [1], [3], [2], [5], [3], [2], [5], [1], [1], [4], [3], [5], [3], [5], [3], [4], [3], [5], [1], [2], [1], [5], [1], [5], [4], [2], [1], [3], [5], [3], [5], [5], [5], [3], [5], [4], [3], [4], [4], [1], [1], [4], [4], [1], [5], [5], [1], [4], [5], [1], [1], [4], [2], [3], [4], [2], [1], [5], [1], [5], [3], [4], [5], [5], [2], [5], [5], [1], [4], [4], [3], [1], [4], [1], [3], [3], [5], [4], [2], [4], [4], [4], [2], [3], [3], [1], [4], [2], [2], [5], [5], [1], [4], [2], [4], [5], [1], [4], [3], [4], [3], [2], [3], [3], [2], [1], [4], [1], [4], [3], [5], [4], [1], [5], [4], [1], [3], [5], [1], [4], [1], [1], [3], [5], [2], [3], [5], [2], [2], [4], [2], [5], [4], [1], [4], [3], [4], [3], [2], [3], [5], [1], [2], [2], [2], [5], [1], [2], [5], [5], [1], [5], [3], [3], [3], [1], [1], [1], [4], [3], [1], [3], [3], [4], [3], [1], [2], [5], [1], [2], [2], [4], [2], [5], [5], [5], [2], [5], [5], [3], [4], [2], [1], [4], [1], [1], [3], [2], [1], [4], [2], [1], [4], [1], [1], [5], [1], [2], [1], [2], [4], [3], [4], [2], [1], [1], [2], [2], [2], [2], [3], [1], [2], [4], [2], [1], [3], [2], [4], [2], [1], [2], [3], [5], [1], [2], [3], [2], [5], [2], [2], [2], [1], [3], [5], [1], [3], [1], [3], [3], [2], [2], [1], [4], [5], [1], [5], [2], [2], [2], [4], [1], [4], [3], [4], [4], [4], [1], [4], [4], [5], [5], [4], [1], [5], [4], [1], [1], [2], [5], [4], [2], [1], [2], [3], [2], [5], [4], [2], [3], [2], [4], [1], [2], [5], [2], [3], [1], [5], [3], [1], [2], [1], [3], [3], [1], [5], [5], [2], [2], [1], [4], [4], [1], [5], [4], [4], [2], [1], [5], [4], [1], [1], [2], [5], [2], [2], [2], [5], [1], [5], [4], [4], [4], [3], [4], [4], [5], [5], [1], [1], [3], [2], [5], [1], [3], [5], [4], [3], [4], [4], [2], [5], [3], [4], [3], [3], [1], [3], [3], [5], [4], [1], [3], [1], [5], [3], [2], [2], [3], [1], [1], [1], [5], [4], [4], [2], [5], [1], [3], [4], [3], [5], [4], [4], [2], [2], [1], [2], [2], [4], [3], [5], [2], [2], [2], [2], [2], [4], [1], [3], [4], [4], [2], [2], [5], [3], [5], [1], [4], [1], [5], [1], [4], [1], [2], [1], [3], [3], [5], [2], [1], [3], [3], [1], [5], [3], [2], [4], [1], [2], [2], [2], [5], [5], [4], [4], [2], [2], [5], [1], [2], [5], [4], [4], [2], [2], [1], [1], [1], [3], [3], [1], [3], [1], [2], [5], [1], [4], [5], [1], [1], [2], [2], [4], [4], [1], [5], [1], [5], [1], [5], [3], [5], [5], [4], [5], [2], [2], [3], [1], [3], [4], [2], [3], [1], [3], [1], [5], [1], [3], [1], [1], [4], [5], [1], [3], [1], [1], [2], [4], [5], [3], [4], [5], [3], [5], [3], [5], [5], [4], [5], [3], [5], [5], [4], [4], [1], [1], [5], [5], [4], [5], [3], [4], [5], [2], [4], [1], [2], [5], [5], [4], [5], [4], [2], [5], [1], [5], [2], [1], [2], [1], [3], [4], [5], [3], [2], [5], [5], [3], [2], [5], [1], [3], [1], [2], [2], [2], [2], [2], [5], [4], [1], [5], [5], [2], [1], [4], [4], [5], [1], [2], [3], [2], [3], [2], [2], [5], [3], [2], [2], [4], [3], [1], [4], [5], [3], [2], [2], [1], [5], [3], [4], [2], [2], [3], [2], [1], [5], [1], [5], [4], [3], [2], [2], [4], [2], [2], [1], [2], [4], [5], [3], [2], [3], [2], [1], [4], [2], [3], [5], [4], [2], [5], [1], [3], [3], [1], [3], [2], [4], [5], [1], [1], [4], [2], [1], [5], [4], [1], [3], [1], [2], [2], [2], [3], [5], [1], [3], [4], [2], [2], [4], [5], [5], [4], [4], [1], [1], [5], [4], [5], [1], [3], [4], [2], [1], [5], [2], [2], [5], [1], [2], [1], [4], [3], [3], [4], [5], [3], [5], [2], [2], [3], [1], [4], [1], [1], [1], [3], [2], [1], [2], [4], [1], [2], [2], [1], [3], [4], [1], [2], [4], [1], [1], [2], [2], [2], [2], [3], [5], [4], [2], [2], [1], [2], [5], [2], [5], [1], [3], [2], [2], [4], [5], [2], [2], [2], [3], [2], [3], [4], [5], [3], [5], [1], [4], [3], [2], [4], [1], [2], [2], [5], [4], [2], [2], [1], [1], [5], [1], [3], [1], [2], [1], [2], [3], [3], [2], [3], [4], [5], [1], [2], [5], [1], [3], [3], [4], [5], [2], [3], [3], [1], [4], [2], [1], [5], [1], [5], [1], [2], [1], [3], [5], [4], [2], [1], [3], [4], [1], [5], [2], [1], [5], [1], [4], [1], [4], [3], [1], [2], [5], [4], [4], [3], [4], [5], [4], [1], [2], [4], [2], [5], [1], [4], [3], [3], [3], [3], [5], [5], [5], [2], [3], [3], [1], [1], [4], [1], [3], [2], [2], [4], [1], [4], [2], [4], [3], [3], [1], [2], [3], [1], [2], [4], [2], [2], [5], [5], [1], [2], [4], [4], [3], [2], [3], [1], [5], [5], [3], [3], [2], [2], [4], [4], [1], [1], [3], [4], [1], [4], [2], [1], [2], [3], [1], [5], [2], [4], [3], [5], [4], [2], [1], [5], [4], [4], [5], [3], [4], [5], [1], [5], [1], [1], [1], [3], [4], [1], [2], [1], [1], [2], [4], [1], [2], [5], [3], [4], [1], [3], [4], [5], [3], [1], [3], [4], [2], [5], [1], [3], [2], [4], [4], [4], [3], [2], [1], [3], [5], [4], [5], [1], [4], [2], [3], [5], [4], [3], [1], [1], [2], [5], [2], [2], [3], [2], [2], [3], [4], [5], [3], [5], [5], [2], [3], [1], [3], [5], [1], [5], [3], [5], [5], [5], [2], [1], [3], [1], [5], [4], [4], [2], [3], [5], [2], [1], [2], [3], [3], [2], [1], [4], [4], [4], [2], [3], [3], [2], [1], [1], [5], [2], [1], [1], [3], [3], [3], [5], [3], [2], [4], [2], [3], [5], [5], [2], [1], [3], [5], [1], [5], [3], [3], [2], [3], [1], [5], [5], [4], [4], [4], [4], [3], [4], [2], [4], [1], [1], [5], [2], [4], [5], [2], [4], [1], [4], [5], [5], [3], [3], [1], [2], [2], [4], [5], [1], [3], [2], [4], [5], [3], [1], [5], [3], [3], [4], [1], [3], [2], [3], [5], [4], [1], [3], [5], [5], [2], [1], [4], [4], [1], [5], [4], [3], [4], [1], [3], [3], [1], [5], [1], [3], [1], [4], [5], [1], [5], [2], [2], [5], [5], [5], [4], [1], [2], [2], [3], [3], [2], [3], [5], [1], [1], [4], [3], [1], [2], [1], [2], [4], [1], [1], [2], [5], [1], [1], [4], [1], [2], [3], [2], [5], [4], [5], [3], [2], [5], [3], [5], [3], [3], [2], [1], [1], [1], [4], [4], [1], [3], [5], [4], [1], [5], [2], [5], [3], [2], [1], [4], [2], [1], [3], [2], [5], [5], [5], [3], [5], [3], [5], [1], [5], [1], [3], [3], [2], [3], [4], [1], [4], [1], [2], [3], [4], [5], [5], [3], [5], [3], [1], [1], [3], [2], [4], [1], [3], [3], [5], [1], [3], [3], [2], [4], [4], [2], [4], [1], [1], [2], [3], [2], [4], [1], [4], [3], [5], [1], [2], [1], [5], [4], [4], [1], [3], [1], [2], [1], [2], [1], [1], [5], [5], [2], [4], [4], [2], [4], [2], [2], [1], [1], [3], [1], [4], [1], [4], [1], [1], [2], [2], [4], [1], [2], [4], [4], [3], [1], [2], [5], [5], [4], [3], [1], [1], [4], [2], [4], [5], [5], [3], [3], [2], [5], [1], [5], [5], [2], [1], [3], [4], [2], [1], [5], [4], [3], [3], [1], [1], [2], [2], [2], [2], [2], [5], [2], [3], [3], [4], [4], [5], [3], [5], [2], [3], [1], [1], [2], [4], [2], [4], [1], [2], [2], [3], [1], [1], [3], [3], [5], [5], [3], [2], [3], [3], [2], [4], [3], [3], [3], [3], [3], [5], [5], [4], [3], [1], [3], [1], [4], [1], [1], [1], [5], [4], [5], [4], [1], [4], [1], [1], [5], [5], [2], [5], [5], [3], [2], [1], [4], [4], [3], [2], [1], [2], [5], [1], [3], [5], [1], [1], [2], [3], [4], [4], [2], [2], [1], [3], [5], [1], [1], [3], [5], [4], [1], [5], [2], [3], [1], [3], [4], [5], [1], [3], [2], [5], [3], [5], [3], [1], [3], [2], [2], [3], [2], [4], [1], [2], [5], [2], [1], [1], [5], [4], [3], [4], [3], [3], [1], [1], [1], [2], [4], [5], [2], [1], [2], [1], [2], [4], [2], [2], [2], [2], [1], [1], [1], [2], [2], [5], [2], [2], [2], [1], [1], [1], [4], [2], [1], [1], [1], [2], [5], [4], [4], [4], [3], [2], [2], [4], [2], [4], [1], [1], [3], [3], [3], [1], [1], [3], [3], [4], [2], [1], [1], [1], [1], [2], [1], [2], [2], [2], [2], [1], [3], [1], [4], [4], [1], [4], [2], [5], [2], [1], [2], [4], [4], [3], [5], [2], [5], [2], [4], [3], [5], [3], [5], [5], [4], [2], [4], [4], [2], [3], [1], [5], [2], [3], [5], [2], [4], [1], [4], [3], [1], [3], [2], [3], [3], [2], [2], [2], [4], [3], [2], [3], [2], [5], [3], [1], [3], [3], [1], [5], [4], [4], [2], [4], [1], [2], [2], [3], [1], [4], [4], [4], [1], [5], [1], [3], [2], [3], [3], [5], [4], [2], [4], [1], [5], [5], [1], [2], [5], [4], [4], [1], [5], [2], [3], [3], [3], [4], [4], [2], [3], [2], [3], [3], [5], [1], [4], [2], [4], [5], [4], [4], [1], [3], [1], [1], [3], [5], [5], [2], [3], [3], [1], [2], [2], [4], [2], [4], [4], [1], [2], [3], [1], [2], [2], [1], [4], [1], [4], [5], [1], [1], [5], [2], [4], [1], [1], [3], [4], [2], [3], [1], [1], [3], [5], [4], [4], [4], [2], [1], [5], [5], [4], [2], [3], [4], [1], [1], [4], [4], [3], [2], [1], [5], [5], [1], [5], [4], [4], [2], [2], [2], [1], [1], [4], [1], [2], [4], [2], [2], [1], [2], [3], [2], [2], [4], [2], [4], [3], [4], [5], [3], [4], [5], [1], [3], [5], [2], [4], [2], [4], [5], [4], [1], [2], [2], [3], [5], [3], [1]]\n",
199 | "{'sport': 1, 'business': 2, 'politics': 3, 'tech': 4, 'entertainment': 5}\n"
200 | ]
201 | }
202 | ],
203 | "source": [
204 | "label_tokenizer = Tokenizer()\n",
205 | "label_tokenizer.fit_on_texts(labels)\n",
206 | "label_word_index = label_tokenizer.word_index\n",
207 | "label_seq = label_tokenizer.texts_to_sequences(labels)\n",
208 | "print(label_seq)\n",
209 | "print(label_word_index)\n",
210 | "\n",
211 | "# Expected Output\n",
212 | "# [[4], [2], [1], [1], [5], [3], [3], [1], [1], [5], [5], [2], [2], [3], [1], [2], [3], [1], [2], [4], [4], [4], [1], [1], [4], [1], [5], [4], [3], [5], [3], [4], [5], [5], [2], [3], [4], [5], [3], [2], [3], [1], [2], [1], [4], [5], [3], [3], [3], [2], [1], [3], [2], [2], [1], [3], [2], [1], [1], [2], [2], [1], [2], [1], [2], [4], [2], [5], [4], [2], [3], [2], [3], [1], [2], [4], [2], [1], [1], [2], [2], [1], [3], [2], [5], [3], [3], [2], [5], [2], [1], [1], [3], [1], [3], [1], [2], [1], [2], [5], [5], [1], [2], [3], [3], [4], [1], [5], [1], [4], [2], [5], [1], [5], [1], [5], [5], [3], [1], [1], [5], [3], [2], [4], [2], [2], [4], [1], [3], [1], [4], [5], [1], [2], [2], [4], [5], [4], [1], [2], [2], [2], [4], [1], [4], [2], [1], [5], [1], [4], [1], [4], [3], [2], [4], [5], [1], [2], [3], [2], [5], [3], [3], [5], [3], [2], [5], [3], [3], [5], [3], [1], [2], [3], [3], [2], [5], [1], [2], [2], [1], [4], [1], [4], [4], [1], [2], [1], [3], [5], [3], [2], [3], [2], [4], [3], [5], [3], [4], [2], [1], [2], [1], [4], [5], [2], [3], [3], [5], [1], [5], [3], [1], [5], [1], [1], [5], [1], [3], [3], [5], [4], [1], [3], [2], [5], [4], [1], [4], [1], [5], [3], [1], [5], [4], [2], [4], [2], [2], [4], [2], [1], [2], [1], [2], [1], [5], [2], [2], [5], [1], [1], [3], [4], [3], [3], [3], [4], [1], [4], [3], [2], [4], [5], [4], [1], [1], [2], [2], [3], [2], [4], [1], [5], [1], [3], [4], [5], [2], [1], [5], [1], [4], [3], [4], [2], [2], [3], [3], [1], [2], [4], [5], [3], [4], [2], [5], [1], [5], [1], [5], [3], [2], [1], [2], [1], [1], [5], [1], [3], [3], [2], [5], [4], [2], [1], [2], [5], [2], [2], [2], [3], [2], [3], [5], [5], [2], [1], [2], [3], [2], [4], [5], [2], [1], [1], [5], [2], [2], [3], [4], [5], [4], [3], [2], [1], [3], [2], [5], [4], [5], [4], [3], [1], [5], [2], [3], [2], [2], [3], [1], [4], [2], [2], [5], [5], [4], [1], [2], [5], [4], [4], [5], [5], [5], [3], [1], [3], [4], [2], [5], [3], [2], [5], [3], [3], [1], [1], [2], [3], [5], [2], [1], [2], [2], [1], [2], [3], [3], [3], [1], [4], [4], [2], [4], [1], [5], [2], [3], [2], [5], [2], [3], [5], [3], [2], [4], [2], [1], [1], [2], [1], [1], [5], [1], [1], [1], [4], [2], [2], [2], [3], [1], [1], [2], [4], [2], [3], [1], [3], [4], [2], [1], [5], [2], [3], [4], [2], [1], [2], [3], [2], [2], [1], [5], [4], [3], [4], [2], [1], [2], [5], [4], [4], [2], [1], [1], [5], [3], [3], [3], [1], [3], [4], [4], [5], [3], [4], [5], [2], [1], [1], [4], [2], [1], [1], [3], [1], [1], [2], [1], [5], [4], [3], [1], [3], [4], [2], [2], [2], [4], [2], [2], [1], [1], [1], [1], [2], [4], [5], [1], [1], [4], [2], [4], [5], [3], [1], [2], [3], [2], [4], [4], [3], [4], [2], [1], [2], [5], [1], [3], [5], [1], [1], [3], [4], [5], [4], [1], [3], [2], [5], [3], [2], [5], [1], [1], [4], [3], [5], [3], [5], [3], [4], [3], [5], [1], [2], [1], [5], [1], [5], [4], [2], [1], [3], [5], [3], [5], [5], [5], [3], [5], [4], [3], [4], [4], [1], [1], [4], [4], [1], [5], [5], [1], [4], [5], [1], [1], [4], [2], [3], [4], [2], [1], [5], [1], [5], [3], [4], [5], [5], [2], [5], [5], [1], [4], [4], [3], [1], [4], [1], [3], [3], [5], [4], [2], [4], [4], [4], [2], [3], [3], [1], [4], [2], [2], [5], [5], [1], [4], [2], [4], [5], [1], [4], [3], [4], [3], [2], [3], [3], [2], [1], [4], [1], [4], [3], [5], [4], [1], [5], [4], [1], [3], [5], [1], [4], [1], [1], [3], [5], [2], [3], [5], [2], [2], [4], [2], [5], [4], [1], [4], [3], [4], [3], [2], [3], [5], [1], [2], [2], [2], [5], [1], [2], [5], [5], [1], [5], [3], [3], [3], [1], [1], [1], [4], [3], [1], [3], [3], [4], [3], [1], [2], [5], [1], [2], [2], [4], [2], [5], [5], [5], [2], [5], [5], [3], [4], [2], [1], [4], [1], [1], [3], [2], [1], [4], [2], [1], [4], [1], [1], [5], [1], [2], [1], [2], [4], [3], [4], [2], [1], [1], [2], [2], [2], [2], [3], [1], [2], [4], [2], [1], [3], [2], [4], [2], [1], [2], [3], [5], [1], [2], [3], [2], [5], [2], [2], [2], [1], [3], [5], [1], [3], [1], [3], [3], [2], [2], [1], [4], [5], [1], [5], [2], [2], [2], [4], [1], [4], [3], [4], [4], [4], [1], [4], [4], [5], [5], [4], [1], [5], [4], [1], [1], [2], [5], [4], [2], [1], [2], [3], [2], [5], [4], [2], [3], [2], [4], [1], [2], [5], [2], [3], [1], [5], [3], [1], [2], [1], [3], [3], [1], [5], [5], [2], [2], [1], [4], [4], [1], [5], [4], [4], [2], [1], [5], [4], [1], [1], [2], [5], [2], [2], [2], [5], [1], [5], [4], [4], [4], [3], [4], [4], [5], [5], [1], [1], [3], [2], [5], [1], [3], [5], [4], [3], [4], [4], [2], [5], [3], [4], [3], [3], [1], [3], [3], [5], [4], [1], [3], [1], [5], [3], [2], [2], [3], [1], [1], [1], [5], [4], [4], [2], [5], [1], [3], [4], [3], [5], [4], [4], [2], [2], [1], [2], [2], [4], [3], [5], [2], [2], [2], [2], [2], [4], [1], [3], [4], [4], [2], [2], [5], [3], [5], [1], [4], [1], [5], [1], [4], [1], [2], [1], [3], [3], [5], [2], [1], [3], [3], [1], [5], [3], [2], [4], [1], [2], [2], [2], [5], [5], [4], [4], [2], [2], [5], [1], [2], [5], [4], [4], [2], [2], [1], [1], [1], [3], [3], [1], [3], [1], [2], [5], [1], [4], [5], [1], [1], [2], [2], [4], [4], [1], [5], [1], [5], [1], [5], [3], [5], [5], [4], [5], [2], [2], [3], [1], [3], [4], [2], [3], [1], [3], [1], [5], [1], [3], [1], [1], [4], [5], [1], [3], [1], [1], [2], [4], [5], [3], [4], [5], [3], [5], [3], [5], [5], [4], [5], [3], [5], [5], [4], [4], [1], [1], [5], [5], [4], [5], [3], [4], [5], [2], [4], [1], [2], [5], [5], [4], [5], [4], [2], [5], [1], [5], [2], [1], [2], [1], [3], [4], [5], [3], [2], [5], [5], [3], [2], [5], [1], [3], [1], [2], [2], [2], [2], [2], [5], [4], [1], [5], [5], [2], [1], [4], [4], [5], [1], [2], [3], [2], [3], [2], [2], [5], [3], [2], [2], [4], [3], [1], [4], [5], [3], [2], [2], [1], [5], [3], [4], [2], [2], [3], [2], [1], [5], [1], [5], [4], [3], [2], [2], [4], [2], [2], [1], [2], [4], [5], [3], [2], [3], [2], [1], [4], [2], [3], [5], [4], [2], [5], [1], [3], [3], [1], [3], [2], [4], [5], [1], [1], [4], [2], [1], [5], [4], [1], [3], [1], [2], [2], [2], [3], [5], [1], [3], [4], [2], [2], [4], [5], [5], [4], [4], [1], [1], [5], [4], [5], [1], [3], [4], [2], [1], [5], [2], [2], [5], [1], [2], [1], [4], [3], [3], [4], [5], [3], [5], [2], [2], [3], [1], [4], [1], [1], [1], [3], [2], [1], [2], [4], [1], [2], [2], [1], [3], [4], [1], [2], [4], [1], [1], [2], [2], [2], [2], [3], [5], [4], [2], [2], [1], [2], [5], [2], [5], [1], [3], [2], [2], [4], [5], [2], [2], [2], [3], [2], [3], [4], [5], [3], [5], [1], [4], [3], [2], [4], [1], [2], [2], [5], [4], [2], [2], [1], [1], [5], [1], [3], [1], [2], [1], [2], [3], [3], [2], [3], [4], [5], [1], [2], [5], [1], [3], [3], [4], [5], [2], [3], [3], [1], [4], [2], [1], [5], [1], [5], [1], [2], [1], [3], [5], [4], [2], [1], [3], [4], [1], [5], [2], [1], [5], [1], [4], [1], [4], [3], [1], [2], [5], [4], [4], [3], [4], [5], [4], [1], [2], [4], [2], [5], [1], [4], [3], [3], [3], [3], [5], [5], [5], [2], [3], [3], [1], [1], [4], [1], [3], [2], [2], [4], [1], [4], [2], [4], [3], [3], [1], [2], [3], [1], [2], [4], [2], [2], [5], [5], [1], [2], [4], [4], [3], [2], [3], [1], [5], [5], [3], [3], [2], [2], [4], [4], [1], [1], [3], [4], [1], [4], [2], [1], [2], [3], [1], [5], [2], [4], [3], [5], [4], [2], [1], [5], [4], [4], [5], [3], [4], [5], [1], [5], [1], [1], [1], [3], [4], [1], [2], [1], [1], [2], [4], [1], [2], [5], [3], [4], [1], [3], [4], [5], [3], [1], [3], [4], [2], [5], [1], [3], [2], [4], [4], [4], [3], [2], [1], [3], [5], [4], [5], [1], [4], [2], [3], [5], [4], [3], [1], [1], [2], [5], [2], [2], [3], [2], [2], [3], [4], [5], [3], [5], [5], [2], [3], [1], [3], [5], [1], [5], [3], [5], [5], [5], [2], [1], [3], [1], [5], [4], [4], [2], [3], [5], [2], [1], [2], [3], [3], [2], [1], [4], [4], [4], [2], [3], [3], [2], [1], [1], [5], [2], [1], [1], [3], [3], [3], [5], [3], [2], [4], [2], [3], [5], [5], [2], [1], [3], [5], [1], [5], [3], [3], [2], [3], [1], [5], [5], [4], [4], [4], [4], [3], [4], [2], [4], [1], [1], [5], [2], [4], [5], [2], [4], [1], [4], [5], [5], [3], [3], [1], [2], [2], [4], [5], [1], [3], [2], [4], [5], [3], [1], [5], [3], [3], [4], [1], [3], [2], [3], [5], [4], [1], [3], [5], [5], [2], [1], [4], [4], [1], [5], [4], [3], [4], [1], [3], [3], [1], [5], [1], [3], [1], [4], [5], [1], [5], [2], [2], [5], [5], [5], [4], [1], [2], [2], [3], [3], [2], [3], [5], [1], [1], [4], [3], [1], [2], [1], [2], [4], [1], [1], [2], [5], [1], [1], [4], [1], [2], [3], [2], [5], [4], [5], [3], [2], [5], [3], [5], [3], [3], [2], [1], [1], [1], [4], [4], [1], [3], [5], [4], [1], [5], [2], [5], [3], [2], [1], [4], [2], [1], [3], [2], [5], [5], [5], [3], [5], [3], [5], [1], [5], [1], [3], [3], [2], [3], [4], [1], [4], [1], [2], [3], [4], [5], [5], [3], [5], [3], [1], [1], [3], [2], [4], [1], [3], [3], [5], [1], [3], [3], [2], [4], [4], [2], [4], [1], [1], [2], [3], [2], [4], [1], [4], [3], [5], [1], [2], [1], [5], [4], [4], [1], [3], [1], [2], [1], [2], [1], [1], [5], [5], [2], [4], [4], [2], [4], [2], [2], [1], [1], [3], [1], [4], [1], [4], [1], [1], [2], [2], [4], [1], [2], [4], [4], [3], [1], [2], [5], [5], [4], [3], [1], [1], [4], [2], [4], [5], [5], [3], [3], [2], [5], [1], [5], [5], [2], [1], [3], [4], [2], [1], [5], [4], [3], [3], [1], [1], [2], [2], [2], [2], [2], [5], [2], [3], [3], [4], [4], [5], [3], [5], [2], [3], [1], [1], [2], [4], [2], [4], [1], [2], [2], [3], [1], [1], [3], [3], [5], [5], [3], [2], [3], [3], [2], [4], [3], [3], [3], [3], [3], [5], [5], [4], [3], [1], [3], [1], [4], [1], [1], [1], [5], [4], [5], [4], [1], [4], [1], [1], [5], [5], [2], [5], [5], [3], [2], [1], [4], [4], [3], [2], [1], [2], [5], [1], [3], [5], [1], [1], [2], [3], [4], [4], [2], [2], [1], [3], [5], [1], [1], [3], [5], [4], [1], [5], [2], [3], [1], [3], [4], [5], [1], [3], [2], [5], [3], [5], [3], [1], [3], [2], [2], [3], [2], [4], [1], [2], [5], [2], [1], [1], [5], [4], [3], [4], [3], [3], [1], [1], [1], [2], [4], [5], [2], [1], [2], [1], [2], [4], [2], [2], [2], [2], [1], [1], [1], [2], [2], [5], [2], [2], [2], [1], [1], [1], [4], [2], [1], [1], [1], [2], [5], [4], [4], [4], [3], [2], [2], [4], [2], [4], [1], [1], [3], [3], [3], [1], [1], [3], [3], [4], [2], [1], [1], [1], [1], [2], [1], [2], [2], [2], [2], [1], [3], [1], [4], [4], [1], [4], [2], [5], [2], [1], [2], [4], [4], [3], [5], [2], [5], [2], [4], [3], [5], [3], [5], [5], [4], [2], [4], [4], [2], [3], [1], [5], [2], [3], [5], [2], [4], [1], [4], [3], [1], [3], [2], [3], [3], [2], [2], [2], [4], [3], [2], [3], [2], [5], [3], [1], [3], [3], [1], [5], [4], [4], [2], [4], [1], [2], [2], [3], [1], [4], [4], [4], [1], [5], [1], [3], [2], [3], [3], [5], [4], [2], [4], [1], [5], [5], [1], [2], [5], [4], [4], [1], [5], [2], [3], [3], [3], [4], [4], [2], [3], [2], [3], [3], [5], [1], [4], [2], [4], [5], [4], [4], [1], [3], [1], [1], [3], [5], [5], [2], [3], [3], [1], [2], [2], [4], [2], [4], [4], [1], [2], [3], [1], [2], [2], [1], [4], [1], [4], [5], [1], [1], [5], [2], [4], [1], [1], [3], [4], [2], [3], [1], [1], [3], [5], [4], [4], [4], [2], [1], [5], [5], [4], [2], [3], [4], [1], [1], [4], [4], [3], [2], [1], [5], [5], [1], [5], [4], [4], [2], [2], [2], [1], [1], [4], [1], [2], [4], [2], [2], [1], [2], [3], [2], [2], [4], [2], [4], [3], [4], [5], [3], [4], [5], [1], [3], [5], [2], [4], [2], [4], [5], [4], [1], [2], [2], [3], [5], [3], [1]]\n",
213 | "# {'sport': 1, 'business': 2, 'politics': 3, 'tech': 4, 'entertainment': 5}"
214 | ]
215 | },
216 | {
217 | "cell_type": "code",
218 | "execution_count": 0,
219 | "metadata": {
220 | "colab": {},
221 | "colab_type": "code",
222 | "id": "E7WuGkVJWjdk"
223 | },
224 | "outputs": [],
225 | "source": []
226 | }
227 | ],
228 | "metadata": {
229 | "colab": {
230 | "machine_shape": "hm",
231 | "name": "Exercise-question.ipynb",
232 | "provenance": []
233 | },
234 | "kernelspec": {
235 | "display_name": "Python 3",
236 | "language": "python",
237 | "name": "python3"
238 | },
239 | "language_info": {
240 | "codemirror_mode": {
241 | "name": "ipython",
242 | "version": 3
243 | },
244 | "file_extension": ".py",
245 | "mimetype": "text/x-python",
246 | "name": "python",
247 | "nbconvert_exporter": "python",
248 | "pygments_lexer": "ipython3",
249 | "version": "3.7.3"
250 | }
251 | },
252 | "nbformat": 4,
253 | "nbformat_minor": 1
254 | }
255 |
--------------------------------------------------------------------------------
/Course 3 - NLP in Tensorflow/Week3_Exercise_Exploring_Overfitting.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {
7 | "colab": {},
8 | "colab_type": "code",
9 | "id": "zX4Kg8DUTKWO"
10 | },
11 | "outputs": [],
12 | "source": [
13 | "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
14 | "# you may not use this file except in compliance with the License.\n",
15 | "# You may obtain a copy of the License at\n",
16 | "#\n",
17 | "# https://www.apache.org/licenses/LICENSE-2.0\n",
18 | "#\n",
19 | "# Unless required by applicable law or agreed to in writing, software\n",
20 | "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
21 | "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
22 | "# See the License for the specific language governing permissions and\n",
23 | "# limitations under the License."
24 | ]
25 | },
26 | {
27 | "cell_type": "code",
28 | "execution_count": null,
29 | "metadata": {
30 | "colab": {},
31 | "colab_type": "code",
32 | "id": "hmA6EzkQJ5jt"
33 | },
34 | "outputs": [],
35 | "source": [
36 | "import json\n",
37 | "import tensorflow as tf\n",
38 | "import csv\n",
39 | "import random\n",
40 | "import numpy as np\n",
41 | "\n",
42 | "from tensorflow.keras.preprocessing.text import Tokenizer\n",
43 | "from tensorflow.keras.preprocessing.sequence import pad_sequences\n",
44 | "from tensorflow.keras.utils import to_categorical\n",
45 | "from tensorflow.keras import regularizers\n",
46 | "\n",
47 | "\n",
48 | "embedding_dim = 100\n",
49 | "max_length = 16\n",
50 | "trunc_type='post'\n",
51 | "padding_type='post'\n",
52 | "oov_tok = \"\"\n",
53 | "training_size=160000\n",
54 | "test_portion=.1\n",
55 | "\n",
56 | "corpus = []\n"
57 | ]
58 | },
59 | {
60 | "cell_type": "code",
61 | "execution_count": null,
62 | "metadata": {
63 | "colab": {
64 | "base_uri": "https://localhost:8080/",
65 | "height": 204
66 | },
67 | "colab_type": "code",
68 | "id": "bM0l_dORKqE0",
69 | "outputId": "491ba86b-f780-4355-a4be-765565a29c8c"
70 | },
71 | "outputs": [
72 | {
73 | "name": "stdout",
74 | "output_type": "stream",
75 | "text": [
76 | "--2019-06-07 17:53:35-- https://storage.googleapis.com/laurencemoroney-blog.appspot.com/training_cleaned.csv\n",
77 | "Resolving storage.googleapis.com (storage.googleapis.com)... 173.194.192.128, 2607:f8b0:4001:c1d::80\n",
78 | "Connecting to storage.googleapis.com (storage.googleapis.com)|173.194.192.128|:443... connected.\n",
79 | "HTTP request sent, awaiting response... 200 OK\n",
80 | "Length: 238942690 (228M) [application/octet-stream]\n",
81 | "Saving to: ‘/tmp/training_cleaned.csv’\n",
82 | "\n",
83 | "/tmp/training_clean 100%[===================>] 227.87M 221MB/s in 1.0s \n",
84 | "\n",
85 | "2019-06-07 17:53:36 (221 MB/s) - ‘/tmp/training_cleaned.csv’ saved [238942690/238942690]\n",
86 | "\n"
87 | ]
88 | }
89 | ],
90 | "source": [
91 | "# Note that I cleaned the Stanford dataset to remove LATIN1 encoding to make it easier for Python CSV reader\n",
92 | "# You can do that yourself with:\n",
93 | "# iconv -f LATIN1 -t UTF8 training.1600000.processed.noemoticon.csv -o training_cleaned.csv\n",
94 | "# I then hosted it on my site to make it easier to use in this notebook\n",
95 | "\n",
96 | "!wget --no-check-certificate \\\n",
97 | " https://storage.googleapis.com/laurencemoroney-blog.appspot.com/training_cleaned.csv \\\n",
98 | " -O /tmp/training_cleaned.csv\n",
99 | "\n",
100 | "num_sentences = 0\n",
101 | "\n",
102 | "with open(\"/tmp/training_cleaned.csv\") as csvfile:\n",
103 | " reader = csv.reader(csvfile, delimiter=',')\n",
104 | " for row in reader:\n",
105 | " list_item=[]\n",
106 | " list_item.append(row[5])\n",
107 | " this_label=row[0]\n",
108 | " if this_label=='0':\n",
109 | " list_item.append(0)\n",
110 | " else:\n",
111 | " list_item.append(1)\n",
112 | " num_sentences = num_sentences + 1\n",
113 | " corpus.append(list_item)\n"
114 | ]
115 | },
116 | {
117 | "cell_type": "code",
118 | "execution_count": null,
119 | "metadata": {
120 | "colab": {
121 | "base_uri": "https://localhost:8080/",
122 | "height": 68
123 | },
124 | "colab_type": "code",
125 | "id": "3kxblBUjEUX-",
126 | "outputId": "3c0227a2-e74b-4d9b-cabb-f9ee150571b1"
127 | },
128 | "outputs": [
129 | {
130 | "name": "stdout",
131 | "output_type": "stream",
132 | "text": [
133 | "1600000\n",
134 | "1600000\n",
135 | "[\"is upset that he can't update his Facebook by texting it... and might cry as a result School today also. Blah!\", 0]\n"
136 | ]
137 | }
138 | ],
139 | "source": [
140 | "print(num_sentences)\n",
141 | "print(len(corpus))\n",
142 | "print(corpus[1])\n",
143 | "\n",
144 | "# Expected Output:\n",
145 | "# 1600000\n",
146 | "# 1600000\n",
147 | "# [\"is upset that he can't update his Facebook by texting it... and might cry as a result School today also. Blah!\", 0]"
148 | ]
149 | },
150 | {
151 | "cell_type": "code",
152 | "execution_count": null,
153 | "metadata": {
154 | "colab": {},
155 | "colab_type": "code",
156 | "id": "ohOGz24lsNAD"
157 | },
158 | "outputs": [],
159 | "source": [
160 | "sentences=[]\n",
161 | "labels=[]\n",
162 | "random.shuffle(corpus)\n",
163 | "for x in range(training_size):\n",
164 | " sentences.append(corpus[x][0])\n",
165 | " labels.append(corpus[x][1])\n",
166 | "\n",
167 | "\n",
168 | "tokenizer = Tokenizer()\n",
169 | "tokenizer.fit_on_texts(sentences)\n",
170 | "\n",
171 | "word_index = tokenizer.word_index\n",
172 | "vocab_size=len(word_index)\n",
173 | "\n",
174 | "sequences = tokenizer.texts_to_sequences(sentences)\n",
175 | "padded = pad_sequences(sequences, maxlen=max_length, padding=padding_type, truncating=trunc_type)\n",
176 | "\n",
177 | "split = int(test_portion * training_size)\n",
178 | "\n",
179 | "test_sequences = padded[0:split]\n",
180 | "training_sequences = padded[split:training_size]\n",
181 | "test_labels = labels[0:split]\n",
182 | "training_labels = labels[split:training_size]"
183 | ]
184 | },
185 | {
186 | "cell_type": "code",
187 | "execution_count": null,
188 | "metadata": {
189 | "colab": {
190 | "base_uri": "https://localhost:8080/",
191 | "height": 51
192 | },
193 | "colab_type": "code",
194 | "id": "gIrtRem1En3N",
195 | "outputId": "4ad8401c-8dba-420d-8aee-38dac0b0839a"
196 | },
197 | "outputs": [
198 | {
199 | "name": "stdout",
200 | "output_type": "stream",
201 | "text": [
202 | "138858\n",
203 | "1\n"
204 | ]
205 | }
206 | ],
207 | "source": [
208 | "print(vocab_size)\n",
209 | "print(word_index['i'])\n",
210 | "# Expected Output\n",
211 | "# 138858\n",
212 | "# 1"
213 | ]
214 | },
215 | {
216 | "cell_type": "code",
217 | "execution_count": null,
218 | "metadata": {
219 | "colab": {
220 | "base_uri": "https://localhost:8080/",
221 | "height": 204
222 | },
223 | "colab_type": "code",
224 | "id": "C1zdgJkusRh0",
225 | "outputId": "b6edd322-8191-45e7-cb12-08921685a72f"
226 | },
227 | "outputs": [
228 | {
229 | "name": "stdout",
230 | "output_type": "stream",
231 | "text": [
232 | "--2019-06-07 17:55:30-- https://storage.googleapis.com/laurencemoroney-blog.appspot.com/glove.6B.100d.txt\n",
233 | "Resolving storage.googleapis.com (storage.googleapis.com)... 64.233.183.128, 2607:f8b0:4001:c12::80\n",
234 | "Connecting to storage.googleapis.com (storage.googleapis.com)|64.233.183.128|:443... connected.\n",
235 | "HTTP request sent, awaiting response... 200 OK\n",
236 | "Length: 347116733 (331M) [text/plain]\n",
237 | "Saving to: ‘/tmp/glove.6B.100d.txt’\n",
238 | "\n",
239 | "/tmp/glove.6B.100d. 100%[===================>] 331.04M 160MB/s in 2.1s \n",
240 | "\n",
241 | "2019-06-07 17:55:33 (160 MB/s) - ‘/tmp/glove.6B.100d.txt’ saved [347116733/347116733]\n",
242 | "\n"
243 | ]
244 | }
245 | ],
246 | "source": [
247 | "# Note this is the 100 dimension version of GloVe from Stanford\n",
248 | "# I unzipped and hosted it on my site to make this notebook easier\n",
249 | "!wget --no-check-certificate \\\n",
250 | " https://storage.googleapis.com/laurencemoroney-blog.appspot.com/glove.6B.100d.txt \\\n",
251 | " -O /tmp/glove.6B.100d.txt\n",
252 | "embeddings_index = {};\n",
253 | "with open('/tmp/glove.6B.100d.txt') as f:\n",
254 | " for line in f:\n",
255 | " values = line.split();\n",
256 | " word = values[0];\n",
257 | " coefs = np.asarray(values[1:], dtype='float32');\n",
258 | " embeddings_index[word] = coefs;\n",
259 | "\n",
260 | "embeddings_matrix = np.zeros((vocab_size+1, embedding_dim));\n",
261 | "for word, i in word_index.items():\n",
262 | " embedding_vector = embeddings_index.get(word);\n",
263 | " if embedding_vector is not None:\n",
264 | " embeddings_matrix[i] = embedding_vector;"
265 | ]
266 | },
267 | {
268 | "cell_type": "code",
269 | "execution_count": null,
270 | "metadata": {
271 | "colab": {
272 | "base_uri": "https://localhost:8080/",
273 | "height": 34
274 | },
275 | "colab_type": "code",
276 | "id": "71NLk_lpFLNt",
277 | "outputId": "97cb88db-754f-4375-fdc3-876cd6b4fdce"
278 | },
279 | "outputs": [
280 | {
281 | "name": "stdout",
282 | "output_type": "stream",
283 | "text": [
284 | "138859\n"
285 | ]
286 | }
287 | ],
288 | "source": [
289 | "print(len(embeddings_matrix))\n",
290 | "# Expected Output\n",
291 | "# 138859"
292 | ]
293 | },
294 | {
295 | "cell_type": "code",
296 | "execution_count": null,
297 | "metadata": {
298 | "colab": {},
299 | "colab_type": "code",
300 | "id": "iKKvbuEBOGFz"
301 | },
302 | "outputs": [],
303 | "source": [
304 | "model = tf.keras.Sequential([\n",
305 | " tf.keras.layers.Embedding(vocab_size+1, embedding_dim, input_length=max_length, weights=[embeddings_matrix], trainable=False),\n",
306 | " tf.keras.layers.Dropout(0.2),\n",
307 | " tf.keras.layers.Conv1D(64, 5, activation='relu'),\n",
308 | " tf.keras.layers.MaxPooling1D(pool_size=4),\n",
309 | " tf.keras.layers.LSTM(64),\n",
310 | " tf.keras.layers.Dense(1, activation='sigmoid')\n",
311 | "])\n",
312 | "model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])\n",
313 | "model.summary()\n",
314 | "\n",
315 | "num_epochs = 50\n",
316 | "\n",
317 | "training_padded = np.array(training_sequences)\n",
318 | "training_labels = np.array(training_labels)\n",
319 | "testing_padded = np.array(test_sequences)\n",
320 | "testing_labels = np.array(test_labels)\n",
321 | "\n",
322 | "history = model.fit(training_padded, training_labels, epochs=num_epochs, validation_data=(testing_padded, testing_labels), verbose=2)\n",
323 | "\n",
324 | "print(\"Training Complete\")"
325 | ]
326 | },
327 | {
328 | "cell_type": "code",
329 | "execution_count": null,
330 | "metadata": {
331 | "colab": {},
332 | "colab_type": "code",
333 | "id": "qxju4ItJKO8F"
334 | },
335 | "outputs": [],
336 | "source": [
337 | "import matplotlib.image as mpimg\n",
338 | "import matplotlib.pyplot as plt\n",
339 | "\n",
340 | "#-----------------------------------------------------------\n",
341 | "# Retrieve a list of list results on training and test data\n",
342 | "# sets for each training epoch\n",
343 | "#-----------------------------------------------------------\n",
344 | "acc=history.history['accuracy']\n",
345 | "val_acc=history.history['val_accuracy']\n",
346 | "loss=history.history['loss']\n",
347 | "val_loss=history.history['val_loss']\n",
348 | "\n",
349 | "epochs=range(len(acc)) # Get number of epochs\n",
350 | "\n",
351 | "#------------------------------------------------\n",
352 | "# Plot training and validation accuracy per epoch\n",
353 | "#------------------------------------------------\n",
354 | "plt.plot(epochs, acc, 'r')\n",
355 | "plt.plot(epochs, val_acc, 'b')\n",
356 | "plt.title('Training and validation accuracy')\n",
357 | "plt.xlabel(\"Epochs\")\n",
358 | "plt.ylabel(\"Accuracy\")\n",
359 | "plt.legend([\"Accuracy\", \"Validation Accuracy\"])\n",
360 | "\n",
361 | "plt.figure()\n",
362 | "\n",
363 | "#------------------------------------------------\n",
364 | "# Plot training and validation loss per epoch\n",
365 | "#------------------------------------------------\n",
366 | "plt.plot(epochs, loss, 'r')\n",
367 | "plt.plot(epochs, val_loss, 'b')\n",
368 | "plt.title('Training and validation loss')\n",
369 | "plt.xlabel(\"Epochs\")\n",
370 | "plt.ylabel(\"Loss\")\n",
371 | "plt.legend([\"Loss\", \"Validation Loss\"])\n",
372 | "\n",
373 | "plt.figure()\n",
374 | "\n",
375 | "\n",
376 | "# Expected Output\n",
377 | "# A chart where the validation loss does not increase sharply!"
378 | ]
379 | }
380 | ],
381 | "metadata": {
382 | "accelerator": "GPU",
383 | "colab": {
384 | "name": "NLP Course - Week 3 Exercise Answer.ipynb",
385 | "provenance": [],
386 | "toc_visible": true
387 | },
388 | "kernelspec": {
389 | "display_name": "Python 3",
390 | "language": "python",
391 | "name": "python3"
392 | },
393 | "language_info": {
394 | "codemirror_mode": {
395 | "name": "ipython",
396 | "version": 3
397 | },
398 | "file_extension": ".py",
399 | "mimetype": "text/x-python",
400 | "name": "python",
401 | "nbconvert_exporter": "python",
402 | "pygments_lexer": "ipython3",
403 | "version": "3.7.3"
404 | }
405 | },
406 | "nbformat": 4,
407 | "nbformat_minor": 1
408 | }
409 |
--------------------------------------------------------------------------------
/Course 3 - NLP in Tensorflow/meta.tsv:
--------------------------------------------------------------------------------
1 |
2 | s
3 | said
4 | will
5 | not
6 | mr
7 | year
8 | also
9 | people
10 | new
11 | us
12 | one
13 | can
14 | last
15 | t
16 | first
17 | time
18 | two
19 | government
20 | world
21 | now
22 | uk
23 | best
24 | years
25 | no
26 | make
27 | just
28 | film
29 | told
30 | made
31 | get
32 | music
33 | game
34 | like
35 | back
36 | many
37 | 000
38 | labour
39 | three
40 | well
41 | 1
42 | next
43 | bbc
44 | take
45 | set
46 | number
47 | added
48 | way
49 | market
50 | 2
51 | company
52 | may
53 | says
54 | election
55 | home
56 | off
57 | party
58 | good
59 | going
60 | much
61 | work
62 | 2004
63 | still
64 | win
65 | show
66 | think
67 | games
68 | go
69 | top
70 | second
71 | won
72 | million
73 | 6
74 | england
75 | firm
76 | since
77 | week
78 | say
79 | play
80 | part
81 | public
82 | use
83 | blair
84 | 3
85 | want
86 | minister
87 | however
88 | 10
89 | country
90 | technology
91 | see
92 | 4
93 | five
94 | british
95 | news
96 | european
97 | high
98 | group
99 | tv
100 | used
101 | end
102 | expected
103 | even
104 | players
105 | m
106 | brown
107 | 5
108 | six
109 | old
110 | net
111 | already
112 | four
113 | plans
114 | put
115 | come
116 | half
117 | london
118 | sales
119 | growth
120 | don
121 | long
122 | economy
123 | service
124 | right
125 | months
126 | chief
127 | day
128 | mobile
129 | former
130 | money
131 | britain
132 | director
133 | tax
134 | services
135 | 2005
136 | deal
137 | need
138 | help
139 | digital
140 | according
141 | big
142 | industry
143 | place
144 | companies
145 | users
146 | system
147 | business
148 | including
149 | team
150 | final
151 | based
152 | hit
153 | record
154 | report
155 | third
156 | called
157 | really
158 | international
159 | month
160 | move
161 | wales
162 | europe
163 | another
164 | 7
165 | life
166 | around
167 | economic
168 | start
169 | great
170 | future
171 | 2003
172 | firms
173 | came
174 | france
175 | open
176 | got
177 | spokesman
178 | software
179 | re
180 | without
181 | general
182 | club
183 | took
184 | up
185 | ireland
186 | video
187 | howard
188 | know
189 | united
190 | online
191 | bank
192 | phone
193 | china
194 | far
195 | state
196 | campaign
197 | side
198 | law
199 | radio
200 | better
201 | court
202 | making
203 | decision
204 | executive
205 | real
206 | media
207 | offer
208 | give
209 | computer
210 | found
211 | action
212 | able
213 | president
214 | information
215 | despite
216 | office
217 | star
218 | lot
219 | o
220 | national
221 | line
222 | countries
223 | likely
224 | using
225 | away
226 | player
227 | internet
228 | saying
229 | it
230 | every
231 | given
232 | security
233 | become
234 | left
235 | awards
236 | figures
237 | anti
238 | nations
239 | run
240 | eu
241 | 20
242 | cost
243 | ve
244 | prime
245 | role
246 | seen
247 | playing
248 | biggest
249 | man
250 | january
251 | data
252 | bill
253 | whether
254 | played
255 | later
256 | foreign
257 | although
258 | cup
259 | hard
260 | award
261 | rise
262 | broadband
263 | times
264 | match
265 | chancellor
266 | oil
267 | pay
268 | lost
269 | taking
270 | house
271 | due
272 | past
273 | interest
274 | early
275 | never
276 | lord
277 | leader
278 | support
279 | case
280 | prices
281 | look
282 | microsoft
283 | shares
284 | michael
285 | legal
286 | analysts
287 | control
288 | believe
289 | december
290 | less
291 | days
292 | cut
293 | recent
294 | season
295 | little
296 | children
297 | e
298 | ahead
299 | earlier
300 | increase
301 | thought
302 | free
303 | john
304 | face
305 | research
306 | scotland
307 | important
308 | something
309 | current
310 | strong
311 | went
312 | issue
313 | secretary
314 | south
315 | local
316 | tory
317 | rights
318 | working
319 | power
320 | budget
321 | financial
322 | spending
323 | 12
324 | quarter
325 | access
326 | currently
327 | held
328 | major
329 | chance
330 | change
331 | trade
332 | films
333 | find
334 | looking
335 | try
336 | following
337 | sunday
338 | 0
339 | full
340 | tories
341 | yet
342 | return
343 | series
344 | latest
345 | meeting
346 | share
347 | different
348 | website
349 | david
350 | winning
351 | almost
352 | injury
353 | sale
354 | must
355 | lead
356 | enough
357 | personal
358 | programme
359 | might
360 | police
361 | low
362 | band
363 | problems
364 | ever
365 | keep
366 | rate
367 | announced
368 | always
369 | key
370 | coach
371 | williams
372 | sold
373 | across
374 | performance
375 | dollar
376 | 11
377 | among
378 | behind
379 | ago
380 | list
381 | 8
382 | 9
383 | clear
384 | getting
385 | political
386 | victory
387 | 25
388 | mark
389 | chairman
390 | include
391 | women
392 | demand
393 | 30
394 | statement
395 | ms
396 | march
397 | february
398 | things
399 | term
400 | rather
401 | jobs
402 | minutes
403 | tuesday
404 | american
405 | chelsea
406 | claims
407 | done
408 | content
409 | continue
410 | point
411 | job
412 | manager
413 | means
414 | head
415 | problem
416 | title
417 | actor
418 | coming
419 | huge
420 | price
421 | asked
422 | released
423 | taken
424 | mail
425 | men
426 | union
427 | members
428 | india
429 | allow
430 | weeks
431 | wednesday
432 | act
433 | japan
434 | rugby
435 | plan
436 | tony
437 | global
438 | investment
439 | least
440 | result
441 | apple
442 | 50
443 | young
444 | network
445 | today
446 | within
447 | costs
448 | fans
449 | forward
450 | d
451 | bid
452 | main
453 | french
454 | possible
455 | production
456 | needed
457 | running
458 | site
459 | beat
460 | november
461 | 18
462 | small
463 | war
464 | council
465 | consumer
466 | available
467 | saturday
468 | form
469 | warned
470 | thing
471 | monday
472 | cash
473 | vote
474 | hold
475 | several
476 | known
477 | wanted
478 | mps
479 | song
480 | pc
481 | issues
482 | total
483 | committee
484 | friday
485 | 15
486 | level
487 | live
488 | football
489 | though
490 | evidence
491 | policy
492 | prize
493 | version
494 | success
495 | led
496 | league
497 | search
498 | trying
499 | 2001
500 | human
501 | calls
502 | previous
503 | buy
504 | sir
505 | recently
506 | saw
507 | web
508 | sony
509 | rates
510 | family
511 | parties
512 | aid
513 | single
514 | album
515 | centre
516 | eight
517 | name
518 | customers
519 | rules
520 | meet
521 | close
522 | development
523 | ministers
524 | others
525 | thursday
526 | health
527 | book
528 | competition
529 | stock
530 | agreed
531 | call
532 | phones
533 | 100
534 | difficult
535 | short
536 | let
537 | race
538 | yukos
539 | consumers
540 | popular
541 | comes
542 | co
543 | fact
544 | charles
545 | event
546 | hope
547 | failed
548 | fourth
549 | higher
550 | showed
551 | networks
552 | debt
553 | board
554 | actress
555 | commission
556 | trial
557 | city
558 | wants
559 | october
560 | italy
561 | choice
562 | york
563 | lib
564 | reported
565 | feel
566 | nothing
567 | conference
568 | project
569 | career
570 | bt
571 | sites
572 | boss
573 | didn
574 | points
575 | liberal
576 | late
577 | sure
578 | liverpool
579 | festival
580 | reports
581 | black
582 | received
583 | cannot
584 | annual
585 | together
586 | instead
587 | claim
588 | shows
589 | gaming
590 | tour
591 | dvd
592 | break
593 | launch
594 | claimed
595 | paid
596 | mean
597 | on
598 | devices
599 | christmas
600 | jones
601 | movie
602 | boost
603 | goal
604 | virus
605 | growing
606 | stage
607 | release
608 | age
609 | largest
610 | september
611 | large
612 | leading
613 | summer
614 | champion
615 | 2002
616 | involved
617 | position
618 | arsenal
619 | west
620 | denied
621 | changes
622 | russian
623 | out
624 | believes
625 | manchester
626 | profits
627 | to
628 | paul
629 | singer
630 | iraq
631 | in
632 | needs
633 | fall
634 | television
635 | products
636 | idea
637 | stop
638 | them
639 | gordon
640 | parliament
641 | 17
642 | australian
643 | pressure
644 | sport
645 | love
646 | germany
647 | africa
648 | started
649 | create
650 | order
651 | scottish
652 | talks
653 | giant
654 | potential
655 | 13
656 | german
657 | test
658 | pre
659 | weekend
660 | 16
661 | quite
662 | round
663 | opening
664 | whole
665 | squad
666 | martin
667 | association
668 | special
669 | senior
670 | launched
671 | box
672 | chart
673 | oscar
674 | seven
675 | street
676 | rose
677 | value
678 | conservative
679 | sent
680 | stars
681 | ball
682 | car
683 | v
684 | anything
685 | grand
686 | groups
687 | hours
688 | accused
689 | 40
690 | stand
691 | remain
692 | 2000
693 | cards
694 | either
695 | hopes
696 | ensure
697 | olympic
698 | simply
699 | robinson
700 | fight
701 | similar
702 | press
703 | smith
704 | range
705 | irish
706 | drive
707 | 2006
708 | exchange
709 | rock
710 | official
711 | 24
712 | 14
713 | results
714 | bit
715 | appeal
716 | turn
717 | dr
718 | provide
719 | ukip
720 | immigration
721 | that
722 | period
723 | makes
724 | target
725 | helped
726 | investors
727 | standard
728 | wrong
729 | sell
730 | attack
731 | commons
732 | fell
733 | independent
734 | tsunami
735 | particularly
736 | meanwhile
737 | comedy
738 | proposals
739 | education
740 | average
741 | energy
742 | lords
743 | ban
744 | gave
745 | impact
746 | via
747 | moment
748 | compared
749 | school
750 | happy
751 | card
752 | forced
753 | ll
754 | charge
755 | attacks
756 | spam
757 | generation
758 | force
759 | brought
760 | amount
761 | private
762 | community
763 | sector
764 | per
765 | bring
766 | fraud
767 | became
768 | fund
769 | euros
770 | extra
771 | systems
772 | everyone
773 | speech
774 | admitted
775 | poll
776 | history
777 | message
778 | numbers
779 | included
780 | widely
781 | gadget
782 | entertainment
783 | windows
784 | debate
785 | speaking
786 | selling
787 | hand
788 | bad
789 | department
790 | laws
791 | workers
792 | date
793 | australia
794 | charges
795 | markets
796 | night
797 | audience
798 | named
799 | russia
800 | comments
801 | soon
802 | worked
803 | staff
804 | agency
805 | view
806 | turned
807 | kilroy
808 | mike
809 | front
810 | member
811 | shot
812 | bush
813 | revealed
814 | areas
815 | download
816 | takes
817 | speed
818 | screen
819 | increased
820 | opposition
821 | university
822 | battle
823 | civil
824 | kennedy
825 | spend
826 | air
827 | finance
828 | newspaper
829 | him
830 | opportunity
831 | concerns
832 | shown
833 | survey
834 | area
835 | cross
836 | white
837 | gone
838 | voters
839 | course
840 | original
841 | millions
842 | bought
843 | offered
844 | £1
845 | poor
846 | alan
847 | followed
848 | east
849 | concerned
850 | leave
851 | often
852 | decided
853 | insisted
854 | authorities
855 | outside
856 | b
857 | favourite
858 | terms
859 | defence
860 | step
861 | all
862 | whose
863 | june
864 | story
865 | reached
866 | analyst
867 | lives
868 | created
869 | designed
870 | mini
871 | process
872 | non
873 | risk
874 | 22
875 | america
876 | body
877 | quality
878 | easy
879 | spent
880 | cuts
881 | becoming
882 | remains
883 | unit
884 | majority
885 | raise
886 | pop
887 | attempt
888 | musical
889 | r
890 | drugs
891 | hollywood
892 | challenge
893 | experience
894 | example
895 | 19
896 | debut
897 | nominated
898 | states
899 | reach
900 | credit
901 | messages
902 | levels
903 | winner
904 | ray
905 | robert
906 | silk
907 | watch
908 | andy
909 | situation
910 | focus
911 | taxes
912 | euro
913 | songs
914 | organisation
915 | build
916 | everything
917 | believed
918 | april
919 | tough
920 | central
921 | anyone
922 | signed
923 | j
924 | pcs
925 | captain
926 | rival
927 | device
928 | indian
929 | confirmed
930 | james
931 | so
932 | titles
933 | businesses
934 | post
935 | technologies
936 | critics
937 | matter
938 | previously
939 | trading
940 | rest
941 | met
942 | began
943 | longer
944 | officials
945 | response
946 | probably
947 | nine
948 | hour
949 | row
950 | minute
951 | light
952 | cases
953 | magazine
954 | building
955 | worth
956 | account
957 | voice
958 | programs
959 | ask
960 | looked
961 | mp
962 | davis
963 | aviator
964 | threat
965 | trust
966 | confidence
967 | looks
968 | g
969 | chinese
970 | machine
971 | gold
972 | category
973 | computers
974 | premiership
975 | host
976 | measures
977 | fast
978 | person
979 | ruled
980 | towards
981 | artists
982 | double
983 | training
984 | missed
985 | felt
986 | care
987 | agreement
988 | allowed
989 | madrid
990 | scheme
991 | zealand
992 | fear
993 | theatre
994 | portable
995 | newcastle
996 | north
997 | serious
998 | spain
999 | management
1000 |
--------------------------------------------------------------------------------
/Course 4 - Sequences, Time Series & Prediction/Week 1 Quiz | Coursera.webarchive:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chrismartinis/tensorflow_developer_professional_certificate/e81bdc75b3b3cbd46911ca816445fa07061dcb7a/Course 4 - Sequences, Time Series & Prediction/Week 1 Quiz | Coursera.webarchive
--------------------------------------------------------------------------------
/Course 4 - Sequences, Time Series & Prediction/Week 3 Quiz | Coursera.webarchive:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chrismartinis/tensorflow_developer_professional_certificate/e81bdc75b3b3cbd46911ca816445fa07061dcb7a/Course 4 - Sequences, Time Series & Prediction/Week 3 Quiz | Coursera.webarchive
--------------------------------------------------------------------------------
/Course 4 - Sequences, Time Series & Prediction/Week 4 Quiz | Coursera.webarchive:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chrismartinis/tensorflow_developer_professional_certificate/e81bdc75b3b3cbd46911ca816445fa07061dcb7a/Course 4 - Sequences, Time Series & Prediction/Week 4 Quiz | Coursera.webarchive
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Chris Martinis & Deeplearning.ai
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TensorFlow Developer Professional Certificate
2 |
3 |
4 | The TensorFlow Developer Professional Certificate was the second specialization I took from Deeplearning.ai. In this course, Laurence Moroney and Andrew NG deliver a solid collection of lectures and labs, which not only helped me build upon the knowledge acquired through the Deep Learning specialization, but also allowed me to gain a deeper understanding of TensorFlow's powerful features. Again, well done!
5 |
6 | Check out the course details __[here](https://www.coursera.org/professional-certificates/tensorflow-in-practice)__.
7 |
8 | ## About the Specialization
9 | TensorFlow is one of the most in-demand and popular open-source deep learning frameworks available today. The DeepLearning.AI TensorFlow Developer Professional Certificate program teaches you applied machine learning skills with TensorFlow so you can build and train powerful models.
10 |
11 | In this hands-on, four-course Professional Certificate program, you’ll learn the necessary tools to build scalable AI-powered applications with TensorFlow. After finishing this program, you’ll be able to apply your new TensorFlow skills to a wide range of problems and projects. This program can help you prepare for the Google TensorFlow Certificate exam and bring you one step closer to achieving the Google TensorFlow Certificate.
12 |
13 | In the DeepLearning.AI TensorFlow Developer Professional Certificate program, you'll get hands-on experience through 16 Python programming assignments. By the end of this program, you will be ready to:
14 |
15 | - Build and train neural networks using TensorFlow
16 |
17 | - Improve your network’s performance using convolutions as you train it to identify real-world images
18 |
19 | - Teach machines to understand, analyze, and respond to human speech with natural language processing systems
20 |
21 | - Process text, represent sentences as vectors, and train a model to create original poetry!
22 |
23 | ## Course 1 - Introduction to TensorFlow for Artificial Intelligence, Machine Learning, and Deep Learning
24 |
25 | If you are a software developer who wants to build scalable AI-powered algorithms, you need to understand how to use the tools to build them. This course is part of the upcoming Machine Learning in Tensorflow Specialization and will teach you best practices for using TensorFlow, a popular open-source framework for machine learning.
26 |
27 | The Machine Learning course and Deep Learning Specialization from Andrew Ng teach the most important and foundational principles of Machine Learning and Deep Learning. This new deeplearning.ai TensorFlow Specialization teaches you how to use TensorFlow to implement those principles so that you can start building and applying scalable models to real-world problems. To develop a deeper understanding of how neural networks work, we recommend that you take the Deep Learning Specialization.
28 |
29 | ## Course 2 - Convolutional Neural Networks in TensorFlow
30 |
31 | In Course 2 of the deeplearning.ai TensorFlow Specialization, you will learn advanced techniques to improve the computer vision model you built in Course 1. You will explore how to work with real-world images in different shapes and sizes, visualize the journey of an image through convolutions to understand how a computer “sees” information, plot loss and accuracy, and explore strategies to prevent overfitting, including augmentation and dropout. Finally, Course 2 will introduce you to transfer learning and how learned features can be extracted from models. The Machine Learning course and Deep Learning Specialization from Andrew Ng teach the most important and foundational principles of Machine Learning and Deep Learning. This new deeplearning.ai TensorFlow Specialization teaches you how to use TensorFlow to implement those principles so that you can start building and applying scalable models to real-world problems. To develop a deeper understanding of how neural networks work, we recommend that you take the Deep Learning Specialization.
32 |
33 | ## Course 3 - Natural Language Processing in TensorFlow
34 |
35 | In Course 3 of the deeplearning.ai TensorFlow Specialization, you will build natural language processing systems using TensorFlow. You will learn to process text, including tokenizing and representing sentences as vectors, so that they can be input to a neural network. You’ll also learn to apply RNNs, GRUs, and LSTMs in TensorFlow. Finally, you’ll get to train an LSTM on existing text to create original poetry! The Machine Learning course and Deep Learning Specialization from Andrew Ng teach the most important and foundational principles of Machine Learning and Deep Learning. This new deeplearning.ai TensorFlow Specialization teaches you how to use TensorFlow to implement those principles so that you can start building and applying scalable models to real-world problems. To develop a deeper understanding of how neural networks work, we recommend that you take the Deep Learning Specialization.
36 |
37 | ## Course 4 - Sequences, Time Series and Prediction
38 |
39 | In this fourth course, you will learn how to build time series models in TensorFlow. You’ll first implement best practices to prepare time series data. You’ll also explore how RNNs and 1D ConvNets can be used for prediction. Finally, you’ll apply everything you’ve learned throughout the Specialization to build a sunspot prediction model using real-world data! The Machine Learning course and Deep Learning Specialization from Andrew Ng teach the most important and foundational principles of Machine Learning and Deep Learning. This new deeplearning.ai TensorFlow Specialization teaches you how to use TensorFlow to implement those principles so that you can start building and applying scalable models to real-world problems. To develop a deeper understanding of how neural networks work, we recommend that you take the Deep Learning Specialization.
40 |
41 | __Note: to view the .webarchive files, please download them to your computer.__
42 |
43 | ## License
44 | __[MIT](https://github.com/chrismartinis/tensorflow_developer_professional_certificate/blob/master/LICENSE)__
45 |
--------------------------------------------------------------------------------