thegeek13242 commited on
Commit
b2898f0
1 Parent(s): 688a87a
Files changed (7) hide show
  1. .gitignore +2 -0
  2. airline_sentiment_analysis.csv +0 -0
  3. api.py +8 -0
  4. infer.py +29 -0
  5. requirements.txt +7 -0
  6. train.ipynb +1154 -0
  7. weights.h5 +3 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ venv
2
+ /__pycache__/
airline_sentiment_analysis.csv ADDED
The diff for this file is too large to render. See raw diff
 
api.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ import infer
3
+
4
+ app = FastAPI()
5
+
6
+ @app.post("/predict")
7
+ async def predict(text: str):
8
+ return {"prediction": infer.predict(text)}
infer.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import emoji
3
+ import tensorflow as tf
4
+ from transformers import BertTokenizer,TFBertForSequenceClassification
5
+
6
+ model = TFBertForSequenceClassification.from_pretrained('bert-base-uncased')
7
+ model.load_weights('weights.h5')
8
+ tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
9
+
10
+ def preprocess(text):
11
+ text = emoji.demojize(text)
12
+ text = text.replace(":"," ")
13
+ text = ' '.join(text.split())
14
+ text = re.sub("@[A-Za-z0-9]+", "", text)
15
+ text = re.sub("#", "", text)
16
+ text = re.sub("https?://[A-Za-z0-9./]+", "", text)
17
+ text = re.sub("[^a-zA-Z.!?']", " ", text)
18
+ return text
19
+
20
+ def predict(text):
21
+ text = preprocess(text)
22
+ tf_batch = tokenizer([text], max_length=128, padding=True, truncation=True, return_tensors='tf')
23
+ tf_outputs = model(tf_batch)
24
+ tf_predictions = tf.nn.softmax(tf_outputs[0], axis=-1)
25
+ labels = ['Negative','Positive']
26
+ label = tf.argmax(tf_predictions, axis=1)
27
+ label = label.numpy()
28
+ return labels[label[0]]
29
+
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ tensorflow-gpu<2.11
2
+ transformers
3
+ emoji
4
+ numpy
5
+ pandas
6
+ scikit-learn
7
+ fast-api
train.ipynb ADDED
@@ -0,0 +1,1154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {
7
+ "id": "nwuC7017BwyD"
8
+ },
9
+ "outputs": [],
10
+ "source": [
11
+ "%pip install \"tensorflow-gpu<2.11\"\n",
12
+ "%pip install transformers\n",
13
+ "%pip install emoji\n",
14
+ "%pip install numpy pandas\n",
15
+ "%pip install scikit-learn"
16
+ ]
17
+ },
18
+ {
19
+ "cell_type": "code",
20
+ "execution_count": 2,
21
+ "metadata": {
22
+ "id": "iM2I9UEjm_pE"
23
+ },
24
+ "outputs": [],
25
+ "source": [
26
+ "import numpy as np\n",
27
+ "import pandas as pd"
28
+ ]
29
+ },
30
+ {
31
+ "cell_type": "code",
32
+ "execution_count": 3,
33
+ "metadata": {
34
+ "colab": {
35
+ "base_uri": "https://localhost:8080/",
36
+ "height": 676
37
+ },
38
+ "id": "mrnzcvkzm_pF",
39
+ "outputId": "fca854f8-422f-4868-e0c8-2c8abf4671f5"
40
+ },
41
+ "outputs": [
42
+ {
43
+ "data": {
44
+ "text/html": [
45
+ "<div>\n",
46
+ "<style scoped>\n",
47
+ " .dataframe tbody tr th:only-of-type {\n",
48
+ " vertical-align: middle;\n",
49
+ " }\n",
50
+ "\n",
51
+ " .dataframe tbody tr th {\n",
52
+ " vertical-align: top;\n",
53
+ " }\n",
54
+ "\n",
55
+ " .dataframe thead th {\n",
56
+ " text-align: right;\n",
57
+ " }\n",
58
+ "</style>\n",
59
+ "<table border=\"1\" class=\"dataframe\">\n",
60
+ " <thead>\n",
61
+ " <tr style=\"text-align: right;\">\n",
62
+ " <th></th>\n",
63
+ " <th>Unnamed: 0</th>\n",
64
+ " <th>airline_sentiment</th>\n",
65
+ " <th>text</th>\n",
66
+ " </tr>\n",
67
+ " </thead>\n",
68
+ " <tbody>\n",
69
+ " <tr>\n",
70
+ " <th>0</th>\n",
71
+ " <td>1</td>\n",
72
+ " <td>positive</td>\n",
73
+ " <td>@VirginAmerica plus you've added commercials t...</td>\n",
74
+ " </tr>\n",
75
+ " <tr>\n",
76
+ " <th>1</th>\n",
77
+ " <td>3</td>\n",
78
+ " <td>negative</td>\n",
79
+ " <td>@VirginAmerica it's really aggressive to blast...</td>\n",
80
+ " </tr>\n",
81
+ " <tr>\n",
82
+ " <th>2</th>\n",
83
+ " <td>4</td>\n",
84
+ " <td>negative</td>\n",
85
+ " <td>@VirginAmerica and it's a really big bad thing...</td>\n",
86
+ " </tr>\n",
87
+ " <tr>\n",
88
+ " <th>3</th>\n",
89
+ " <td>5</td>\n",
90
+ " <td>negative</td>\n",
91
+ " <td>@VirginAmerica seriously would pay $30 a fligh...</td>\n",
92
+ " </tr>\n",
93
+ " <tr>\n",
94
+ " <th>4</th>\n",
95
+ " <td>6</td>\n",
96
+ " <td>positive</td>\n",
97
+ " <td>@VirginAmerica yes, nearly every time I fly VX...</td>\n",
98
+ " </tr>\n",
99
+ " <tr>\n",
100
+ " <th>5</th>\n",
101
+ " <td>8</td>\n",
102
+ " <td>positive</td>\n",
103
+ " <td>@virginamerica Well, I didn't…but NOW I DO! :-D</td>\n",
104
+ " </tr>\n",
105
+ " <tr>\n",
106
+ " <th>6</th>\n",
107
+ " <td>9</td>\n",
108
+ " <td>positive</td>\n",
109
+ " <td>@VirginAmerica it was amazing, and arrived an ...</td>\n",
110
+ " </tr>\n",
111
+ " <tr>\n",
112
+ " <th>7</th>\n",
113
+ " <td>11</td>\n",
114
+ " <td>positive</td>\n",
115
+ " <td>@VirginAmerica I &amp;lt;3 pretty graphics. so muc...</td>\n",
116
+ " </tr>\n",
117
+ " <tr>\n",
118
+ " <th>8</th>\n",
119
+ " <td>12</td>\n",
120
+ " <td>positive</td>\n",
121
+ " <td>@VirginAmerica This is such a great deal! Alre...</td>\n",
122
+ " </tr>\n",
123
+ " <tr>\n",
124
+ " <th>9</th>\n",
125
+ " <td>13</td>\n",
126
+ " <td>positive</td>\n",
127
+ " <td>@VirginAmerica @virginmedia I'm flying your #f...</td>\n",
128
+ " </tr>\n",
129
+ " <tr>\n",
130
+ " <th>10</th>\n",
131
+ " <td>14</td>\n",
132
+ " <td>positive</td>\n",
133
+ " <td>@VirginAmerica Thanks!</td>\n",
134
+ " </tr>\n",
135
+ " <tr>\n",
136
+ " <th>11</th>\n",
137
+ " <td>15</td>\n",
138
+ " <td>negative</td>\n",
139
+ " <td>@VirginAmerica SFO-PDX schedule is still MIA.</td>\n",
140
+ " </tr>\n",
141
+ " <tr>\n",
142
+ " <th>12</th>\n",
143
+ " <td>16</td>\n",
144
+ " <td>positive</td>\n",
145
+ " <td>@VirginAmerica So excited for my first cross c...</td>\n",
146
+ " </tr>\n",
147
+ " <tr>\n",
148
+ " <th>13</th>\n",
149
+ " <td>17</td>\n",
150
+ " <td>negative</td>\n",
151
+ " <td>@VirginAmerica I flew from NYC to SFO last we...</td>\n",
152
+ " </tr>\n",
153
+ " <tr>\n",
154
+ " <th>14</th>\n",
155
+ " <td>18</td>\n",
156
+ " <td>positive</td>\n",
157
+ " <td>I ❤️ flying @VirginAmerica. ☺️👍</td>\n",
158
+ " </tr>\n",
159
+ " <tr>\n",
160
+ " <th>15</th>\n",
161
+ " <td>19</td>\n",
162
+ " <td>positive</td>\n",
163
+ " <td>@VirginAmerica you know what would be amazingl...</td>\n",
164
+ " </tr>\n",
165
+ " <tr>\n",
166
+ " <th>16</th>\n",
167
+ " <td>20</td>\n",
168
+ " <td>negative</td>\n",
169
+ " <td>@VirginAmerica why are your first fares in May...</td>\n",
170
+ " </tr>\n",
171
+ " <tr>\n",
172
+ " <th>17</th>\n",
173
+ " <td>21</td>\n",
174
+ " <td>positive</td>\n",
175
+ " <td>@VirginAmerica I love this graphic. http://t.c...</td>\n",
176
+ " </tr>\n",
177
+ " <tr>\n",
178
+ " <th>18</th>\n",
179
+ " <td>22</td>\n",
180
+ " <td>positive</td>\n",
181
+ " <td>@VirginAmerica I love the hipster innovation. ...</td>\n",
182
+ " </tr>\n",
183
+ " <tr>\n",
184
+ " <th>19</th>\n",
185
+ " <td>24</td>\n",
186
+ " <td>negative</td>\n",
187
+ " <td>@VirginAmerica you guys messed up my seating.....</td>\n",
188
+ " </tr>\n",
189
+ " </tbody>\n",
190
+ "</table>\n",
191
+ "</div>"
192
+ ],
193
+ "text/plain": [
194
+ " Unnamed: 0 airline_sentiment \\\n",
195
+ "0 1 positive \n",
196
+ "1 3 negative \n",
197
+ "2 4 negative \n",
198
+ "3 5 negative \n",
199
+ "4 6 positive \n",
200
+ "5 8 positive \n",
201
+ "6 9 positive \n",
202
+ "7 11 positive \n",
203
+ "8 12 positive \n",
204
+ "9 13 positive \n",
205
+ "10 14 positive \n",
206
+ "11 15 negative \n",
207
+ "12 16 positive \n",
208
+ "13 17 negative \n",
209
+ "14 18 positive \n",
210
+ "15 19 positive \n",
211
+ "16 20 negative \n",
212
+ "17 21 positive \n",
213
+ "18 22 positive \n",
214
+ "19 24 negative \n",
215
+ "\n",
216
+ " text \n",
217
+ "0 @VirginAmerica plus you've added commercials t... \n",
218
+ "1 @VirginAmerica it's really aggressive to blast... \n",
219
+ "2 @VirginAmerica and it's a really big bad thing... \n",
220
+ "3 @VirginAmerica seriously would pay $30 a fligh... \n",
221
+ "4 @VirginAmerica yes, nearly every time I fly VX... \n",
222
+ "5 @virginamerica Well, I didn't…but NOW I DO! :-D \n",
223
+ "6 @VirginAmerica it was amazing, and arrived an ... \n",
224
+ "7 @VirginAmerica I &lt;3 pretty graphics. so muc... \n",
225
+ "8 @VirginAmerica This is such a great deal! Alre... \n",
226
+ "9 @VirginAmerica @virginmedia I'm flying your #f... \n",
227
+ "10 @VirginAmerica Thanks! \n",
228
+ "11 @VirginAmerica SFO-PDX schedule is still MIA. \n",
229
+ "12 @VirginAmerica So excited for my first cross c... \n",
230
+ "13 @VirginAmerica I flew from NYC to SFO last we... \n",
231
+ "14 I ❤️ flying @VirginAmerica. ☺️👍 \n",
232
+ "15 @VirginAmerica you know what would be amazingl... \n",
233
+ "16 @VirginAmerica why are your first fares in May... \n",
234
+ "17 @VirginAmerica I love this graphic. http://t.c... \n",
235
+ "18 @VirginAmerica I love the hipster innovation. ... \n",
236
+ "19 @VirginAmerica you guys messed up my seating..... "
237
+ ]
238
+ },
239
+ "execution_count": 3,
240
+ "metadata": {},
241
+ "output_type": "execute_result"
242
+ }
243
+ ],
244
+ "source": [
245
+ "df = pd.read_csv(\"airline_sentiment_analysis.csv\")\n",
246
+ "df.head(20)\n"
247
+ ]
248
+ },
249
+ {
250
+ "cell_type": "code",
251
+ "execution_count": 4,
252
+ "metadata": {
253
+ "colab": {
254
+ "base_uri": "https://localhost:8080/",
255
+ "height": 676
256
+ },
257
+ "id": "Jbl-wjpWm_pG",
258
+ "outputId": "0bf3597e-5645-4c37-a993-dc3c3eb57db4"
259
+ },
260
+ "outputs": [
261
+ {
262
+ "data": {
263
+ "text/html": [
264
+ "<div>\n",
265
+ "<style scoped>\n",
266
+ " .dataframe tbody tr th:only-of-type {\n",
267
+ " vertical-align: middle;\n",
268
+ " }\n",
269
+ "\n",
270
+ " .dataframe tbody tr th {\n",
271
+ " vertical-align: top;\n",
272
+ " }\n",
273
+ "\n",
274
+ " .dataframe thead th {\n",
275
+ " text-align: right;\n",
276
+ " }\n",
277
+ "</style>\n",
278
+ "<table border=\"1\" class=\"dataframe\">\n",
279
+ " <thead>\n",
280
+ " <tr style=\"text-align: right;\">\n",
281
+ " <th></th>\n",
282
+ " <th>Unnamed: 0</th>\n",
283
+ " <th>airline_sentiment</th>\n",
284
+ " <th>text</th>\n",
285
+ " </tr>\n",
286
+ " </thead>\n",
287
+ " <tbody>\n",
288
+ " <tr>\n",
289
+ " <th>0</th>\n",
290
+ " <td>1</td>\n",
291
+ " <td>1</td>\n",
292
+ " <td>@VirginAmerica plus you've added commercials t...</td>\n",
293
+ " </tr>\n",
294
+ " <tr>\n",
295
+ " <th>1</th>\n",
296
+ " <td>3</td>\n",
297
+ " <td>0</td>\n",
298
+ " <td>@VirginAmerica it's really aggressive to blast...</td>\n",
299
+ " </tr>\n",
300
+ " <tr>\n",
301
+ " <th>2</th>\n",
302
+ " <td>4</td>\n",
303
+ " <td>0</td>\n",
304
+ " <td>@VirginAmerica and it's a really big bad thing...</td>\n",
305
+ " </tr>\n",
306
+ " <tr>\n",
307
+ " <th>3</th>\n",
308
+ " <td>5</td>\n",
309
+ " <td>0</td>\n",
310
+ " <td>@VirginAmerica seriously would pay $30 a fligh...</td>\n",
311
+ " </tr>\n",
312
+ " <tr>\n",
313
+ " <th>4</th>\n",
314
+ " <td>6</td>\n",
315
+ " <td>1</td>\n",
316
+ " <td>@VirginAmerica yes, nearly every time I fly VX...</td>\n",
317
+ " </tr>\n",
318
+ " <tr>\n",
319
+ " <th>5</th>\n",
320
+ " <td>8</td>\n",
321
+ " <td>1</td>\n",
322
+ " <td>@virginamerica Well, I didn't…but NOW I DO! :-D</td>\n",
323
+ " </tr>\n",
324
+ " <tr>\n",
325
+ " <th>6</th>\n",
326
+ " <td>9</td>\n",
327
+ " <td>1</td>\n",
328
+ " <td>@VirginAmerica it was amazing, and arrived an ...</td>\n",
329
+ " </tr>\n",
330
+ " <tr>\n",
331
+ " <th>7</th>\n",
332
+ " <td>11</td>\n",
333
+ " <td>1</td>\n",
334
+ " <td>@VirginAmerica I &amp;lt;3 pretty graphics. so muc...</td>\n",
335
+ " </tr>\n",
336
+ " <tr>\n",
337
+ " <th>8</th>\n",
338
+ " <td>12</td>\n",
339
+ " <td>1</td>\n",
340
+ " <td>@VirginAmerica This is such a great deal! Alre...</td>\n",
341
+ " </tr>\n",
342
+ " <tr>\n",
343
+ " <th>9</th>\n",
344
+ " <td>13</td>\n",
345
+ " <td>1</td>\n",
346
+ " <td>@VirginAmerica @virginmedia I'm flying your #f...</td>\n",
347
+ " </tr>\n",
348
+ " <tr>\n",
349
+ " <th>10</th>\n",
350
+ " <td>14</td>\n",
351
+ " <td>1</td>\n",
352
+ " <td>@VirginAmerica Thanks!</td>\n",
353
+ " </tr>\n",
354
+ " <tr>\n",
355
+ " <th>11</th>\n",
356
+ " <td>15</td>\n",
357
+ " <td>0</td>\n",
358
+ " <td>@VirginAmerica SFO-PDX schedule is still MIA.</td>\n",
359
+ " </tr>\n",
360
+ " <tr>\n",
361
+ " <th>12</th>\n",
362
+ " <td>16</td>\n",
363
+ " <td>1</td>\n",
364
+ " <td>@VirginAmerica So excited for my first cross c...</td>\n",
365
+ " </tr>\n",
366
+ " <tr>\n",
367
+ " <th>13</th>\n",
368
+ " <td>17</td>\n",
369
+ " <td>0</td>\n",
370
+ " <td>@VirginAmerica I flew from NYC to SFO last we...</td>\n",
371
+ " </tr>\n",
372
+ " <tr>\n",
373
+ " <th>14</th>\n",
374
+ " <td>18</td>\n",
375
+ " <td>1</td>\n",
376
+ " <td>I ❤️ flying @VirginAmerica. ☺️👍</td>\n",
377
+ " </tr>\n",
378
+ " <tr>\n",
379
+ " <th>15</th>\n",
380
+ " <td>19</td>\n",
381
+ " <td>1</td>\n",
382
+ " <td>@VirginAmerica you know what would be amazingl...</td>\n",
383
+ " </tr>\n",
384
+ " <tr>\n",
385
+ " <th>16</th>\n",
386
+ " <td>20</td>\n",
387
+ " <td>0</td>\n",
388
+ " <td>@VirginAmerica why are your first fares in May...</td>\n",
389
+ " </tr>\n",
390
+ " <tr>\n",
391
+ " <th>17</th>\n",
392
+ " <td>21</td>\n",
393
+ " <td>1</td>\n",
394
+ " <td>@VirginAmerica I love this graphic. http://t.c...</td>\n",
395
+ " </tr>\n",
396
+ " <tr>\n",
397
+ " <th>18</th>\n",
398
+ " <td>22</td>\n",
399
+ " <td>1</td>\n",
400
+ " <td>@VirginAmerica I love the hipster innovation. ...</td>\n",
401
+ " </tr>\n",
402
+ " <tr>\n",
403
+ " <th>19</th>\n",
404
+ " <td>24</td>\n",
405
+ " <td>0</td>\n",
406
+ " <td>@VirginAmerica you guys messed up my seating.....</td>\n",
407
+ " </tr>\n",
408
+ " </tbody>\n",
409
+ "</table>\n",
410
+ "</div>"
411
+ ],
412
+ "text/plain": [
413
+ " Unnamed: 0 airline_sentiment \\\n",
414
+ "0 1 1 \n",
415
+ "1 3 0 \n",
416
+ "2 4 0 \n",
417
+ "3 5 0 \n",
418
+ "4 6 1 \n",
419
+ "5 8 1 \n",
420
+ "6 9 1 \n",
421
+ "7 11 1 \n",
422
+ "8 12 1 \n",
423
+ "9 13 1 \n",
424
+ "10 14 1 \n",
425
+ "11 15 0 \n",
426
+ "12 16 1 \n",
427
+ "13 17 0 \n",
428
+ "14 18 1 \n",
429
+ "15 19 1 \n",
430
+ "16 20 0 \n",
431
+ "17 21 1 \n",
432
+ "18 22 1 \n",
433
+ "19 24 0 \n",
434
+ "\n",
435
+ " text \n",
436
+ "0 @VirginAmerica plus you've added commercials t... \n",
437
+ "1 @VirginAmerica it's really aggressive to blast... \n",
438
+ "2 @VirginAmerica and it's a really big bad thing... \n",
439
+ "3 @VirginAmerica seriously would pay $30 a fligh... \n",
440
+ "4 @VirginAmerica yes, nearly every time I fly VX... \n",
441
+ "5 @virginamerica Well, I didn't…but NOW I DO! :-D \n",
442
+ "6 @VirginAmerica it was amazing, and arrived an ... \n",
443
+ "7 @VirginAmerica I &lt;3 pretty graphics. so muc... \n",
444
+ "8 @VirginAmerica This is such a great deal! Alre... \n",
445
+ "9 @VirginAmerica @virginmedia I'm flying your #f... \n",
446
+ "10 @VirginAmerica Thanks! \n",
447
+ "11 @VirginAmerica SFO-PDX schedule is still MIA. \n",
448
+ "12 @VirginAmerica So excited for my first cross c... \n",
449
+ "13 @VirginAmerica I flew from NYC to SFO last we... \n",
450
+ "14 I ❤️ flying @VirginAmerica. ☺️👍 \n",
451
+ "15 @VirginAmerica you know what would be amazingl... \n",
452
+ "16 @VirginAmerica why are your first fares in May... \n",
453
+ "17 @VirginAmerica I love this graphic. http://t.c... \n",
454
+ "18 @VirginAmerica I love the hipster innovation. ... \n",
455
+ "19 @VirginAmerica you guys messed up my seating..... "
456
+ ]
457
+ },
458
+ "execution_count": 4,
459
+ "metadata": {},
460
+ "output_type": "execute_result"
461
+ }
462
+ ],
463
+ "source": [
464
+ "for label in df['airline_sentiment']:\n",
465
+ " if label == 'positive':\n",
466
+ " df['airline_sentiment'].replace(label, 1, inplace=True)\n",
467
+ " elif label == 'negative':\n",
468
+ " df['airline_sentiment'].replace(label, 0, inplace=True)\n",
469
+ "df.head(20)"
470
+ ]
471
+ },
472
+ {
473
+ "cell_type": "code",
474
+ "execution_count": 5,
475
+ "metadata": {
476
+ "colab": {
477
+ "base_uri": "https://localhost:8080/",
478
+ "height": 676
479
+ },
480
+ "id": "ApZHkGw2m_pG",
481
+ "outputId": "3b89a43e-9523-42be-d646-679858136abc"
482
+ },
483
+ "outputs": [
484
+ {
485
+ "data": {
486
+ "text/html": [
487
+ "<div>\n",
488
+ "<style scoped>\n",
489
+ " .dataframe tbody tr th:only-of-type {\n",
490
+ " vertical-align: middle;\n",
491
+ " }\n",
492
+ "\n",
493
+ " .dataframe tbody tr th {\n",
494
+ " vertical-align: top;\n",
495
+ " }\n",
496
+ "\n",
497
+ " .dataframe thead th {\n",
498
+ " text-align: right;\n",
499
+ " }\n",
500
+ "</style>\n",
501
+ "<table border=\"1\" class=\"dataframe\">\n",
502
+ " <thead>\n",
503
+ " <tr style=\"text-align: right;\">\n",
504
+ " <th></th>\n",
505
+ " <th>Unnamed: 0</th>\n",
506
+ " <th>airline_sentiment</th>\n",
507
+ " <th>text</th>\n",
508
+ " </tr>\n",
509
+ " </thead>\n",
510
+ " <tbody>\n",
511
+ " <tr>\n",
512
+ " <th>0</th>\n",
513
+ " <td>1</td>\n",
514
+ " <td>1</td>\n",
515
+ " <td>plus you've added commercials to the experien...</td>\n",
516
+ " </tr>\n",
517
+ " <tr>\n",
518
+ " <th>1</th>\n",
519
+ " <td>3</td>\n",
520
+ " <td>0</td>\n",
521
+ " <td>it's really aggressive to blast obnoxious en...</td>\n",
522
+ " </tr>\n",
523
+ " <tr>\n",
524
+ " <th>2</th>\n",
525
+ " <td>4</td>\n",
526
+ " <td>0</td>\n",
527
+ " <td>and it's a really big bad thing about it</td>\n",
528
+ " </tr>\n",
529
+ " <tr>\n",
530
+ " <th>3</th>\n",
531
+ " <td>5</td>\n",
532
+ " <td>0</td>\n",
533
+ " <td>seriously would pay a flight for seats th...</td>\n",
534
+ " </tr>\n",
535
+ " <tr>\n",
536
+ " <th>4</th>\n",
537
+ " <td>6</td>\n",
538
+ " <td>1</td>\n",
539
+ " <td>yes nearly every time I fly VX this ear wor...</td>\n",
540
+ " </tr>\n",
541
+ " <tr>\n",
542
+ " <th>5</th>\n",
543
+ " <td>8</td>\n",
544
+ " <td>1</td>\n",
545
+ " <td>Well I didn't but NOW I DO! D</td>\n",
546
+ " </tr>\n",
547
+ " <tr>\n",
548
+ " <th>6</th>\n",
549
+ " <td>9</td>\n",
550
+ " <td>1</td>\n",
551
+ " <td>it was amazing and arrived an hour early. Yo...</td>\n",
552
+ " </tr>\n",
553
+ " <tr>\n",
554
+ " <th>7</th>\n",
555
+ " <td>11</td>\n",
556
+ " <td>1</td>\n",
557
+ " <td>I lt pretty graphics. so much better than ...</td>\n",
558
+ " </tr>\n",
559
+ " <tr>\n",
560
+ " <th>8</th>\n",
561
+ " <td>12</td>\n",
562
+ " <td>1</td>\n",
563
+ " <td>This is such a great deal! Already thinking a...</td>\n",
564
+ " </tr>\n",
565
+ " <tr>\n",
566
+ " <th>9</th>\n",
567
+ " <td>13</td>\n",
568
+ " <td>1</td>\n",
569
+ " <td>I'm flying your fabulous Seductive skies aga...</td>\n",
570
+ " </tr>\n",
571
+ " <tr>\n",
572
+ " <th>10</th>\n",
573
+ " <td>14</td>\n",
574
+ " <td>1</td>\n",
575
+ " <td>Thanks!</td>\n",
576
+ " </tr>\n",
577
+ " <tr>\n",
578
+ " <th>11</th>\n",
579
+ " <td>15</td>\n",
580
+ " <td>0</td>\n",
581
+ " <td>SFO PDX schedule is still MIA.</td>\n",
582
+ " </tr>\n",
583
+ " <tr>\n",
584
+ " <th>12</th>\n",
585
+ " <td>16</td>\n",
586
+ " <td>1</td>\n",
587
+ " <td>So excited for my first cross country flight ...</td>\n",
588
+ " </tr>\n",
589
+ " <tr>\n",
590
+ " <th>13</th>\n",
591
+ " <td>17</td>\n",
592
+ " <td>0</td>\n",
593
+ " <td>I flew from NYC to SFO last week and couldn't...</td>\n",
594
+ " </tr>\n",
595
+ " <tr>\n",
596
+ " <th>14</th>\n",
597
+ " <td>18</td>\n",
598
+ " <td>1</td>\n",
599
+ " <td>I red heart flying . smiling face thumbs up</td>\n",
600
+ " </tr>\n",
601
+ " <tr>\n",
602
+ " <th>15</th>\n",
603
+ " <td>19</td>\n",
604
+ " <td>1</td>\n",
605
+ " <td>you know what would be amazingly awesome? BOS...</td>\n",
606
+ " </tr>\n",
607
+ " <tr>\n",
608
+ " <th>16</th>\n",
609
+ " <td>20</td>\n",
610
+ " <td>0</td>\n",
611
+ " <td>why are your first fares in May over three ti...</td>\n",
612
+ " </tr>\n",
613
+ " <tr>\n",
614
+ " <th>17</th>\n",
615
+ " <td>21</td>\n",
616
+ " <td>1</td>\n",
617
+ " <td>I love this graphic. http t.co UT GrRwAaA</td>\n",
618
+ " </tr>\n",
619
+ " <tr>\n",
620
+ " <th>18</th>\n",
621
+ " <td>22</td>\n",
622
+ " <td>1</td>\n",
623
+ " <td>I love the hipster innovation. You are a feel...</td>\n",
624
+ " </tr>\n",
625
+ " <tr>\n",
626
+ " <th>19</th>\n",
627
+ " <td>24</td>\n",
628
+ " <td>0</td>\n",
629
+ " <td>you guys messed up my seating.. I reserved se...</td>\n",
630
+ " </tr>\n",
631
+ " </tbody>\n",
632
+ "</table>\n",
633
+ "</div>"
634
+ ],
635
+ "text/plain": [
636
+ " Unnamed: 0 airline_sentiment \\\n",
637
+ "0 1 1 \n",
638
+ "1 3 0 \n",
639
+ "2 4 0 \n",
640
+ "3 5 0 \n",
641
+ "4 6 1 \n",
642
+ "5 8 1 \n",
643
+ "6 9 1 \n",
644
+ "7 11 1 \n",
645
+ "8 12 1 \n",
646
+ "9 13 1 \n",
647
+ "10 14 1 \n",
648
+ "11 15 0 \n",
649
+ "12 16 1 \n",
650
+ "13 17 0 \n",
651
+ "14 18 1 \n",
652
+ "15 19 1 \n",
653
+ "16 20 0 \n",
654
+ "17 21 1 \n",
655
+ "18 22 1 \n",
656
+ "19 24 0 \n",
657
+ "\n",
658
+ " text \n",
659
+ "0 plus you've added commercials to the experien... \n",
660
+ "1 it's really aggressive to blast obnoxious en... \n",
661
+ "2 and it's a really big bad thing about it \n",
662
+ "3 seriously would pay a flight for seats th... \n",
663
+ "4 yes nearly every time I fly VX this ear wor... \n",
664
+ "5 Well I didn't but NOW I DO! D \n",
665
+ "6 it was amazing and arrived an hour early. Yo... \n",
666
+ "7 I lt pretty graphics. so much better than ... \n",
667
+ "8 This is such a great deal! Already thinking a... \n",
668
+ "9 I'm flying your fabulous Seductive skies aga... \n",
669
+ "10 Thanks! \n",
670
+ "11 SFO PDX schedule is still MIA. \n",
671
+ "12 So excited for my first cross country flight ... \n",
672
+ "13 I flew from NYC to SFO last week and couldn't... \n",
673
+ "14 I red heart flying . smiling face thumbs up \n",
674
+ "15 you know what would be amazingly awesome? BOS... \n",
675
+ "16 why are your first fares in May over three ti... \n",
676
+ "17 I love this graphic. http t.co UT GrRwAaA \n",
677
+ "18 I love the hipster innovation. You are a feel... \n",
678
+ "19 you guys messed up my seating.. I reserved se... "
679
+ ]
680
+ },
681
+ "execution_count": 5,
682
+ "metadata": {},
683
+ "output_type": "execute_result"
684
+ }
685
+ ],
686
+ "source": [
687
+ "# remove mentions, hashtags, links, and special characters\n",
688
+ "# replace emoji with text\n",
689
+ "import emoji\n",
690
+ "for i,r in df.iterrows():\n",
691
+ " \n",
692
+ " df.loc[i,\"text\"] = emoji.demojize(df.loc[i,\"text\"])\n",
693
+ " df.loc[i,\"text\"] = df.loc[i,\"text\"].replace(\":\",\" \")\n",
694
+ " df.loc[i,\"text\"] = ' '.join(df.loc[i,\"text\"].split())\n",
695
+ "\n",
696
+ "df['text'] = df['text'].str.replace(\"@[A-Za-z0-9]+\", \"\",regex=True)\n",
697
+ "df['text'] = df['text'].str.replace(\"#\", \"\",regex=True)\n",
698
+ "df['text'] = df['text'].str.replace(\"https?://[A-Za-z0-9./]+\", \"\",regex=True)\n",
699
+ "df['text'] = df['text'].str.replace(\"[^a-zA-Z.!?']\", \" \",regex=True)\n",
700
+ "\n",
701
+ "\n",
702
+ "df.head(20)"
703
+ ]
704
+ },
705
+ {
706
+ "cell_type": "code",
707
+ "execution_count": 8,
708
+ "metadata": {
709
+ "id": "MrynUQ9Xm_pG"
710
+ },
711
+ "outputs": [],
712
+ "source": [
713
+ "# split the data into train and test\n",
714
+ "from sklearn.model_selection import train_test_split\n",
715
+ "\n",
716
+ "train, test = train_test_split(df, test_size=0.2, random_state=42)\n"
717
+ ]
718
+ },
719
+ {
720
+ "cell_type": "code",
721
+ "execution_count": 9,
722
+ "metadata": {
723
+ "colab": {
724
+ "base_uri": "https://localhost:8080/"
725
+ },
726
+ "id": "MambfTNXm_pG",
727
+ "outputId": "f0e11223-8e74-445a-8cdc-cc8492f26b14"
728
+ },
729
+ "outputs": [
730
+ {
731
+ "name": "stderr",
732
+ "output_type": "stream",
733
+ "text": [
734
+ "d:\\sentiment_analysis\\venv\\lib\\site-packages\\tqdm\\auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
735
+ " from .autonotebook import tqdm as notebook_tqdm\n",
736
+ "All model checkpoint layers were used when initializing TFBertForSequenceClassification.\n",
737
+ "\n",
738
+ "Some layers of TFBertForSequenceClassification were not initialized from the model checkpoint at bert-base-uncased and are newly initialized: ['classifier']\n",
739
+ "You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n"
740
+ ]
741
+ }
742
+ ],
743
+ "source": [
744
+ "from transformers import BertTokenizer, TFBertForSequenceClassification\n",
745
+ "from transformers import InputExample, InputFeatures\n",
746
+ "import tensorflow as tf\n",
747
+ "\n",
748
+ "model = TFBertForSequenceClassification.from_pretrained('bert-base-uncased')\n",
749
+ "tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')"
750
+ ]
751
+ },
752
+ {
753
+ "cell_type": "code",
754
+ "execution_count": 10,
755
+ "metadata": {
756
+ "id": "uxgZ7GsEm_pH"
757
+ },
758
+ "outputs": [],
759
+ "source": [
760
+ "def convert_data_to_examples(train, test, DATA_COLUMN, LABEL_COLUMN): \n",
761
+ " train_InputExamples = train.apply(lambda x: InputExample(guid=None, # Globally unique ID for bookkeeping, unused in this case\n",
762
+ " text_a = x[DATA_COLUMN], \n",
763
+ " text_b = None,\n",
764
+ " label = x[LABEL_COLUMN]), axis = 1)\n",
765
+ "\n",
766
+ " validation_InputExamples = test.apply(lambda x: InputExample(guid=None, # Globally unique ID for bookkeeping, unused in this case\n",
767
+ " text_a = x[DATA_COLUMN], \n",
768
+ " text_b = None,\n",
769
+ " label = x[LABEL_COLUMN]), axis = 1)\n",
770
+ " \n",
771
+ " return train_InputExamples, validation_InputExamples\n",
772
+ "\n",
773
+ " train_InputExamples, validation_InputExamples = convert_data_to_examples(train, \n",
774
+ " test, \n",
775
+ " 'DATA_COLUMN', \n",
776
+ " 'LABEL_COLUMN')\n",
777
+ " \n",
778
+ "def convert_examples_to_tf_dataset(examples, tokenizer, max_length=128):\n",
779
+ " features = [] # -> will hold InputFeatures to be converted later\n",
780
+ "\n",
781
+ " for e in examples:\n",
782
+ " # Documentation is really strong for this method, so please take a look at it\n",
783
+ " input_dict = tokenizer.encode_plus(\n",
784
+ " e.text_a,\n",
785
+ " add_special_tokens=True,\n",
786
+ " max_length=max_length, # truncates if len(s) > max_length\n",
787
+ " return_token_type_ids=True,\n",
788
+ " return_attention_mask=True,\n",
789
+ " pad_to_max_length=True, # pads to the right by default # CHECK THIS for pad_to_max_length\n",
790
+ " truncation=True\n",
791
+ " )\n",
792
+ "\n",
793
+ " input_ids, token_type_ids, attention_mask = (input_dict[\"input_ids\"],\n",
794
+ " input_dict[\"token_type_ids\"], input_dict['attention_mask'])\n",
795
+ "\n",
796
+ " features.append(\n",
797
+ " InputFeatures(\n",
798
+ " input_ids=input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids, label=e.label\n",
799
+ " )\n",
800
+ " )\n",
801
+ "\n",
802
+ " def gen():\n",
803
+ " for f in features:\n",
804
+ " yield (\n",
805
+ " {\n",
806
+ " \"input_ids\": f.input_ids,\n",
807
+ " \"attention_mask\": f.attention_mask,\n",
808
+ " \"token_type_ids\": f.token_type_ids,\n",
809
+ " },\n",
810
+ " f.label,\n",
811
+ " )\n",
812
+ "\n",
813
+ " return tf.data.Dataset.from_generator(\n",
814
+ " gen,\n",
815
+ " ({\"input_ids\": tf.int32, \"attention_mask\": tf.int32, \"token_type_ids\": tf.int32}, tf.int64),\n",
816
+ " (\n",
817
+ " {\n",
818
+ " \"input_ids\": tf.TensorShape([None]),\n",
819
+ " \"attention_mask\": tf.TensorShape([None]),\n",
820
+ " \"token_type_ids\": tf.TensorShape([None]),\n",
821
+ " },\n",
822
+ " tf.TensorShape([]),\n",
823
+ " ),\n",
824
+ " )\n"
825
+ ]
826
+ },
827
+ {
828
+ "cell_type": "code",
829
+ "execution_count": 11,
830
+ "metadata": {
831
+ "colab": {
832
+ "base_uri": "https://localhost:8080/"
833
+ },
834
+ "id": "tPsHpWhJm_pH",
835
+ "outputId": "a9f7b2b8-d0bb-474b-d91a-25f0c8a40905"
836
+ },
837
+ "outputs": [
838
+ {
839
+ "name": "stderr",
840
+ "output_type": "stream",
841
+ "text": [
842
+ "d:\\sentiment_analysis\\venv\\lib\\site-packages\\transformers\\tokenization_utils_base.py:2336: FutureWarning: The `pad_to_max_length` argument is deprecated and will be removed in a future version, use `padding=True` or `padding='longest'` to pad to the longest sequence in the batch, or use `padding='max_length'` to pad to a max length. In this case, you can give a specific length with `max_length` (e.g. `max_length=45`) or leave max_length to None to pad to the maximal input size of the model (e.g. 512 for Bert).\n",
843
+ " warnings.warn(\n"
844
+ ]
845
+ }
846
+ ],
847
+ "source": [
848
+ "DATA_COLUMN = 'text'\n",
849
+ "LABEL_COLUMN = 'airline_sentiment'\n",
850
+ "\n",
851
+ "\n",
852
+ "train_InputExamples, validation_InputExamples = convert_data_to_examples(train, test, DATA_COLUMN, LABEL_COLUMN)\n",
853
+ "\n",
854
+ "train_data = convert_examples_to_tf_dataset(list(train_InputExamples), tokenizer)\n",
855
+ "train_data = train_data.shuffle(100).batch(32).repeat(2)\n",
856
+ "\n",
857
+ "validation_data = convert_examples_to_tf_dataset(list(validation_InputExamples), tokenizer)\n",
858
+ "validation_data = validation_data.batch(32)"
859
+ ]
860
+ },
861
+ {
862
+ "cell_type": "code",
863
+ "execution_count": 13,
864
+ "metadata": {
865
+ "colab": {
866
+ "base_uri": "https://localhost:8080/"
867
+ },
868
+ "id": "GDcgmUOCm_pI",
869
+ "outputId": "2f262b78-65f4-4cfc-deb3-a51d2b499eab"
870
+ },
871
+ "outputs": [
872
+ {
873
+ "name": "stdout",
874
+ "output_type": "stream",
875
+ "text": [
876
+ "Epoch 1/2\n",
877
+ " 4/Unknown - 168s 36s/step - loss: 0.4485 - accuracy: 0.8203"
878
+ ]
879
+ },
880
+ {
881
+ "ename": "KeyboardInterrupt",
882
+ "evalue": "",
883
+ "output_type": "error",
884
+ "traceback": [
885
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
886
+ "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
887
+ "Cell \u001b[1;32mIn[13], line 5\u001b[0m\n\u001b[0;32m 1\u001b[0m model\u001b[39m.\u001b[39mcompile(optimizer\u001b[39m=\u001b[39mtf\u001b[39m.\u001b[39mkeras\u001b[39m.\u001b[39moptimizers\u001b[39m.\u001b[39mAdam(learning_rate\u001b[39m=\u001b[39m\u001b[39m3e-5\u001b[39m, epsilon\u001b[39m=\u001b[39m\u001b[39m1e-08\u001b[39m, clipnorm\u001b[39m=\u001b[39m\u001b[39m1.0\u001b[39m), \n\u001b[0;32m 2\u001b[0m loss\u001b[39m=\u001b[39mtf\u001b[39m.\u001b[39mkeras\u001b[39m.\u001b[39mlosses\u001b[39m.\u001b[39mSparseCategoricalCrossentropy(from_logits\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m), \n\u001b[0;32m 3\u001b[0m metrics\u001b[39m=\u001b[39m[tf\u001b[39m.\u001b[39mkeras\u001b[39m.\u001b[39mmetrics\u001b[39m.\u001b[39mSparseCategoricalAccuracy(\u001b[39m'\u001b[39m\u001b[39maccuracy\u001b[39m\u001b[39m'\u001b[39m)])\n\u001b[1;32m----> 5\u001b[0m model\u001b[39m.\u001b[39;49mfit(train_data, epochs\u001b[39m=\u001b[39;49m\u001b[39m2\u001b[39;49m, validation_data\u001b[39m=\u001b[39;49mvalidation_data)\n",
888
+ "File \u001b[1;32md:\\sentiment_analysis\\venv\\lib\\site-packages\\keras\\utils\\traceback_utils.py:65\u001b[0m, in \u001b[0;36mfilter_traceback.<locals>.error_handler\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 63\u001b[0m filtered_tb \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m\n\u001b[0;32m 64\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m---> 65\u001b[0m \u001b[39mreturn\u001b[39;00m fn(\u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[0;32m 66\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mException\u001b[39;00m \u001b[39mas\u001b[39;00m e:\n\u001b[0;32m 67\u001b[0m filtered_tb \u001b[39m=\u001b[39m _process_traceback_frames(e\u001b[39m.\u001b[39m__traceback__)\n",
889
+ "File \u001b[1;32md:\\sentiment_analysis\\venv\\lib\\site-packages\\keras\\engine\\training.py:1564\u001b[0m, in \u001b[0;36mModel.fit\u001b[1;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)\u001b[0m\n\u001b[0;32m 1556\u001b[0m \u001b[39mwith\u001b[39;00m tf\u001b[39m.\u001b[39mprofiler\u001b[39m.\u001b[39mexperimental\u001b[39m.\u001b[39mTrace(\n\u001b[0;32m 1557\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mtrain\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[0;32m 1558\u001b[0m epoch_num\u001b[39m=\u001b[39mepoch,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 1561\u001b[0m _r\u001b[39m=\u001b[39m\u001b[39m1\u001b[39m,\n\u001b[0;32m 1562\u001b[0m ):\n\u001b[0;32m 1563\u001b[0m callbacks\u001b[39m.\u001b[39mon_train_batch_begin(step)\n\u001b[1;32m-> 1564\u001b[0m tmp_logs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mtrain_function(iterator)\n\u001b[0;32m 1565\u001b[0m \u001b[39mif\u001b[39;00m data_handler\u001b[39m.\u001b[39mshould_sync:\n\u001b[0;32m 1566\u001b[0m context\u001b[39m.\u001b[39masync_wait()\n",
890
+ "File \u001b[1;32md:\\sentiment_analysis\\venv\\lib\\site-packages\\tensorflow\\python\\util\\traceback_utils.py:150\u001b[0m, in \u001b[0;36mfilter_traceback.<locals>.error_handler\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 148\u001b[0m filtered_tb \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m\n\u001b[0;32m 149\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m--> 150\u001b[0m \u001b[39mreturn\u001b[39;00m fn(\u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[0;32m 151\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mException\u001b[39;00m \u001b[39mas\u001b[39;00m e:\n\u001b[0;32m 152\u001b[0m filtered_tb \u001b[39m=\u001b[39m _process_traceback_frames(e\u001b[39m.\u001b[39m__traceback__)\n",
891
+ "File \u001b[1;32md:\\sentiment_analysis\\venv\\lib\\site-packages\\tensorflow\\python\\eager\\def_function.py:915\u001b[0m, in \u001b[0;36mFunction.__call__\u001b[1;34m(self, *args, **kwds)\u001b[0m\n\u001b[0;32m 912\u001b[0m compiler \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mxla\u001b[39m\u001b[39m\"\u001b[39m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_jit_compile \u001b[39melse\u001b[39;00m \u001b[39m\"\u001b[39m\u001b[39mnonXla\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m 914\u001b[0m \u001b[39mwith\u001b[39;00m OptionalXlaContext(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_jit_compile):\n\u001b[1;32m--> 915\u001b[0m result \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_call(\u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwds)\n\u001b[0;32m 917\u001b[0m new_tracing_count \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mexperimental_get_tracing_count()\n\u001b[0;32m 918\u001b[0m without_tracing \u001b[39m=\u001b[39m (tracing_count \u001b[39m==\u001b[39m new_tracing_count)\n",
892
+ "File \u001b[1;32md:\\sentiment_analysis\\venv\\lib\\site-packages\\tensorflow\\python\\eager\\def_function.py:947\u001b[0m, in \u001b[0;36mFunction._call\u001b[1;34m(self, *args, **kwds)\u001b[0m\n\u001b[0;32m 944\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_lock\u001b[39m.\u001b[39mrelease()\n\u001b[0;32m 945\u001b[0m \u001b[39m# In this case we have created variables on the first call, so we run the\u001b[39;00m\n\u001b[0;32m 946\u001b[0m \u001b[39m# defunned version which is guaranteed to never create variables.\u001b[39;00m\n\u001b[1;32m--> 947\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_stateless_fn(\u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwds) \u001b[39m# pylint: disable=not-callable\u001b[39;00m\n\u001b[0;32m 948\u001b[0m \u001b[39melif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_stateful_fn \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m 949\u001b[0m \u001b[39m# Release the lock early so that multiple threads can perform the call\u001b[39;00m\n\u001b[0;32m 950\u001b[0m \u001b[39m# in parallel.\u001b[39;00m\n\u001b[0;32m 951\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_lock\u001b[39m.\u001b[39mrelease()\n",
893
+ "File \u001b[1;32md:\\sentiment_analysis\\venv\\lib\\site-packages\\tensorflow\\python\\eager\\function.py:2496\u001b[0m, in \u001b[0;36mFunction.__call__\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 2493\u001b[0m \u001b[39mwith\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_lock:\n\u001b[0;32m 2494\u001b[0m (graph_function,\n\u001b[0;32m 2495\u001b[0m filtered_flat_args) \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_maybe_define_function(args, kwargs)\n\u001b[1;32m-> 2496\u001b[0m \u001b[39mreturn\u001b[39;00m graph_function\u001b[39m.\u001b[39;49m_call_flat(\n\u001b[0;32m 2497\u001b[0m filtered_flat_args, captured_inputs\u001b[39m=\u001b[39;49mgraph_function\u001b[39m.\u001b[39;49mcaptured_inputs)\n",
894
+ "File \u001b[1;32md:\\sentiment_analysis\\venv\\lib\\site-packages\\tensorflow\\python\\eager\\function.py:1862\u001b[0m, in \u001b[0;36mConcreteFunction._call_flat\u001b[1;34m(self, args, captured_inputs, cancellation_manager)\u001b[0m\n\u001b[0;32m 1858\u001b[0m possible_gradient_type \u001b[39m=\u001b[39m gradients_util\u001b[39m.\u001b[39mPossibleTapeGradientTypes(args)\n\u001b[0;32m 1859\u001b[0m \u001b[39mif\u001b[39;00m (possible_gradient_type \u001b[39m==\u001b[39m gradients_util\u001b[39m.\u001b[39mPOSSIBLE_GRADIENT_TYPES_NONE\n\u001b[0;32m 1860\u001b[0m \u001b[39mand\u001b[39;00m executing_eagerly):\n\u001b[0;32m 1861\u001b[0m \u001b[39m# No tape is watching; skip to running the function.\u001b[39;00m\n\u001b[1;32m-> 1862\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_build_call_outputs(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_inference_function\u001b[39m.\u001b[39;49mcall(\n\u001b[0;32m 1863\u001b[0m ctx, args, cancellation_manager\u001b[39m=\u001b[39;49mcancellation_manager))\n\u001b[0;32m 1864\u001b[0m forward_backward \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_select_forward_and_backward_functions(\n\u001b[0;32m 1865\u001b[0m args,\n\u001b[0;32m 1866\u001b[0m possible_gradient_type,\n\u001b[0;32m 1867\u001b[0m executing_eagerly)\n\u001b[0;32m 1868\u001b[0m forward_function, args_with_tangents \u001b[39m=\u001b[39m forward_backward\u001b[39m.\u001b[39mforward()\n",
895
+ "File \u001b[1;32md:\\sentiment_analysis\\venv\\lib\\site-packages\\tensorflow\\python\\eager\\function.py:499\u001b[0m, in \u001b[0;36m_EagerDefinedFunction.call\u001b[1;34m(self, ctx, args, cancellation_manager)\u001b[0m\n\u001b[0;32m 497\u001b[0m \u001b[39mwith\u001b[39;00m _InterpolateFunctionError(\u001b[39mself\u001b[39m):\n\u001b[0;32m 498\u001b[0m \u001b[39mif\u001b[39;00m cancellation_manager \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m--> 499\u001b[0m outputs \u001b[39m=\u001b[39m execute\u001b[39m.\u001b[39;49mexecute(\n\u001b[0;32m 500\u001b[0m \u001b[39mstr\u001b[39;49m(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49msignature\u001b[39m.\u001b[39;49mname),\n\u001b[0;32m 501\u001b[0m num_outputs\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_num_outputs,\n\u001b[0;32m 502\u001b[0m inputs\u001b[39m=\u001b[39;49margs,\n\u001b[0;32m 503\u001b[0m attrs\u001b[39m=\u001b[39;49mattrs,\n\u001b[0;32m 504\u001b[0m ctx\u001b[39m=\u001b[39;49mctx)\n\u001b[0;32m 505\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m 506\u001b[0m outputs \u001b[39m=\u001b[39m execute\u001b[39m.\u001b[39mexecute_with_cancellation(\n\u001b[0;32m 507\u001b[0m \u001b[39mstr\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39msignature\u001b[39m.\u001b[39mname),\n\u001b[0;32m 508\u001b[0m num_outputs\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_num_outputs,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 511\u001b[0m ctx\u001b[39m=\u001b[39mctx,\n\u001b[0;32m 512\u001b[0m cancellation_manager\u001b[39m=\u001b[39mcancellation_manager)\n",
896
+ "File \u001b[1;32md:\\sentiment_analysis\\venv\\lib\\site-packages\\tensorflow\\python\\eager\\execute.py:54\u001b[0m, in \u001b[0;36mquick_execute\u001b[1;34m(op_name, num_outputs, inputs, attrs, ctx, name)\u001b[0m\n\u001b[0;32m 52\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m 53\u001b[0m ctx\u001b[39m.\u001b[39mensure_initialized()\n\u001b[1;32m---> 54\u001b[0m tensors \u001b[39m=\u001b[39m pywrap_tfe\u001b[39m.\u001b[39;49mTFE_Py_Execute(ctx\u001b[39m.\u001b[39;49m_handle, device_name, op_name,\n\u001b[0;32m 55\u001b[0m inputs, attrs, num_outputs)\n\u001b[0;32m 56\u001b[0m \u001b[39mexcept\u001b[39;00m core\u001b[39m.\u001b[39m_NotOkStatusException \u001b[39mas\u001b[39;00m e:\n\u001b[0;32m 57\u001b[0m \u001b[39mif\u001b[39;00m name \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n",
897
+ "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
898
+ ]
899
+ }
900
+ ],
901
+ "source": [
902
+ "model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=3e-5, epsilon=1e-08, clipnorm=1.0), \n",
903
+ " loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), \n",
904
+ " metrics=[tf.keras.metrics.SparseCategoricalAccuracy('accuracy')])\n",
905
+ "\n",
906
+ "model.fit(train_data, epochs=2, validation_data=validation_data)"
907
+ ]
908
+ },
909
+ {
910
+ "cell_type": "code",
911
+ "execution_count": null,
912
+ "metadata": {
913
+ "id": "K3pzOJS8R1dx"
914
+ },
915
+ "outputs": [],
916
+ "source": [
917
+ "model.save_weights(\"weights.h5\")"
918
+ ]
919
+ },
920
+ {
921
+ "cell_type": "code",
922
+ "execution_count": null,
923
+ "metadata": {
924
+ "colab": {
925
+ "base_uri": "https://localhost:8080/",
926
+ "height": 143
927
+ },
928
+ "id": "BLcz_yKOr38C",
929
+ "outputId": "a56245b6-395a-4ff1-aeba-ab30c98cedb1"
930
+ },
931
+ "outputs": [
932
+ {
933
+ "data": {
934
+ "text/html": [
935
+ "\n",
936
+ " <div id=\"df-cc5f72e8-1526-491c-af16-8e253c1ba29b\">\n",
937
+ " <div class=\"colab-df-container\">\n",
938
+ " <div>\n",
939
+ "<style scoped>\n",
940
+ " .dataframe tbody tr th:only-of-type {\n",
941
+ " vertical-align: middle;\n",
942
+ " }\n",
943
+ "\n",
944
+ " .dataframe tbody tr th {\n",
945
+ " vertical-align: top;\n",
946
+ " }\n",
947
+ "\n",
948
+ " .dataframe thead th {\n",
949
+ " text-align: right;\n",
950
+ " }\n",
951
+ "</style>\n",
952
+ "<table border=\"1\" class=\"dataframe\">\n",
953
+ " <thead>\n",
954
+ " <tr style=\"text-align: right;\">\n",
955
+ " <th></th>\n",
956
+ " <th>0</th>\n",
957
+ " </tr>\n",
958
+ " </thead>\n",
959
+ " <tbody>\n",
960
+ " <tr>\n",
961
+ " <th>0</th>\n",
962
+ " <td>The flight was great</td>\n",
963
+ " </tr>\n",
964
+ " <tr>\n",
965
+ " <th>1</th>\n",
966
+ " <td>frowning face</td>\n",
967
+ " </tr>\n",
968
+ " <tr>\n",
969
+ " <th>2</th>\n",
970
+ " <td>confetti ball it was bad experience</td>\n",
971
+ " </tr>\n",
972
+ " </tbody>\n",
973
+ "</table>\n",
974
+ "</div>\n",
975
+ " <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-cc5f72e8-1526-491c-af16-8e253c1ba29b')\"\n",
976
+ " title=\"Convert this dataframe to an interactive table.\"\n",
977
+ " style=\"display:none;\">\n",
978
+ " \n",
979
+ " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
980
+ " width=\"24px\">\n",
981
+ " <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
982
+ " <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
983
+ " </svg>\n",
984
+ " </button>\n",
985
+ " \n",
986
+ " <style>\n",
987
+ " .colab-df-container {\n",
988
+ " display:flex;\n",
989
+ " flex-wrap:wrap;\n",
990
+ " gap: 12px;\n",
991
+ " }\n",
992
+ "\n",
993
+ " .colab-df-convert {\n",
994
+ " background-color: #E8F0FE;\n",
995
+ " border: none;\n",
996
+ " border-radius: 50%;\n",
997
+ " cursor: pointer;\n",
998
+ " display: none;\n",
999
+ " fill: #1967D2;\n",
1000
+ " height: 32px;\n",
1001
+ " padding: 0 0 0 0;\n",
1002
+ " width: 32px;\n",
1003
+ " }\n",
1004
+ "\n",
1005
+ " .colab-df-convert:hover {\n",
1006
+ " background-color: #E2EBFA;\n",
1007
+ " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
1008
+ " fill: #174EA6;\n",
1009
+ " }\n",
1010
+ "\n",
1011
+ " [theme=dark] .colab-df-convert {\n",
1012
+ " background-color: #3B4455;\n",
1013
+ " fill: #D2E3FC;\n",
1014
+ " }\n",
1015
+ "\n",
1016
+ " [theme=dark] .colab-df-convert:hover {\n",
1017
+ " background-color: #434B5C;\n",
1018
+ " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
1019
+ " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
1020
+ " fill: #FFFFFF;\n",
1021
+ " }\n",
1022
+ " </style>\n",
1023
+ "\n",
1024
+ " <script>\n",
1025
+ " const buttonEl =\n",
1026
+ " document.querySelector('#df-cc5f72e8-1526-491c-af16-8e253c1ba29b button.colab-df-convert');\n",
1027
+ " buttonEl.style.display =\n",
1028
+ " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
1029
+ "\n",
1030
+ " async function convertToInteractive(key) {\n",
1031
+ " const element = document.querySelector('#df-cc5f72e8-1526-491c-af16-8e253c1ba29b');\n",
1032
+ " const dataTable =\n",
1033
+ " await google.colab.kernel.invokeFunction('convertToInteractive',\n",
1034
+ " [key], {});\n",
1035
+ " if (!dataTable) return;\n",
1036
+ "\n",
1037
+ " const docLinkHtml = 'Like what you see? Visit the ' +\n",
1038
+ " '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
1039
+ " + ' to learn more about interactive tables.';\n",
1040
+ " element.innerHTML = '';\n",
1041
+ " dataTable['output_type'] = 'display_data';\n",
1042
+ " await google.colab.output.renderOutput(dataTable, element);\n",
1043
+ " const docLink = document.createElement('div');\n",
1044
+ " docLink.innerHTML = docLinkHtml;\n",
1045
+ " element.appendChild(docLink);\n",
1046
+ " }\n",
1047
+ " </script>\n",
1048
+ " </div>\n",
1049
+ " </div>\n",
1050
+ " "
1051
+ ],
1052
+ "text/plain": [
1053
+ " 0\n",
1054
+ "0 The flight was great\n",
1055
+ "1 frowning face\n",
1056
+ "2 confetti ball it was bad experience"
1057
+ ]
1058
+ },
1059
+ "execution_count": 23,
1060
+ "metadata": {},
1061
+ "output_type": "execute_result"
1062
+ }
1063
+ ],
1064
+ "source": [
1065
+ "pred_data = [\"@abc The flight was great\", \"@abc ☹️\",\"🎊 it was bad experience\"]\n",
1066
+ "pred_data = pd.DataFrame(pred_data)\n",
1067
+ "\n",
1068
+ "\n",
1069
+ "for i,r in pred_data.iterrows():\n",
1070
+ " pred_data.loc[i,0] = emoji.demojize(r[0])\n",
1071
+ " pred_data.loc[i,0] = r[0].replace(\":\",\" \")\n",
1072
+ " pred_data.loc[i,0] = ' '.join(r[0].split())\n",
1073
+ "\n",
1074
+ "\n",
1075
+ "pred_data[0] = pred_data[0].str.replace(\"@[A-Za-z0-9]+\", \"\",regex=True)\n",
1076
+ "pred_data[0] = pred_data[0].str.replace(\"#\", \"\",regex=True)\n",
1077
+ "pred_data[0] = pred_data[0].str.replace(\"https?://[A-Za-z0-9./]+\", \"\",regex=True)\n",
1078
+ "pred_data[0] = pred_data[0].str.replace(\"[^a-zA-Z.!?']\", \" \",regex=True)\n",
1079
+ "\n",
1080
+ "pred_data.head()\n"
1081
+ ]
1082
+ },
1083
+ {
1084
+ "cell_type": "code",
1085
+ "execution_count": null,
1086
+ "metadata": {
1087
+ "colab": {
1088
+ "base_uri": "https://localhost:8080/"
1089
+ },
1090
+ "id": "lrTfXZzLsKd6",
1091
+ "outputId": "0f2c6e24-bc62-45a6-bc71-9b6918ab961e"
1092
+ },
1093
+ "outputs": [
1094
+ {
1095
+ "name": "stdout",
1096
+ "output_type": "stream",
1097
+ "text": [
1098
+ "[' The flight was great', ' frowning face', 'confetti ball it was bad experience']\n",
1099
+ " The flight was great : \n",
1100
+ " Positive\n",
1101
+ " frowning face : \n",
1102
+ " Negative\n",
1103
+ "confetti ball it was bad experience : \n",
1104
+ " Negative\n"
1105
+ ]
1106
+ }
1107
+ ],
1108
+ "source": [
1109
+ "pred_data = pred_data[0].values.tolist()\n",
1110
+ "print(pred_data)\n",
1111
+ "tf_batch = tokenizer(pred_data, max_length=128, padding=True, truncation=True, return_tensors='tf')\n",
1112
+ "tf_outputs = model(tf_batch)\n",
1113
+ "tf_predictions = tf.nn.softmax(tf_outputs[0], axis=-1)\n",
1114
+ "labels = ['Negative','Positive']\n",
1115
+ "label = tf.argmax(tf_predictions, axis=1)\n",
1116
+ "label = label.numpy()\n",
1117
+ "for i in range(len(pred_data)):\n",
1118
+ " print(pred_data[i], \": \\n\", labels[label[i]])"
1119
+ ]
1120
+ }
1121
+ ],
1122
+ "metadata": {
1123
+ "accelerator": "GPU",
1124
+ "colab": {
1125
+ "provenance": []
1126
+ },
1127
+ "gpuClass": "standard",
1128
+ "kernelspec": {
1129
+ "display_name": "venv",
1130
+ "language": "python",
1131
+ "name": "python3"
1132
+ },
1133
+ "language_info": {
1134
+ "codemirror_mode": {
1135
+ "name": "ipython",
1136
+ "version": 3
1137
+ },
1138
+ "file_extension": ".py",
1139
+ "mimetype": "text/x-python",
1140
+ "name": "python",
1141
+ "nbconvert_exporter": "python",
1142
+ "pygments_lexer": "ipython3",
1143
+ "version": "3.10.9 (tags/v3.10.9:1dd9be6, Dec 6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)]"
1144
+ },
1145
+ "orig_nbformat": 4,
1146
+ "vscode": {
1147
+ "interpreter": {
1148
+ "hash": "497fb9213e55408ad8b1ca9a37e341ac93888d86a532670599a03e0c8054f45a"
1149
+ }
1150
+ }
1151
+ },
1152
+ "nbformat": 4,
1153
+ "nbformat_minor": 0
1154
+ }
weights.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f65c531ac62337f7a5622b09e4bdecfeb6de6975d53cbf063be98f2667458325
3
+ size 438223128