Skip to content

Commit c9ad558

Browse files
committed
Update for latest MEAP, PyTorch v1.3.0, p2ch14.
1 parent f5d199c commit c9ad558

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+9122
-2196
lines changed

p1ch3/1_tensors.ipynb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@
510510
}
511511
],
512512
"source": [
513-
"points = torch.tensor([[4.0, 1.0], [5.0, 3.0], [2.0, 1.0]])\n",
514513
"second_point = points[1]\n",
515514
"second_point.size()"
516515
]
@@ -727,9 +726,9 @@
727726
}
728727
],
729728
"source": [
730-
"some_tensor = torch.ones(3, 4, 5)\n",
731-
"some_tensor_t = some_tensor.transpose(0, 2)\n",
732-
"some_tensor.shape"
729+
"some_t = torch.ones(3, 4, 5)\n",
730+
"transpose_t = some_t.transpose(0, 2)\n",
731+
"some_t.shape"
733732
]
734733
},
735734
{
@@ -749,7 +748,7 @@
749748
}
750749
],
751750
"source": [
752-
"some_tensor_t.shape"
751+
"transpose_t.shape"
753752
]
754753
},
755754
{
@@ -769,7 +768,7 @@
769768
}
770769
],
771770
"source": [
772-
"some_tensor.stride()"
771+
"some_t.stride()"
773772
]
774773
},
775774
{
@@ -789,7 +788,7 @@
789788
}
790789
],
791790
"source": [
792-
"some_tensor_t.stride()"
791+
"transpose_t.stride()"
793792
]
794793
},
795794
{
@@ -1179,7 +1178,7 @@
11791178
"source": [
11801179
"f = h5py.File('../data/p1ch3/ourpoints.hdf5', 'r')\n",
11811180
"dset = f['coords']\n",
1182-
"last_points = dset[1:]"
1181+
"last_points = dset[-2:]"
11831182
]
11841183
},
11851184
{
@@ -1188,7 +1187,7 @@
11881187
"metadata": {},
11891188
"outputs": [],
11901189
"source": [
1191-
"last_points = torch.from_numpy(dset[1:])\n",
1190+
"last_points = torch.from_numpy(dset[-2:])\n",
11921191
"f.close()"
11931192
]
11941193
},

p1ch4/2_time_series_bikes.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
"source": [
151151
"weather_onehot.scatter_(\n",
152152
" dim=1, \n",
153-
" index=first_day[:,9].unsqueeze(1) - 1, # <1>\n",
153+
" index=first_day[:,9].unsqueeze(1).long() - 1, # <1>\n",
154154
" value=1.0)"
155155
]
156156
},

p1ch4/3_text_jane_austin.ipynb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
}
6161
],
6262
"source": [
63-
"letter_tensor = torch.zeros(len(line), 128) # <1> \n",
64-
"letter_tensor.shape"
63+
"letter_t = torch.zeros(len(line), 128) # <1> \n",
64+
"letter_t.shape"
6565
]
6666
},
6767
{
@@ -72,7 +72,7 @@
7272
"source": [
7373
"for i, letter in enumerate(line.lower().strip()):\n",
7474
" letter_index = ord(letter) if ord(letter) < 128 else 0 # <1>\n",
75-
" letter_tensor[i][letter_index] = 1"
75+
" letter_t[i][letter_index] = 1"
7676
]
7777
},
7878
{
@@ -161,13 +161,13 @@
161161
}
162162
],
163163
"source": [
164-
"word_tensor = torch.zeros(len(words_in_line), len(word2index_dict))\n",
164+
"word_t = torch.zeros(len(words_in_line), len(word2index_dict))\n",
165165
"for i, word in enumerate(words_in_line):\n",
166166
" word_index = word2index_dict[word]\n",
167-
" word_tensor[i][word_index] = 1\n",
167+
" word_t[i][word_index] = 1\n",
168168
" print('{:2} {:4} {}'.format(i, word_index, word))\n",
169169
" \n",
170-
"print(word_tensor.shape)\n"
170+
"print(word_t.shape)\n"
171171
]
172172
},
173173
{
@@ -187,8 +187,8 @@
187187
}
188188
],
189189
"source": [
190-
"word_tensor = word_tensor.unsqueeze(1)\n",
191-
"word_tensor.shape"
190+
"word_t = word_t.unsqueeze(1)\n",
191+
"word_t.shape"
192192
]
193193
},
194194
{

p1ch4/4_audio_chirp.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@
167167
],
168168
"source": [
169169
"sp_left = sp_right = sp_arr\n",
170-
"sp_left_tensor = torch.from_numpy(sp_left)\n",
171-
"sp_right_tensor = torch.from_numpy(sp_right)\n",
172-
"sp_left_tensor.shape, sp_right_tensor.shape"
170+
"sp_left_t = torch.from_numpy(sp_left)\n",
171+
"sp_right_t = torch.from_numpy(sp_right)\n",
172+
"sp_left_t.shape, sp_right_t.shape"
173173
]
174174
},
175175
{
@@ -197,8 +197,8 @@
197197
}
198198
],
199199
"source": [
200-
"sp_tensor = torch.stack((sp_left_tensor, sp_right_tensor), dim=0)\n",
201-
"sp_tensor.shape"
200+
"sp_t = torch.stack((sp_left_t, sp_right_t), dim=0)\n",
201+
"sp_t.shape"
202202
]
203203
},
204204
{

p1ch4/5_image_dog.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"import os\n",
6464
"\n",
6565
"data_dir = '../data/p1ch4/image-cats/'\n",
66-
"filenames = [name for name in os.listdir(data_dir) if os.path.splitext(name) == '.png']\n",
66+
"filenames = [name for name in os.listdir(data_dir) if os.path.splitext(name)[-1] == '.png']\n",
6767
"for i, filename in enumerate(filenames):\n",
6868
" img_arr = imageio.imread(filename)\n",
6969
" batch[i] = torch.transpose(torch.from_numpy(img_arr), 0, 2)"

p1ch6/1_neural_networks.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,10 @@
262262
"source": [
263263
"def training_loop(n_epochs, optimizer, model, loss_fn, t_u_train, t_u_val, t_c_train, t_c_val):\n",
264264
" for epoch in range(1, n_epochs + 1):\n",
265-
" t_p_train = model(t_un_train) # <1>\n",
265+
" t_p_train = model(t_u_train) # <1>\n",
266266
" loss_train = loss_fn(t_p_train, t_c_train)\n",
267267
"\n",
268-
" t_p_val = model(t_un_val) # <1>\n",
268+
" t_p_val = model(t_u_val) # <1>\n",
269269
" loss_val = loss_fn(t_p_val, t_c_val)\n",
270270
" \n",
271271
" optimizer.zero_grad()\n",

p1ch7/1_datasets.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
],
4343
"source": [
4444
"from torchvision import datasets\n",
45-
"data_path = '../data-unversioned/p1ch6/''\n",
45+
"data_path = '../data-unversioned/p1ch6/'\n",
4646
"cifar10 = datasets.CIFAR10(data_path, train=True, download=True)\n",
4747
"cifar10_val = datasets.CIFAR10(data_path, train=False, download=True)"
4848
]

p1ch8/1_convolution.ipynb

Lines changed: 328 additions & 68 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)