|
21 | 21 | "name": "stdout", |
22 | 22 | "output_type": "stream", |
23 | 23 | "text": [ |
24 | | - "1.0.0 cuda\n" |
| 24 | + "1.1.0 cuda\n" |
25 | 25 | ] |
26 | 26 | } |
27 | 27 | ], |
|
39 | 39 | "sys.path.append(\"..\") \n", |
40 | 40 | "import d2lzh_pytorch as d2l\n", |
41 | 41 | "\n", |
42 | | - "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"7\"\n", |
| 42 | + "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"2\"\n", |
43 | 43 | "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\n", |
44 | 44 | "\n", |
45 | | - "DATA_ROOT = \"/S1/CSCL/tangss/Datasets\"\n", |
| 45 | + "DATA_ROOT = \"/data1/tangss/Datasets\"\n", |
46 | 46 | "\n", |
47 | 47 | "print(torch.__version__, device)" |
48 | 48 | ] |
|
88 | 88 | "name": "stderr", |
89 | 89 | "output_type": "stream", |
90 | 90 | "text": [ |
91 | | - "100%|██████████| 12500/12500 [00:04<00:00, 2930.03it/s]\n", |
92 | | - "100%|██████████| 12500/12500 [00:04<00:00, 3008.48it/s]\n", |
93 | | - "100%|██████████| 12500/12500 [00:03<00:00, 3365.08it/s]\n", |
94 | | - "100%|██████████| 12500/12500 [00:03<00:00, 3305.63it/s]\n" |
| 91 | + "100%|██████████| 12500/12500 [00:00<00:00, 34211.42it/s]\n", |
| 92 | + "100%|██████████| 12500/12500 [00:00<00:00, 38506.48it/s]\n", |
| 93 | + "100%|██████████| 12500/12500 [00:00<00:00, 31316.61it/s]\n", |
| 94 | + "100%|██████████| 12500/12500 [00:00<00:00, 29664.72it/s]\n" |
95 | 95 | ] |
96 | 96 | } |
97 | 97 | ], |
|
108 | 108 | " random.shuffle(data)\n", |
109 | 109 | " return data\n", |
110 | 110 | "\n", |
111 | | - "train_data, test_data = read_imdb('train'), read_imdb('test')" |
| 111 | + "data_root = os.path.join(DATA_ROOT, \"aclImdb\")\n", |
| 112 | + "train_data, test_data = read_imdb('train', data_root), read_imdb('test', data_root)" |
112 | 113 | ] |
113 | 114 | }, |
114 | 115 | { |
|
152 | 153 | { |
153 | 154 | "data": { |
154 | 155 | "text/plain": [ |
155 | | - "('# words in vocab:', 46151)" |
| 156 | + "('# words in vocab:', 46152)" |
156 | 157 | ] |
157 | 158 | }, |
158 | 159 | "execution_count": 5, |
|
330 | 331 | "ExecuteTime": { |
331 | 332 | "end_time": "2019-07-03T04:26:47.895604Z", |
332 | 333 | "start_time": "2019-07-03T04:26:47.685801Z" |
333 | | - }, |
334 | | - "collapsed": true |
| 334 | + } |
335 | 335 | }, |
336 | 336 | "outputs": [], |
337 | 337 | "source": [ |
|
345 | 345 | "ExecuteTime": { |
346 | 346 | "end_time": "2019-07-03T04:26:48.102388Z", |
347 | 347 | "start_time": "2019-07-03T04:26:47.897582Z" |
348 | | - }, |
349 | | - "collapsed": true |
| 348 | + } |
350 | 349 | }, |
351 | | - "outputs": [], |
| 350 | + "outputs": [ |
| 351 | + { |
| 352 | + "name": "stdout", |
| 353 | + "output_type": "stream", |
| 354 | + "text": [ |
| 355 | + "There are 21202 oov words.\n" |
| 356 | + ] |
| 357 | + } |
| 358 | + ], |
352 | 359 | "source": [ |
353 | 360 | "def load_pretrained_embedding(words, pretrained_vocab):\n", |
354 | 361 | " \"\"\"从预训练好的vocab中提取出words对应的词向量\"\"\"\n", |
|
359 | 366 | " idx = pretrained_vocab.stoi[word]\n", |
360 | 367 | " embed[i, :] = pretrained_vocab.vectors[idx]\n", |
361 | 368 | " except KeyError:\n", |
362 | | - " oov_count += 0\n", |
| 369 | + " oov_count += 1\n", |
363 | 370 | " if oov_count > 0:\n", |
364 | | - " print(\"There are %d oov words.\")\n", |
| 371 | + " print(\"There are %d oov words.\" % oov_count)\n", |
365 | 372 | " return embed\n", |
366 | 373 | "\n", |
367 | 374 | "net.embedding.weight.data.copy_(load_pretrained_embedding(vocab.itos, glove_vocab))\n", |
|
390 | 397 | "output_type": "stream", |
391 | 398 | "text": [ |
392 | 399 | "training on cuda\n", |
393 | | - "epoch 1, loss 0.5759, train acc 0.666, test acc 0.832, time 250.8 sec\n", |
394 | | - "epoch 2, loss 0.1785, train acc 0.842, test acc 0.852, time 253.3 sec\n", |
395 | | - "epoch 3, loss 0.1042, train acc 0.866, test acc 0.856, time 253.7 sec\n", |
396 | | - "epoch 4, loss 0.0682, train acc 0.888, test acc 0.868, time 254.2 sec\n", |
397 | | - "epoch 5, loss 0.0483, train acc 0.901, test acc 0.862, time 251.4 sec\n" |
| 400 | + "epoch 1, loss 0.5415, train acc 0.719, test acc 0.819, time 48.7 sec\n", |
| 401 | + "epoch 2, loss 0.1897, train acc 0.837, test acc 0.852, time 53.0 sec\n", |
| 402 | + "epoch 3, loss 0.1105, train acc 0.857, test acc 0.844, time 51.6 sec\n", |
| 403 | + "epoch 4, loss 0.0719, train acc 0.881, test acc 0.865, time 52.1 sec\n", |
| 404 | + "epoch 5, loss 0.0519, train acc 0.894, test acc 0.852, time 51.2 sec\n" |
398 | 405 | ] |
399 | 406 | } |
400 | 407 | ], |
|
488 | 495 | ], |
489 | 496 | "metadata": { |
490 | 497 | "kernelspec": { |
491 | | - "display_name": "Python [conda env:py36]", |
| 498 | + "display_name": "Python [conda env:py36_pytorch]", |
492 | 499 | "language": "python", |
493 | | - "name": "conda-env-py36-py" |
| 500 | + "name": "conda-env-py36_pytorch-py" |
494 | 501 | }, |
495 | 502 | "language_info": { |
496 | 503 | "codemirror_mode": { |
|
502 | 509 | "name": "python", |
503 | 510 | "nbconvert_exporter": "python", |
504 | 511 | "pygments_lexer": "ipython3", |
505 | | - "version": "3.6.3" |
| 512 | + "version": "3.6.2" |
506 | 513 | }, |
507 | 514 | "varInspector": { |
508 | 515 | "cols": { |
|
0 commit comments