Skip to content

Commit 8566ac5

Browse files
authored
Small updates for NCAS summer school improving background info (#24)
* some comments on notebooks to help students * make worked examples consistent with the additional commentary added in the exercises * typo fix for consistency
1 parent 82e0c86 commit 8566ac5

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

exercises/01_penguin_classification.ipynb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@
105105
" train=True,\n",
106106
")\n",
107107
"\n",
108+
"\n",
108109
"for features, target in data_set:\n",
110+
" # print the features and targets here\n",
109111
" pass"
110112
]
111113
},
@@ -124,7 +126,7 @@
124126
"source": [
125127
"### Task 4: Applying transforms to the data\n",
126128
"\n",
127-
"A common way of transforming inputs to neural networks is to apply a series of transforms using ``torchvision.transforms.Compose``. The ``Compose`` object takes a list of callable objects and applies them to the incoming data.\n",
129+
"A common way of transforming inputs to neural networks is to apply a series of transforms using ``torchvision.transforms.Compose``. The [``Compose``](https://pytorch.org/vision/stable/generated/torchvision.transforms.Compose.html) object takes a list of callable objects (i.e., functions) and applies them to the incoming data.\n",
128130
"\n",
129131
"These transforms can be very useful for mapping between file paths and tensors of images, etc.\n",
130132
"\n",
@@ -141,8 +143,12 @@
141143
"outputs": [],
142144
"source": [
143145
"from torchvision.transforms import Compose\n",
146+
"# import some useful functions here, see https://pytorch.org/docs/stable/torch.html\n",
147+
"# where `tensor` and `eye` are used for constructing tensors,\n",
148+
"# and using a lower-precision float32 is advised for performance\n",
149+
"from torch import tensor, eye, float32 \n",
144150
"\n",
145-
"# Apply the transforms we need to the PenguinDataset to get out inputs\n",
151+
"# Apply the transforms we need to the PenguinDataset to get out input\n",
146152
"# targets as Tensors."
147153
]
148154
},
@@ -154,7 +160,7 @@
154160
"\n",
155161
"- Once we have created a ``Dataset`` object, we wrap it in a ``DataLoader``.\n",
156162
" - The ``DataLoader`` object allows us to put our inputs and targets in mini-batches, which makes for more efficient training.\n",
157-
" - Note: rather than supplying one input-target pair to the model at a time, we supply \"mini-batches\" of these data at once.\n",
163+
" - Note: rather than supplying one input-target pair to the model at a time, we supply \"mini-batches\" of these data at once (typically a small power of 2, like 16 or 32).\n",
158164
" - The number of items we supply at once is called the batch size.\n",
159165
" - The ``DataLoader`` can also randomly shuffle the data each epoch (when training).\n",
160166
" - It allows us to load different mini-batches in parallel, which can be very useful for larger datasets and images that can't all fit in memory at once.\n",

src/ml_workshop/_penguins.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def _load_penguin_data() -> DataFrame:
109109
.sort_values(by=sorted(data.keys()))
110110
.reset_index(drop=True)
111111
)
112+
# Transform the sex field into a float, with male represented by 1.0, female by 0.0
112113
data.sex = (data.sex == "male").astype(float)
113114
return data
114115

worked-solutions/01_penguin_classification_solutions.ipynb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
"source": [
215215
"### Task 4: Applying transforms to the data\n",
216216
"\n",
217-
"A common way of transforming inputs to neural networks is to apply a series of transforms using ``torchvision.transforms.Compose``. The ``Compose`` object takes a list of callable objects and applies them to the incoming data.\n",
217+
"A common way of transforming inputs to neural networks is to apply a series of transforms using ``torchvision.transforms.Compose``. The [``Compose``](https://pytorch.org/vision/stable/generated/torchvision.transforms.Compose.html) object takes a list of callable objects and applies them to the incoming data.\n",
218218
"\n",
219219
"These transforms can be very useful for mapping between file paths and tensors of images, etc.\n",
220220
"\n",
@@ -242,11 +242,14 @@
242242
}
243243
],
244244
"source": [
245-
"from torch import tensor, float32, eye\n",
246245
"from torchvision.transforms import Compose\n",
246+
"# import some useful functions here, see https://pytorch.org/docs/stable/torch.html\n",
247+
"# where `tensor` and `eye` are used for constructing tensors,\n",
248+
"# and using a lower-precision float32 is advised for performance\n",
249+
"from torch import tensor, float32, eye\n",
247250
"\n",
248251
"\n",
249-
"# Apply the transforms we need to the PenguinDataset to get out inputs\n",
252+
"# Apply the transforms we need to the PenguinDataset to get out input\n",
250253
"# targets as Tensors.\n",
251254
"\n",
252255
"\n",
@@ -321,7 +324,7 @@
321324
"\n",
322325
"- Once we have created a ``Dataset`` object, we wrap it in a ``DataLoader``.\n",
323326
" - The ``DataLoader`` object allows us to put our inputs and targets in mini-batches, which makes for more efficient training.\n",
324-
" - Note: rather than supplying one input-target pair to the model at a time, we supply \"mini-batches\" of these data at once.\n",
327+
" - Note: rather than supplying one input-target pair to the model at a time, we supply \"mini-batches\" of these data at once (typically a small power of 2, like 16 or 32).\n",
325328
" - The number of items we supply at once is called the batch size.\n",
326329
" - The ``DataLoader`` can also randomly shuffle the data each epoch (when training).\n",
327330
" - It allows us to load different mini-batches in parallel, which can be very useful for larger datasets and images that can't all fit in memory at once.\n",

0 commit comments

Comments
 (0)