thegeek13242
commited on
Commit
•
6bee2db
1
Parent(s):
b2898f0
retrained after balancing dataset
Browse files- balanced.csv +0 -0
- train.ipynb +194 -834
- weights.h5 +1 -1
balanced.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
train.ipynb
CHANGED
@@ -1,5 +1,54 @@
|
|
1 |
{
|
2 |
"cells": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
"execution_count": null,
|
@@ -8,458 +57,79 @@
|
|
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":
|
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":
|
33 |
"metadata": {
|
34 |
"colab": {
|
35 |
"base_uri": "https://localhost:8080/",
|
36 |
"height": 676
|
37 |
},
|
38 |
"id": "mrnzcvkzm_pF",
|
39 |
-
"outputId": "
|
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 &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 <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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
]
|
248 |
},
|
249 |
{
|
250 |
"cell_type": "code",
|
251 |
-
"execution_count":
|
252 |
"metadata": {
|
253 |
"colab": {
|
254 |
"base_uri": "https://localhost:8080/",
|
255 |
"height": 676
|
256 |
},
|
257 |
"id": "Jbl-wjpWm_pG",
|
258 |
-
"outputId": "
|
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 &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 <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",
|
@@ -469,223 +139,28 @@
|
|
469 |
"df.head(20)"
|
470 |
]
|
471 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
472 |
{
|
473 |
"cell_type": "code",
|
474 |
-
"execution_count":
|
475 |
"metadata": {
|
476 |
"colab": {
|
477 |
"base_uri": "https://localhost:8080/",
|
478 |
"height": 676
|
479 |
},
|
480 |
"id": "ApZHkGw2m_pG",
|
481 |
-
"outputId": "
|
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 |
-
"
|
688 |
-
"# replace emoji with text\n",
|
689 |
"import emoji\n",
|
690 |
"for i,r in df.iterrows():\n",
|
691 |
" \n",
|
@@ -702,9 +177,56 @@
|
|
702 |
"df.head(20)"
|
703 |
]
|
704 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
705 |
{
|
706 |
"cell_type": "code",
|
707 |
-
"execution_count":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
708 |
"metadata": {
|
709 |
"id": "MrynUQ9Xm_pG"
|
710 |
},
|
@@ -716,9 +238,17 @@
|
|
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":
|
722 |
"metadata": {
|
723 |
"colab": {
|
724 |
"base_uri": "https://localhost:8080/"
|
@@ -726,20 +256,7 @@
|
|
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",
|
@@ -749,9 +266,17 @@
|
|
749 |
"tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')"
|
750 |
]
|
751 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
752 |
{
|
753 |
"cell_type": "code",
|
754 |
-
"execution_count":
|
755 |
"metadata": {
|
756 |
"id": "uxgZ7GsEm_pH"
|
757 |
},
|
@@ -770,10 +295,6 @@
|
|
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",
|
@@ -824,9 +345,17 @@
|
|
824 |
" )\n"
|
825 |
]
|
826 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
827 |
{
|
828 |
"cell_type": "code",
|
829 |
-
"execution_count":
|
830 |
"metadata": {
|
831 |
"colab": {
|
832 |
"base_uri": "https://localhost:8080/"
|
@@ -834,16 +363,7 @@
|
|
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",
|
@@ -860,7 +380,7 @@
|
|
860 |
},
|
861 |
{
|
862 |
"cell_type": "code",
|
863 |
-
"execution_count":
|
864 |
"metadata": {
|
865 |
"colab": {
|
866 |
"base_uri": "https://localhost:8080/"
|
@@ -868,36 +388,7 @@
|
|
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",
|
@@ -906,6 +397,14 @@
|
|
906 |
"model.fit(train_data, epochs=2, validation_data=validation_data)"
|
907 |
]
|
908 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
909 |
{
|
910 |
"cell_type": "code",
|
911 |
"execution_count": null,
|
@@ -917,6 +416,14 @@
|
|
917 |
"model.save_weights(\"weights.h5\")"
|
918 |
]
|
919 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
920 |
{
|
921 |
"cell_type": "code",
|
922 |
"execution_count": null,
|
@@ -928,139 +435,7 @@
|
|
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",
|
@@ -1090,21 +465,7 @@
|
|
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",
|
@@ -1142,7 +503,6 @@
|
|
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"
|
|
|
1 |
{
|
2 |
"cells": [
|
3 |
+
{
|
4 |
+
"attachments": {},
|
5 |
+
"cell_type": "markdown",
|
6 |
+
"metadata": {},
|
7 |
+
"source": [
|
8 |
+
"## Airline Sentiment Prediction using BERT\n",
|
9 |
+
"\n",
|
10 |
+
"### Approach\n",
|
11 |
+
"First I analysed the data and I found that there was a huge imbalance in the dataset, to resolve this I used Textattack for augumentation of data.\n",
|
12 |
+
"Before the augumenting the dataset I used the following techniques to clean the data & reduce the noise:\n",
|
13 |
+
"- Removed the @usernames\n",
|
14 |
+
"- Removed the URLs\n",
|
15 |
+
"- Removed hashtags\n",
|
16 |
+
"- Replacement of emojis with their meaning\n",
|
17 |
+
"\n",
|
18 |
+
"After cleaning the data I used EasyDataAugment of Textattack to augment the data, augmenting the data helped me to increase the accuracy of the model by more than 3%. I also tried using Clare(It replaces the words with their synonyms) but that was very resource intensive & it was taking very long to get output.\n",
|
19 |
+
"\n",
|
20 |
+
"### Model\n",
|
21 |
+
"Since, this was a binary classification task I used BERT for training the model. I used the pretrained BERT model from Huggingface transformers library. I used the BERT model with the following parameters:\n",
|
22 |
+
"- BERT-base-uncased\n",
|
23 |
+
"- Max length of the input sequence: 128\n",
|
24 |
+
"- Learning rate: 3e-5\n",
|
25 |
+
"- Batch size: 32\n",
|
26 |
+
"\n",
|
27 |
+
"### Results\n",
|
28 |
+
"The dataset was split into 80:20 ratio for training & validation.\n",
|
29 |
+
"I got the following results after training the model:\n",
|
30 |
+
"Training loss: 0.0137\n",
|
31 |
+
"Validation loss: 0.1209\n",
|
32 |
+
"Training accuracy: 0.9955\n",
|
33 |
+
"Validation accuracy: 0.9794\n"
|
34 |
+
]
|
35 |
+
},
|
36 |
+
{
|
37 |
+
"attachments": {},
|
38 |
+
"cell_type": "markdown",
|
39 |
+
"metadata": {},
|
40 |
+
"source": [
|
41 |
+
"========================================================================================================================================"
|
42 |
+
]
|
43 |
+
},
|
44 |
+
{
|
45 |
+
"attachments": {},
|
46 |
+
"cell_type": "markdown",
|
47 |
+
"metadata": {},
|
48 |
+
"source": [
|
49 |
+
"Install the required libraries"
|
50 |
+
]
|
51 |
+
},
|
52 |
{
|
53 |
"cell_type": "code",
|
54 |
"execution_count": null,
|
|
|
57 |
},
|
58 |
"outputs": [],
|
59 |
"source": [
|
|
|
60 |
"%pip install transformers\n",
|
61 |
"%pip install emoji\n",
|
62 |
"%pip install numpy pandas\n",
|
63 |
+
"%pip install scikit-learn\n",
|
64 |
+
"%pip install textattack"
|
65 |
+
]
|
66 |
+
},
|
67 |
+
{
|
68 |
+
"attachments": {},
|
69 |
+
"cell_type": "markdown",
|
70 |
+
"metadata": {},
|
71 |
+
"source": [
|
72 |
+
"Importing the libraries"
|
73 |
]
|
74 |
},
|
75 |
{
|
76 |
"cell_type": "code",
|
77 |
+
"execution_count": null,
|
78 |
"metadata": {
|
79 |
"id": "iM2I9UEjm_pE"
|
80 |
},
|
81 |
"outputs": [],
|
82 |
"source": [
|
83 |
"import numpy as np\n",
|
84 |
+
"import pandas as pd\n",
|
85 |
+
"from pprint import pprint"
|
86 |
+
]
|
87 |
+
},
|
88 |
+
{
|
89 |
+
"attachments": {},
|
90 |
+
"cell_type": "markdown",
|
91 |
+
"metadata": {},
|
92 |
+
"source": [
|
93 |
+
"Reading the data"
|
94 |
]
|
95 |
},
|
96 |
{
|
97 |
"cell_type": "code",
|
98 |
+
"execution_count": null,
|
99 |
"metadata": {
|
100 |
"colab": {
|
101 |
"base_uri": "https://localhost:8080/",
|
102 |
"height": 676
|
103 |
},
|
104 |
"id": "mrnzcvkzm_pF",
|
105 |
+
"outputId": "61550835-27fc-4049-f3a3-f9ab9e1ba1bb"
|
106 |
},
|
107 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
"source": [
|
109 |
"df = pd.read_csv(\"airline_sentiment_analysis.csv\")\n",
|
110 |
+
"df.head(20)"
|
111 |
+
]
|
112 |
+
},
|
113 |
+
{
|
114 |
+
"attachments": {},
|
115 |
+
"cell_type": "markdown",
|
116 |
+
"metadata": {},
|
117 |
+
"source": [
|
118 |
+
"Assigning 1 to positive sentiment and 0 to negative sentiment"
|
119 |
]
|
120 |
},
|
121 |
{
|
122 |
"cell_type": "code",
|
123 |
+
"execution_count": null,
|
124 |
"metadata": {
|
125 |
"colab": {
|
126 |
"base_uri": "https://localhost:8080/",
|
127 |
"height": 676
|
128 |
},
|
129 |
"id": "Jbl-wjpWm_pG",
|
130 |
+
"outputId": "19c8b0ca-4506-4960-d588-505feecf678e"
|
131 |
},
|
132 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
"source": [
|
134 |
"for label in df['airline_sentiment']:\n",
|
135 |
" if label == 'positive':\n",
|
|
|
139 |
"df.head(20)"
|
140 |
]
|
141 |
},
|
142 |
+
{
|
143 |
+
"attachments": {},
|
144 |
+
"cell_type": "markdown",
|
145 |
+
"metadata": {},
|
146 |
+
"source": [
|
147 |
+
"Remove the @usernames, URLs, hashtags & Replace the emojis with their meaning"
|
148 |
+
]
|
149 |
+
},
|
150 |
{
|
151 |
"cell_type": "code",
|
152 |
+
"execution_count": null,
|
153 |
"metadata": {
|
154 |
"colab": {
|
155 |
"base_uri": "https://localhost:8080/",
|
156 |
"height": 676
|
157 |
},
|
158 |
"id": "ApZHkGw2m_pG",
|
159 |
+
"outputId": "330f44ff-3314-4392-eef4-69f2994b1cae"
|
160 |
},
|
161 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
"source": [
|
163 |
+
"\n",
|
|
|
164 |
"import emoji\n",
|
165 |
"for i,r in df.iterrows():\n",
|
166 |
" \n",
|
|
|
177 |
"df.head(20)"
|
178 |
]
|
179 |
},
|
180 |
+
{
|
181 |
+
"attachments": {},
|
182 |
+
"cell_type": "markdown",
|
183 |
+
"metadata": {},
|
184 |
+
"source": [
|
185 |
+
"Augumenting Positive Sentiment using EasyDataAugment"
|
186 |
+
]
|
187 |
+
},
|
188 |
{
|
189 |
"cell_type": "code",
|
190 |
+
"execution_count": null,
|
191 |
+
"metadata": {
|
192 |
+
"id": "lNr4OWDaGYww"
|
193 |
+
},
|
194 |
+
"outputs": [],
|
195 |
+
"source": [
|
196 |
+
"positive_feedback = (df.loc[df[\"airline_sentiment\"] == 1])[\"text\"]\n",
|
197 |
+
"positive_feedback = positive_feedback.tolist()\n",
|
198 |
+
"# pprint(positive_feedback)\n",
|
199 |
+
"\n",
|
200 |
+
"from textattack.augmentation import EasyDataAugmenter\n",
|
201 |
+
"esy_aug = EasyDataAugmenter()\n",
|
202 |
+
"aug_list = []\n",
|
203 |
+
"for sen in positive_feedback:\n",
|
204 |
+
" aug_list.append(esy_aug.augment(sen))\n",
|
205 |
+
"serial_list = []\n",
|
206 |
+
"for l in aug_list:\n",
|
207 |
+
" for sen in l:\n",
|
208 |
+
" serial_list.append(sen)\n",
|
209 |
+
"df = df.drop(df.columns[[0]],axis=1)\n",
|
210 |
+
"\n",
|
211 |
+
"df2 = pd.DataFrame(list(zip([1]*len(serial_list),serial_list)),columns=[\"airline_sentiment\",\"text\"])\n",
|
212 |
+
"\n",
|
213 |
+
"df = pd.concat([df,df2])\n",
|
214 |
+
"\n",
|
215 |
+
"df.to_csv(\"modified.csv\") #save the modified dataset\n",
|
216 |
+
"df.head()"
|
217 |
+
]
|
218 |
+
},
|
219 |
+
{
|
220 |
+
"attachments": {},
|
221 |
+
"cell_type": "markdown",
|
222 |
+
"metadata": {},
|
223 |
+
"source": [
|
224 |
+
"Split dataset into train & validation in 80:20 ratio"
|
225 |
+
]
|
226 |
+
},
|
227 |
+
{
|
228 |
+
"cell_type": "code",
|
229 |
+
"execution_count": null,
|
230 |
"metadata": {
|
231 |
"id": "MrynUQ9Xm_pG"
|
232 |
},
|
|
|
238 |
"train, test = train_test_split(df, test_size=0.2, random_state=42)\n"
|
239 |
]
|
240 |
},
|
241 |
+
{
|
242 |
+
"attachments": {},
|
243 |
+
"cell_type": "markdown",
|
244 |
+
"metadata": {},
|
245 |
+
"source": [
|
246 |
+
"Initalise the BERT model & tokenizer"
|
247 |
+
]
|
248 |
+
},
|
249 |
{
|
250 |
"cell_type": "code",
|
251 |
+
"execution_count": null,
|
252 |
"metadata": {
|
253 |
"colab": {
|
254 |
"base_uri": "https://localhost:8080/"
|
|
|
256 |
"id": "MambfTNXm_pG",
|
257 |
"outputId": "f0e11223-8e74-445a-8cdc-cc8492f26b14"
|
258 |
},
|
259 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
"source": [
|
261 |
"from transformers import BertTokenizer, TFBertForSequenceClassification\n",
|
262 |
"from transformers import InputExample, InputFeatures\n",
|
|
|
266 |
"tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')"
|
267 |
]
|
268 |
},
|
269 |
+
{
|
270 |
+
"attachments": {},
|
271 |
+
"cell_type": "markdown",
|
272 |
+
"metadata": {},
|
273 |
+
"source": [
|
274 |
+
"Utility function to convert the data into the format required by BERT"
|
275 |
+
]
|
276 |
+
},
|
277 |
{
|
278 |
"cell_type": "code",
|
279 |
+
"execution_count": null,
|
280 |
"metadata": {
|
281 |
"id": "uxgZ7GsEm_pH"
|
282 |
},
|
|
|
295 |
" \n",
|
296 |
" return train_InputExamples, validation_InputExamples\n",
|
297 |
"\n",
|
|
|
|
|
|
|
|
|
298 |
" \n",
|
299 |
"def convert_examples_to_tf_dataset(examples, tokenizer, max_length=128):\n",
|
300 |
" features = [] # -> will hold InputFeatures to be converted later\n",
|
|
|
345 |
" )\n"
|
346 |
]
|
347 |
},
|
348 |
+
{
|
349 |
+
"attachments": {},
|
350 |
+
"cell_type": "markdown",
|
351 |
+
"metadata": {},
|
352 |
+
"source": [
|
353 |
+
"BERT model for training"
|
354 |
+
]
|
355 |
+
},
|
356 |
{
|
357 |
"cell_type": "code",
|
358 |
+
"execution_count": null,
|
359 |
"metadata": {
|
360 |
"colab": {
|
361 |
"base_uri": "https://localhost:8080/"
|
|
|
363 |
"id": "tPsHpWhJm_pH",
|
364 |
"outputId": "a9f7b2b8-d0bb-474b-d91a-25f0c8a40905"
|
365 |
},
|
366 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
"source": [
|
368 |
"DATA_COLUMN = 'text'\n",
|
369 |
"LABEL_COLUMN = 'airline_sentiment'\n",
|
|
|
380 |
},
|
381 |
{
|
382 |
"cell_type": "code",
|
383 |
+
"execution_count": null,
|
384 |
"metadata": {
|
385 |
"colab": {
|
386 |
"base_uri": "https://localhost:8080/"
|
|
|
388 |
"id": "GDcgmUOCm_pI",
|
389 |
"outputId": "2f262b78-65f4-4cfc-deb3-a51d2b499eab"
|
390 |
},
|
391 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
392 |
"source": [
|
393 |
"model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=3e-5, epsilon=1e-08, clipnorm=1.0), \n",
|
394 |
" loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), \n",
|
|
|
397 |
"model.fit(train_data, epochs=2, validation_data=validation_data)"
|
398 |
]
|
399 |
},
|
400 |
+
{
|
401 |
+
"attachments": {},
|
402 |
+
"cell_type": "markdown",
|
403 |
+
"metadata": {},
|
404 |
+
"source": [
|
405 |
+
"Saving the trained weights"
|
406 |
+
]
|
407 |
+
},
|
408 |
{
|
409 |
"cell_type": "code",
|
410 |
"execution_count": null,
|
|
|
416 |
"model.save_weights(\"weights.h5\")"
|
417 |
]
|
418 |
},
|
419 |
+
{
|
420 |
+
"attachments": {},
|
421 |
+
"cell_type": "markdown",
|
422 |
+
"metadata": {},
|
423 |
+
"source": [
|
424 |
+
"Inference: Predicting the sentiment of the tweet"
|
425 |
+
]
|
426 |
+
},
|
427 |
{
|
428 |
"cell_type": "code",
|
429 |
"execution_count": null,
|
|
|
435 |
"id": "BLcz_yKOr38C",
|
436 |
"outputId": "a56245b6-395a-4ff1-aeba-ab30c98cedb1"
|
437 |
},
|
438 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
439 |
"source": [
|
440 |
"pred_data = [\"@abc The flight was great\", \"@abc ☹️\",\"🎊 it was bad experience\"]\n",
|
441 |
"pred_data = pd.DataFrame(pred_data)\n",
|
|
|
465 |
"id": "lrTfXZzLsKd6",
|
466 |
"outputId": "0f2c6e24-bc62-45a6-bc71-9b6918ab961e"
|
467 |
},
|
468 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
469 |
"source": [
|
470 |
"pred_data = pred_data[0].values.tolist()\n",
|
471 |
"print(pred_data)\n",
|
|
|
503 |
"pygments_lexer": "ipython3",
|
504 |
"version": "3.10.9 (tags/v3.10.9:1dd9be6, Dec 6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)]"
|
505 |
},
|
|
|
506 |
"vscode": {
|
507 |
"interpreter": {
|
508 |
"hash": "497fb9213e55408ad8b1ca9a37e341ac93888d86a532670599a03e0c8054f45a"
|
weights.h5
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
size 438223128
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:25a8035cac413601b82f8fdae3da3d851827d2b8bf5441ef5f321afd89c2ec4c
|
3 |
size 438223128
|