전체 인덱싱.ipynb
37.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5699\n",
"9823\n",
"14020\n",
"2727\n",
"1498\n",
"1464\n"
]
}
],
"source": [
"import pandas as pd\n",
"from nltk.corpus import stopwords\n",
"from nltk.tokenize import word_tokenize\n",
"import re\n",
"thriller_plot = pd.read_csv('/Users/yangyoonji/Documents/2020-1/2020-dataCapstone/data/moviedata/moviePlot/thrillerPlot.csv')\n",
"drama_plot = pd.read_csv('/Users/yangyoonji/Documents/2020-1/2020-dataCapstone/data/moviedata/moviePlot/dramaPlot.csv')\n",
"fantasy_plot = pd.read_csv('/Users/yangyoonji/Documents/2020-1/2020-dataCapstone/data/moviedata/moviePlot/fantasyPlot.csv')\n",
"history_plot = pd.read_csv('/Users/yangyoonji/Documents/2020-1/2020-dataCapstone/data/moviedata/moviePlot/historyPlot.csv')\n",
"social_plot = pd.read_csv('/Users/yangyoonji/Documents/2020-1/2020-dataCapstone/data/moviedata/moviePlot/socialPlot.csv')\n",
"romance_plot = pd.read_csv('/Users/yangyoonji/Documents/2020-1/2020-dataCapstone/data/moviedata/moviePlot/romancePlot.csv')\n",
"\"\"\"\n",
"romance_plot = pd.read_csv('/Users/김서영/Desktop/datacap/data/moviedata/moviePlot/romancePlot.csv')\n",
"thriller_plot = pd.read_csv('/Users/김서영/Desktop/datacap/data/moviedata/moviePlot/thrillerPlot.csv')\n",
"drama_plot = pd.read_csv('/Users/김서영/Desktop/datacap/data/moviedata/moviePlot/dramaPlot.csv')\n",
"fantasy_plot = pd.read_csv('/Users/김서영/Desktop/datacap/data/moviedata/moviePlot/fantasyPlot.csv')\n",
"history_plot = pd.read_csv('/Users/김서영/Desktop/datacap/data/moviedata/moviePlot/historyPlot.csv')\n",
"social_plot = pd.read_csv('/Users/김서영/Desktop/datacap/data/moviedata/moviePlot/socialPlot.csv')\n",
"\"\"\"\n",
"print(len(romance_plot)) #5699 ==> train 2500 test 2500\n",
"print(len(thriller_plot)) #9823 ==> train 2500 test 2500\n",
"print(len(drama_plot))\n",
"print(len(fantasy_plot))\n",
"print(len(history_plot))\n",
"print(len(social_plot))\n",
"\n",
"train_data_size = 1463\n",
"test_data_size = 1463\n",
"\n",
"#전처리(1) 전부 소문자로 변환\n",
"\n",
"\n",
"#romance_plot.줄거리 = romance_plot.줄거리.str.lower()\n",
"#thriller_plot.줄거리 = thriller_plot.줄거리.str.lower()\n",
"\n",
"#전처리(1-1) 데이터 csv 파일로 옮기기\n",
"#romance_plot 2899개 train_data로 to_csv || 2800개 test_data로 to_csv\n",
"#thriller_plot 2899개 train_data로 to_csv || 2800개 test_data로 to_csv\n"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"RM = [[] for _ in range(5699)]\n",
"for i in range(5699):\n",
" RM[i].append(''.join(romance_plot.줄거리[i]))\n",
" \n",
"TH = [[] for _ in range(9823)]\n",
"for i in range(9823):\n",
" TH[i].append(''.join(thriller_plot.줄거리[i]))\n",
"\n",
"FN = [[] for _ in range(2727)]\n",
"for i in range(2727):\n",
" FN[i].append(''.join(fantasy_plot.줄거리[i]))\n",
" \n",
"HS = [[] for _ in range(1498)]\n",
"for i in range(1498):\n",
" HS[i].append(''.join(history_plot.줄거리[i]))\n",
" \n",
"SC = [[] for _ in range(1464)]\n",
"for i in range(1464):\n",
" SC[i].append(''.join(social_plot.줄거리[i]))\n",
"\n",
"DR = [[] for _ in range(14019)]\n",
"for i in range(14019):\n",
" DR[i].append(''.join(drama_plot.줄거리[i]))\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"allplot = RM+TH+FN+HS+SC+DR #모든 드라마 줄거리"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"35230\n"
]
}
],
"source": [
"print(len(allplot))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 모든 장르 줄거리 "
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|███████████████████████████████████████████████████████████████████████████| 35230/35230 [04:06<00:00, 142.67it/s]\n"
]
}
],
"source": [
"# 토큰화+전처리(3) 전체 불용어 처리\n",
"# 전체 플롯\n",
"from tqdm import tqdm\n",
"all_vocab = {} \n",
"all_sentences = []\n",
"stop_words = set(stopwords.words('english'))\n",
"\n",
"for i in tqdm(allplot):\n",
" all_sentences = word_tokenize(str(i)) # 단어 토큰화를 수행합니다.\n",
" result = []\n",
" for word in all_sentences: \n",
" word = word.lower() # 모든 단어를 소문자화하여 단어의 개수를 줄입니다.\n",
" if word not in stop_words: # 단어 토큰화 된 결과에 대해서 불용어를 제거합니다.\n",
" if len(word) > 2: # 단어 길이가 2이하인 경우에 대하여 추가로 단어를 제거합니다.\n",
" result.append(word)\n",
" if word not in all_vocab:\n",
" all_vocab[word] = 0 \n",
" all_vocab[word] += 1\n",
" all_sentences.append(result) "
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"all_vocab_sorted = sorted(all_vocab.items(), key = lambda x:x[1], reverse = True)\n",
"\n",
"#전처리(4) 인덱스 부여\n",
"all_word_to_index = {}\n",
"i=0\n",
"for (word, frequency) in all_vocab_sorted :\n",
" if frequency > 1 : # 정제(Cleaning) 챕터에서 언급했듯이 빈도수가 적은 단어는 제외한다.\n",
" i=i+1\n",
" all_word_to_index[word] = i\n",
"#print(all_word_to_index)\n",
"\n",
"vocab_size = 15000 #상위 15000개 단어만 사용\n",
"words_frequency = [w for w,c in all_word_to_index.items() if c >= vocab_size + 1] # 인덱스가 200 초과인 단어 제거\n",
"for w in words_frequency:\n",
" del all_word_to_index[w] # 해당 단어에 대한 인덱스 정보를 삭제\n",
"\n",
" \n",
"all_word_to_index['OOV'] = len(all_word_to_index) + 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 로맨스"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|█████████████████████████████████████████████████████████████████████████████| 5699/5699 [00:36<00:00, 154.26it/s]\n"
]
}
],
"source": [
"# 토큰화+전처리(3) 불용어 처리\n",
"# 로맨스 플롯\n",
"\n",
"vocab_r = {} \n",
"RMsentences = []\n",
"RMstop_words = set(stopwords.words('english'))\n",
"\n",
"for i in tqdm(RM):\n",
" RMsentence = word_tokenize(str(i)) # 단어 토큰화를 수행합니다.\n",
" result = []\n",
"\n",
" for word in RMsentence: \n",
" word = word.lower() # 모든 단어를 소문자화하여 단어의 개수를 줄입니다.\n",
" if word not in RMstop_words: # 단어 토큰화 된 결과에 대해서 불용어를 제거합니다.\n",
" if len(word) > 2: # 단어 길이가 2이하인 경우에 대하여 추가로 단어를 제거합니다.\n",
" result.append(word)\n",
" if word not in vocab_r:\n",
" vocab_r[word] = 0 \n",
" vocab_r[word] += 1\n",
" RMsentences.append(result) \n",
"\n",
"R_encoded = []\n",
"for s in RMsentences:\n",
" temp = []\n",
" for w in s:\n",
" try:\n",
" temp.append(all_word_to_index[w])\n",
" except KeyError:\n",
" temp.append(all_word_to_index['OOV'])\n",
" R_encoded.append(temp)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 스릴러"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|█████████████████████████████████████████████████████████████████████████████| 9823/9823 [01:19<00:00, 124.04it/s]\n"
]
}
],
"source": [
"# 토큰화+전처리(3) 불용어 처리\n",
"# 스릴러 플롯\n",
"\n",
"vocab_th = {} \n",
"THsentences = []\n",
"THstop_words = set(stopwords.words('english'))\n",
"\n",
"for i in tqdm(TH):\n",
" \n",
" THsentence = word_tokenize(str(i)) # 단어 토큰화를 수행합니다.\n",
" result = []\n",
"\n",
" for word in THsentence: \n",
" word = word.lower() # 모든 단어를 소문자화하여 단어의 개수를 줄입니다.\n",
" if word not in THstop_words: # 단어 토큰화 된 결과에 대해서 불용어를 제거합니다.\n",
" if len(word) > 2: # 단어 길이가 2이하인 경우에 대하여 추가로 단어를 제거합니다.\n",
" result.append(word)\n",
" if word not in vocab_th:\n",
" vocab_th[word] = 0 \n",
" vocab_th[word] += 1\n",
" THsentences.append(result) \n",
"\n",
"TH_encoded = []\n",
"for s in THsentences:\n",
" temp = []\n",
" for w in s:\n",
" try:\n",
" temp.append(all_word_to_index[w])\n",
" except KeyError:\n",
" temp.append(all_word_to_index['OOV'])\n",
" TH_encoded.append(temp)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#전처리 방법에는 NLTK의 FreqDist, 케라스(Keras) 토크나이저도 사용 가능."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"로맨스 플롯, 스릴러 따로 토큰화 해서 x train에 넣을지... 고민중\n",
"\n",
"이번주 : 전처리 완료, \n",
"이번 달 목표 : 뮤지컬 장르 분류 << 다양한 모델 사용해보기.\n",
"\n",
"6월에 교차검증 및 장르 시각화 설계까지.\n",
"\n",
"다음주 : 2진분류(LSTM) 완료, RNN 분류기 만들어보기"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 학습데이터"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 영화 줄거리는 X_train에, 장르 정보는 y_train에 저장된다.\n",
"# 테스트용 줄거리 X_test에, 테스트용 줄거리의 장르 정보는 y_test에 저장된다.\n",
"#맞춰서 저장하기. (진행중)\n",
"\n",
"#X_train = train_sc_df.dropna().drop(‘trade_price_idx_value’, axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"X_train = []\n",
"Y_train = [] #0 : romance, 1 : thriller \n",
"for i in range(train_data_size):\n",
" X_train.append(R_encoded[i])\n",
" Y_train.append(0)\n",
" X_train.append(TH_encoded[i])\n",
" Y_train.append(1)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"#print(X_train[2])\n",
"#print(Y_train[2])"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"줄거리 최대 길이 : 1974\n",
"줄거리 평균 길이 : 267.093984962406\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAD4CAYAAAAD6PrjAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAdIElEQVR4nO3df5DU9Z3n8eeLSYt7ahQUlR+yY3IkhaEuaii1SjbnrBtFsiXkKslJpZTVuSPZEy7WJhYYrko3ualyvY1WZPfYwx1K3DJjvDWWVNQlxHPPoyoa0RDFTFzREDNCgAQWUZQ4zPv++H76azP0DD3TPd3T7etR1dXf/vS3+/ue6Yb3fD+fz/f9UURgZmYGMKHRAZiZ2fjhpGBmZjknBTMzyzkpmJlZzknBzMxyH2p0AMdzxhlnRHt7e6PDsBb13HPP/TYiptT7uP5e21iq5ns97pNCe3s7W7ZsaXQY1qIk/aoRx/X32sZSNd9rdx+ZmVnOScHMzHLHTQqSzpH0pKReSS9J+mpqnyxpk6RX0v2k1C5Jd0vaLukFSReWvNeStP8rkpaM3Y9lZmajUcmZQj/wtYiYDVwC3CjpPGAl8EREzAKeSI8BrgJmpdtSYA1kSQS4FbgYuAi4tZhIzMxsfDhuUoiIXR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6/q7GekKXr6NzxvwaeBCYFujY/FtVJ9fG/Aq8BHgBOBnwHl1OO4O4IxBbXcAK9P2SuCv0vYC4HGyazIuAZ6p8tjHfGdHemxgMvBaup+UtifVMJ7bgK+X2fe89BlNBM5Nn11bLT5HYCpwYdo+BfiXdLy6/G58ptAiIuIpYF+j47BRy8tkRMTvgWKZjEZYCKxP2+uBRSXt90XmaeA0SVNHe5AhvrMjPfaVwKaI2BcR+4FNwPwaxjOUhcADEXE4In4JbCf7DKv+HCNiV0Q8n7YPAr1kyxbX5XfjpGA2PlS0fvkYCOCHkp5LZTgAzoqIXZD9BwWcWccYR3rsesS0LHXLrCt22dQrHkntwAXAM9Tpd+OkYDY+VLR++Ri4NCIuBK4CbpT06WH2bVSMwx17rGNaA3wUOB/YBXy7XvFIOhl4CLgpIt4cbtdaxuKkYDY+NKRMRkTsTPd7gIfJuj92F7uF0v2eOsY40mOPaUwRsTsijkTEAHAP2e9nzOORVCBLCPdHxPdTc11+N04KZuND3ctkSDpJ0inFbeAKYFs6bnGmyhLgkbS9AbguzXa5BDhQ7M6ooZEeeyNwhaRJqWvnitRWE4PGTD5H9vspxnONpImSzgVmAT+hBp+jJAHdQG9E3FnyVH1+N9XMHvBt/NyAHrLT2/fI/kLobHRMvo34M1xANtPkVWBVHY73EbLZMT8DXioeEzgdeAJ4Jd1PTu0iW0joVeBFYG6Vxz/mOzuaYwM3kA30bgeur3E8/5CO90L6z3dqyf6rUjwvA1fV6nME5pF187wAbE23BfX63bjMhZmZ5dx9ZGZmOScFMzPLOSmYmVnOScHMzHJOCmZmlnNSMDOznJOCmZnl/j8lGxvkzw55lwAAAABJRU5ErkJggg==\n",
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"\n",
"len_result = [len(s) for s in X_train]\n",
"print(\"줄거리 최대 길이 : \",max(len_result))\n",
"print(\"줄거리 평균 길이 : \",sum(len_result)/len(len_result))\n",
"\n",
"plt.subplot(1,2,1)\n",
"plt.boxplot(len_result)\n",
"plt.subplot(1,2,2)\n",
"plt.hist(len_result, bins=50)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 테스트 데이터\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"X_test = []\n",
"Y_test = [] #0 : romance, 1 : thriller \n",
"for i in range(test_data_size):\n",
" X_test.append(R_encoded[train_data_size+i])\n",
" Y_test.append(0)\n",
" X_test.append(TH_encoded[train_data_size+i])\n",
" Y_test.append(1)\n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"줄거리 최대 길이 : 1749\n",
"줄거리 평균 길이 : 197.71394395078605\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD4CAYAAAAAczaOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAbkUlEQVR4nO3db3Bc1Znn8e/Psk2ymRgsMIY1sCLBSZm4NoaoGAqUFIbB2GQqTraSXZut4M1o43jGuJIKWxszegGTLVGE3Qwz7DBQZuSK2cqIZIfx4AJniNc4Q7kqEOTYAYMgFsQBY0dWYkMCGf5IevZFn7ZbUuuP1a3uVt/fp+rWvf3c092P3K1H1+eee64iAjMzy4YZ1U7AzMwqx0XfzCxDXPTNzDLERd/MLENc9M3MMmRmtRMYz1lnnRVNTU3VTsPq1J49e34dEfMq/b7+XttUGut7XfNFv6mpia6urmqnYXVK0i+r8b7+XttUGut77e4dM7MMcdE3M8sQF30zswxx0TczyxAXfTOzDBm36EvaLOmopP0Fse9J2peWg5L2pXiTpH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bZPWR1PzauV9qvlULM+I6I2IgYgYBO4n9+9XE7mBi75ZraiJaRwkfUDSB/PbwDJgf8olP+JlDfBw2t4G3JhGzVwOvJHvdplip5rPY8AySXNTd8uyFCu7Yec0Pkfu3y+f2ypJp6X7hC8EfkKlP/upOkPspbIL0Enuv5LvkTtyaK12Tl5O+TO8Hvg5uZEcbVXK4UPkRo/8DHgunwdwJrATOJDWjSkucjePeQl4FmiegpxGfLcnkw/wJ+ROnvYAX5rC3P5Peu9nyBXvcwvat6XcXgRWVOOz9zQMZmYZ4u4dM7MMcdE3M8sQF30zswxx0TczyxAXfTOzDHHRNzPLEBd9M7MM+f8TmXUVrZGt4wAAAABJRU5ErkJggg==\n",
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"\n",
"len_result = [len(s) for s in X_test]\n",
"print(\"줄거리 최대 길이 : \",max(len_result))\n",
"print(\"줄거리 평균 길이 : \",sum(len_result)/len(len_result))\n",
"\n",
"plt.subplot(1,2,1)\n",
"plt.boxplot(len_result)\n",
"plt.subplot(1,2,2)\n",
"plt.hist(len_result, bins=50)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## LSTM 분류 \n"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
"from tensorflow.keras.preprocessing.sequence import pad_sequences\n",
"from tensorflow.keras.models import Sequential\n",
"from tensorflow.keras.layers import Dense, LSTM, Embedding\n",
"from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint\n",
"import numpy as np\n",
"\n",
"max_len = 600\n",
"X_train = pad_sequences(X_train, maxlen=max_len)\n",
"X_test = pad_sequences(X_train, maxlen=max_len)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Train on 2926 samples, validate on 2926 samples\n",
"Epoch 1/5\n",
"2880/2926 [============================>.] - ETA: 1s - loss: 0.6713 - acc: 0.6417\n",
"Epoch 00001: val_acc improved from -inf to 0.81579, saving model to best_model.h5\n",
"2926/2926 [==============================] - 108s 37ms/sample - loss: 0.6699 - acc: 0.6415 - val_loss: 0.4897 - val_acc: 0.8158\n",
"Epoch 2/5\n",
"2880/2926 [============================>.] - ETA: 1s - loss: 0.4069 - acc: 0.8500\n",
"Epoch 00002: val_acc improved from 0.81579 to 0.85885, saving model to best_model.h5\n",
"2926/2926 [==============================] - 103s 35ms/sample - loss: 0.4084 - acc: 0.8483 - val_loss: 0.3895 - val_acc: 0.8589\n",
"Epoch 3/5\n",
"2880/2926 [============================>.] - ETA: 1s - loss: 0.1958 - acc: 0.9347\n",
"Epoch 00003: val_acc improved from 0.85885 to 0.97573, saving model to best_model.h5\n",
"2926/2926 [==============================] - 107s 37ms/sample - loss: 0.1965 - acc: 0.9340 - val_loss: 0.0733 - val_acc: 0.9757\n",
"Epoch 4/5\n",
"2880/2926 [============================>.] - ETA: 1s - loss: 0.0680 - acc: 0.9823\n",
"Epoch 00004: val_acc improved from 0.97573 to 0.99522, saving model to best_model.h5\n",
"2926/2926 [==============================] - 102s 35ms/sample - loss: 0.0681 - acc: 0.9822 - val_loss: 0.0322 - val_acc: 0.9952\n",
"Epoch 5/5\n",
"2432/2926 [=======================>......] - ETA: 14s - loss: 0.0178 - acc: 0.9959"
]
}
],
"source": [
"model = Sequential()\n",
"model.add(Embedding(15002, 120))\n",
"model.add(LSTM(128))\n",
"model.add(Dense(1, activation='sigmoid'))\n",
"\n",
"es = EarlyStopping(monitor='val_loss', mode='min', verbose=1, patience=4)\n",
"mc = ModelCheckpoint('best_model.h5', monitor='val_acc', mode='max', verbose=1, save_best_only=True)\n",
"\n",
"X_train = np.array(X_train)\n",
"Y_train = np.array(Y_train)\n",
"X_test = np.array(X_test)\n",
"Y_test = np.array(Y_test)\n",
"\n",
"model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['acc'])\n",
"model.fit(X_train, Y_train, validation_data=(X_test, Y_test), epochs=5, batch_size=64, callbacks=[es, mc])\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}