├── 01_intro.ipynb
├── 02_production.ipynb
├── 03_ethics.ipynb
├── 04_mnist_basics.ipynb
├── 05_pet_breeds.ipynb
├── 06_multicat.ipynb
├── 07_sizing_and_tta.ipynb
├── 08_collab.ipynb
├── 09_collab.ipynb
├── 09_tabular.ipynb
├── 10_nlp.ipynb
├── 10_tabular.ipynb
├── 11_nlp.ipynb
├── 11_nlp_dive.ipynb
├── 12_better_rnn.ipynb
├── 12_nlp_dive.ipynb
├── 13_better_rnn.ipynb
├── 13_convolutions.ipynb
├── 14_convolutions.ipynb
├── 14_deep_conv.ipynb
├── 15_deep_conv.ipynb
├── 15_resnet.ipynb
├── 16_arch_details.ipynb
├── 16_resnet.ipynb
├── 17_accel_sgd.ipynb
├── 17_arch_details.ipynb
├── 18_accel_sgd.ipynb
├── 18_callbacks.ipynb
├── 19_callbacks.ipynb
├── 19_foundations.ipynb
├── 20_foundations.ipynb
├── 20_trainingloop.ipynb
├── 21_CAM.ipynb
├── 21_trainingloop.ipynb
├── 22_CAM.ipynb
├── 22_conclusion.ipynb
├── 23_conclusion.ipynb
├── README.md
├── app_blog.ipynb
├── app_jupyter.ipynb
├── images
├── 0_jupyter.png
├── Dropout.png
├── Dropout1.png
├── LSTM.png
├── analytics_chain.gif
├── att_00000.png
├── att_00001.png
├── att_00002.png
├── att_00003.png
├── att_00004.png
├── att_00005.png
├── att_00006.png
├── att_00007.png
├── att_00008.png
├── att_00009.png
├── att_00010.png
├── att_00011.png
├── att_00012.png
├── att_00013.png
├── att_00014.png
├── att_00015.png
├── att_00016.png
├── att_00017.png
├── att_00018.png
├── att_00019.png
├── att_00020.png
├── att_00021.png
├── att_00022.png
├── att_00023.png
├── att_00024.png
├── att_00025.png
├── att_00026.png
├── att_00027.png
├── att_00028.png
├── att_00029.png
├── att_00030.png
├── att_00031.png
├── att_00032.png
├── att_00033.png
├── att_00034.png
├── att_00035.png
├── att_00036.png
├── att_00037.png
├── att_00038.png
├── att_00039.png
├── att_00040.png
├── att_00041.png
├── att_00042.png
├── att_00043.png
├── att_00044.png
├── att_00045.png
├── att_00046.png
├── att_00047.png
├── att_00048.png
├── att_00049.png
├── att_00050.png
├── att_00051.png
├── att_00052.png
├── att_00053.png
├── att_00054.png
├── att_00055.png
├── att_00056.png
├── att_00057.png
├── att_00058.png
├── att_00059.png
├── att_00060.png
├── att_00061.png
├── att_00062.png
├── att_00063.png
├── att_00064.png
├── att_00065.png
├── att_00066.png
├── att_00067.png
├── att_00068.png
├── att_00069.png
├── att_00070.png
├── att_00071.png
├── chapter1_add.png
├── chapter1_busy.png
├── chapter1_cat_example.jpg
├── chapter1_markdown.png
├── chapter1_new_notebook.png
├── chapter1_run.png
├── chapter1_save.png
├── chapter1_terminal.png
├── chapter2_bouncing.PNG
├── chapter2_bouncy.svg
├── chapter2_derivative.PNG
├── chapter2_div.svg
├── chapter2_layer1and2.PNG
├── chapter2_layer3.PNG
├── chapter2_layer4and5.PNG
├── chapter2_perfect.svg
├── chapter2_sgd.PNG
├── chapter2_small.svg
├── chapter4_1cycle_schedule.png
├── chapter4_overfit.png
├── chapter7_neuron.png
├── chapter9_baseconv.svg
├── chapter9_bottleneck.png
├── chapter9_cat_conv.png
├── chapter9_conv_basic.png
├── chapter9_conv_pad.png
├── chapter9_conv_rgb.png
├── chapter9_conv_stride.png
├── chapter9_loss_landscape.png
├── chapter9_nopadconv.svg
├── chapter9_padconv.svg
├── chapter9_rgb_conv_stack.svg
├── chapter9_rgbconv.svg
├── chapter9_skip_connection.png
├── chapter9_strideconv.svg
├── colorful_dist.jpeg
├── colorful_summ.png
├── cover.png
├── driver_phone.png
├── driver_phone2.png
├── drivetrain-approach.png
├── ethics
│ ├── image1.png
│ ├── image10.png
│ ├── image11.png
│ ├── image12.png
│ ├── image13.png
│ ├── image14.png
│ ├── image15.jpeg
│ ├── image16.png
│ ├── image17.jpeg
│ ├── image17.png
│ ├── image18.jpeg
│ ├── image2.png
│ ├── image3.jpeg
│ ├── image4.png
│ ├── image5.png
│ ├── image6.png
│ ├── image7.png
│ ├── image8.png
│ └── image9.jpeg
├── fast_template
│ ├── image1.png
│ ├── image10.png
│ ├── image11.png
│ ├── image12.png
│ ├── image13.png
│ ├── image14.png
│ ├── image15.png
│ ├── image16.png
│ ├── image2.png
│ ├── image3.png
│ ├── image4.png
│ ├── image5.png
│ ├── image6.png
│ ├── image7.png
│ ├── image8.png
│ └── image9.png
├── fltscale.svg
├── gitblog
│ ├── commit.png
│ ├── image1.png
│ ├── image2.png
│ ├── image3.png
│ ├── image4.png
│ └── image5.png
├── grad_illustration.svg
├── grizzly.jpg
├── healthy_skin.gif
├── matmul2.svg
├── mnist3_xl.gif
├── mnist3_xl_300.gif
├── mnist3_xl_custom.gif
├── pratchett.png
├── profit_drivers.gif
├── sklearn_features.png
├── tarsier.png
├── timeseries1.png
├── timeseries2.png
├── timeseries3.png
├── turing.jpg
└── turing_300.jpg
└── utils.py
/03_ethics.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Data Ethics"
8 | ]
9 | },
10 | {
11 | "cell_type": "markdown",
12 | "metadata": {},
13 | "source": [
14 | "## Acknowledgement: Dr Rachel Thomas"
15 | ]
16 | },
17 | {
18 | "cell_type": "markdown",
19 | "metadata": {},
20 | "source": [
21 | "## Introduction to data ethics"
22 | ]
23 | },
24 | {
25 | "cell_type": "markdown",
26 | "metadata": {},
27 | "source": [
28 | "## Getting started with some examples"
29 | ]
30 | },
31 | {
32 | "cell_type": "markdown",
33 | "metadata": {},
34 | "source": [
35 | "### Bugs and recourse: Buggy algorithm used for healthcare benefits"
36 | ]
37 | },
38 | {
39 | "cell_type": "markdown",
40 | "metadata": {},
41 | "source": [
42 | "### Feedback loops: YouTube's recommendation system"
43 | ]
44 | },
45 | {
46 | "cell_type": "markdown",
47 | "metadata": {},
48 | "source": [
49 | "### Bias: Professor Lantanya Sweeney \"arrested\""
50 | ]
51 | },
52 | {
53 | "cell_type": "markdown",
54 | "metadata": {},
55 | "source": [
56 | "## So what?"
57 | ]
58 | },
59 | {
60 | "cell_type": "markdown",
61 | "metadata": {},
62 | "source": [
63 | "## Integrating machine learning with product design"
64 | ]
65 | },
66 | {
67 | "cell_type": "markdown",
68 | "metadata": {},
69 | "source": [
70 | "## Topics in Data Ethics"
71 | ]
72 | },
73 | {
74 | "cell_type": "markdown",
75 | "metadata": {},
76 | "source": [
77 | "## Errors and recourse"
78 | ]
79 | },
80 | {
81 | "cell_type": "markdown",
82 | "metadata": {},
83 | "source": [
84 | "## Feedback loops"
85 | ]
86 | },
87 | {
88 | "cell_type": "markdown",
89 | "metadata": {},
90 | "source": [
91 | "### Bias"
92 | ]
93 | },
94 | {
95 | "cell_type": "markdown",
96 | "metadata": {},
97 | "source": [
98 | "#### Historical bias"
99 | ]
100 | },
101 | {
102 | "cell_type": "markdown",
103 | "metadata": {},
104 | "source": [
105 | "#### Measurement bias"
106 | ]
107 | },
108 | {
109 | "cell_type": "markdown",
110 | "metadata": {},
111 | "source": [
112 | "#### Aggregation Bias"
113 | ]
114 | },
115 | {
116 | "cell_type": "markdown",
117 | "metadata": {},
118 | "source": [
119 | "#### Representation Bias"
120 | ]
121 | },
122 | {
123 | "cell_type": "markdown",
124 | "metadata": {},
125 | "source": [
126 | "### Addressing different types of bias"
127 | ]
128 | },
129 | {
130 | "cell_type": "markdown",
131 | "metadata": {},
132 | "source": [
133 | "### Humans are biased, so does algorithmic bias matter?"
134 | ]
135 | },
136 | {
137 | "cell_type": "markdown",
138 | "metadata": {},
139 | "source": [
140 | "### Data contains errors"
141 | ]
142 | },
143 | {
144 | "cell_type": "markdown",
145 | "metadata": {},
146 | "source": [
147 | "## Disinformation"
148 | ]
149 | },
150 | {
151 | "cell_type": "markdown",
152 | "metadata": {},
153 | "source": [
154 | "## What to do"
155 | ]
156 | },
157 | {
158 | "cell_type": "markdown",
159 | "metadata": {},
160 | "source": [
161 | "### Analyze a project you are working on"
162 | ]
163 | },
164 | {
165 | "cell_type": "markdown",
166 | "metadata": {},
167 | "source": [
168 | "### Processes to implement"
169 | ]
170 | },
171 | {
172 | "cell_type": "markdown",
173 | "metadata": {},
174 | "source": [
175 | "#### Ethical Lenses"
176 | ]
177 | },
178 | {
179 | "cell_type": "markdown",
180 | "metadata": {},
181 | "source": [
182 | "### Fairness, accountability, and transparency"
183 | ]
184 | },
185 | {
186 | "cell_type": "markdown",
187 | "metadata": {},
188 | "source": [
189 | "### Role of Policy"
190 | ]
191 | },
192 | {
193 | "cell_type": "markdown",
194 | "metadata": {},
195 | "source": [
196 | "### The power of diversity"
197 | ]
198 | },
199 | {
200 | "cell_type": "markdown",
201 | "metadata": {},
202 | "source": [
203 | "### Conclusion"
204 | ]
205 | },
206 | {
207 | "cell_type": "markdown",
208 | "metadata": {},
209 | "source": [
210 | "## Questionnaire"
211 | ]
212 | },
213 | {
214 | "cell_type": "markdown",
215 | "metadata": {},
216 | "source": [
217 | "### Further research:"
218 | ]
219 | },
220 | {
221 | "cell_type": "markdown",
222 | "metadata": {},
223 | "source": [
224 | "## Section 1: that's a wrap!"
225 | ]
226 | },
227 | {
228 | "cell_type": "code",
229 | "execution_count": null,
230 | "metadata": {},
231 | "outputs": [],
232 | "source": []
233 | }
234 | ],
235 | "metadata": {
236 | "jupytext": {
237 | "split_at_heading": true
238 | },
239 | "kernelspec": {
240 | "display_name": "Python 3",
241 | "language": "python",
242 | "name": "python3"
243 | },
244 | "language_info": {
245 | "codemirror_mode": {
246 | "name": "ipython",
247 | "version": 3
248 | },
249 | "file_extension": ".py",
250 | "mimetype": "text/x-python",
251 | "name": "python",
252 | "nbconvert_exporter": "python",
253 | "pygments_lexer": "ipython3",
254 | "version": "3.7.4"
255 | }
256 | },
257 | "nbformat": 4,
258 | "nbformat_minor": 2
259 | }
260 |
--------------------------------------------------------------------------------
/13_better_rnn.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "#hide\n",
10 | "from utils import *"
11 | ]
12 | },
13 | {
14 | "cell_type": "markdown",
15 | "metadata": {},
16 | "source": [
17 | "# Making our RNN state of the art"
18 | ]
19 | },
20 | {
21 | "cell_type": "code",
22 | "execution_count": 2,
23 | "metadata": {},
24 | "outputs": [],
25 | "source": [
26 | "#hide\n",
27 | "from fastai2.text.all import *\n",
28 | "path = untar_data(URLs.HUMAN_NUMBERS)\n",
29 | "lines = L()\n",
30 | "with open(path/'train.txt') as f: lines += L(*f.readlines())\n",
31 | "with open(path/'valid.txt') as f: lines += L(*f.readlines())\n",
32 | "text = ' . '.join([l.strip() for l in lines])\n",
33 | "tokens = text.split(' ')\n",
34 | "vocab = L(*tokens).unique()\n",
35 | "word2idx = {w:i for i,w in enumerate(vocab)}\n",
36 | "nums = L(word2idx[i] for i in tokens)\n",
37 | "\n",
38 | "def group_chunks(ds, bs):\n",
39 | " m = len(ds) // bs\n",
40 | " new_ds = L()\n",
41 | " for i in range(m): new_ds += L(ds[i + m*j] for j in range(bs))\n",
42 | " return new_ds"
43 | ]
44 | },
45 | {
46 | "cell_type": "code",
47 | "execution_count": 3,
48 | "metadata": {},
49 | "outputs": [],
50 | "source": [
51 | "sl,bs = 16,64\n",
52 | "seqs = L((tensor(nums[i:i+sl]), tensor(nums[i+1:i+sl+1])) for i in range(0,len(nums)-sl-1,sl))\n",
53 | "cut = int(len(seqs) * 0.8)\n",
54 | "dls = DataLoaders.from_dsets(group_chunks(seqs[:cut], bs), group_chunks(seqs[cut:], bs), bs=bs, drop_last=True, shuffle=False)"
55 | ]
56 | },
57 | {
58 | "cell_type": "markdown",
59 | "metadata": {},
60 | "source": [
61 | "## Multilayer RNNs"
62 | ]
63 | },
64 | {
65 | "cell_type": "markdown",
66 | "metadata": {},
67 | "source": [
68 | "### The model"
69 | ]
70 | },
71 | {
72 | "cell_type": "code",
73 | "execution_count": null,
74 | "metadata": {},
75 | "outputs": [],
76 | "source": [
77 | "class LMModel5(Module):\n",
78 | " def __init__(self, vocab_sz, n_hidden, n_layers):\n",
79 | " self.i_h = nn.Embedding(vocab_sz, n_hidden)\n",
80 | " self.rnn = nn.RNN(n_hidden, n_hidden, n_layers, batch_first=True)\n",
81 | " self.h_o = nn.Linear(n_hidden, vocab_sz)\n",
82 | " self.h = torch.zeros(n_layers, bs, n_hidden)\n",
83 | " \n",
84 | " def forward(self, x):\n",
85 | " res,h = self.rnn(self.i_h(x), self.h)\n",
86 | " self.h = h.detach()\n",
87 | " return self.h_o(res)\n",
88 | " \n",
89 | " def reset(self): self.h.zero_()"
90 | ]
91 | },
92 | {
93 | "cell_type": "code",
94 | "execution_count": null,
95 | "metadata": {},
96 | "outputs": [
97 | {
98 | "data": {
99 | "text/html": [
100 | "
\n",
101 | " \n",
102 | " \n",
103 | " epoch | \n",
104 | " train_loss | \n",
105 | " valid_loss | \n",
106 | " accuracy | \n",
107 | " time | \n",
108 | "
\n",
109 | " \n",
110 | " \n",
111 | " \n",
112 | " 0 | \n",
113 | " 3.048115 | \n",
114 | " 2.622384 | \n",
115 | " 0.434001 | \n",
116 | " 00:02 | \n",
117 | "
\n",
118 | " \n",
119 | " 1 | \n",
120 | " 2.136388 | \n",
121 | " 1.763967 | \n",
122 | " 0.471191 | \n",
123 | " 00:02 | \n",
124 | "
\n",
125 | " \n",
126 | " 2 | \n",
127 | " 1.689246 | \n",
128 | " 1.898718 | \n",
129 | " 0.364746 | \n",
130 | " 00:02 | \n",
131 | "
\n",
132 | " \n",
133 | " 3 | \n",
134 | " 1.443545 | \n",
135 | " 1.747440 | \n",
136 | " 0.480387 | \n",
137 | " 00:01 | \n",
138 | "
\n",
139 | " \n",
140 | " 4 | \n",
141 | " 1.271023 | \n",
142 | " 1.870939 | \n",
143 | " 0.479980 | \n",
144 | " 00:02 | \n",
145 | "
\n",
146 | " \n",
147 | " 5 | \n",
148 | " 1.101259 | \n",
149 | " 1.794428 | \n",
150 | " 0.495361 | \n",
151 | " 00:02 | \n",
152 | "
\n",
153 | " \n",
154 | " 6 | \n",
155 | " 0.948380 | \n",
156 | " 1.769644 | \n",
157 | " 0.511149 | \n",
158 | " 00:02 | \n",
159 | "
\n",
160 | " \n",
161 | " 7 | \n",
162 | " 0.822373 | \n",
163 | " 1.800406 | \n",
164 | " 0.535400 | \n",
165 | " 00:01 | \n",
166 | "
\n",
167 | " \n",
168 | " 8 | \n",
169 | " 0.731188 | \n",
170 | " 1.914065 | \n",
171 | " 0.522461 | \n",
172 | " 00:01 | \n",
173 | "
\n",
174 | " \n",
175 | " 9 | \n",
176 | " 0.662659 | \n",
177 | " 1.987547 | \n",
178 | " 0.525798 | \n",
179 | " 00:02 | \n",
180 | "
\n",
181 | " \n",
182 | " 10 | \n",
183 | " 0.613053 | \n",
184 | " 2.022102 | \n",
185 | " 0.527751 | \n",
186 | " 00:02 | \n",
187 | "
\n",
188 | " \n",
189 | " 11 | \n",
190 | " 0.577007 | \n",
191 | " 2.068472 | \n",
192 | " 0.526530 | \n",
193 | " 00:02 | \n",
194 | "
\n",
195 | " \n",
196 | " 12 | \n",
197 | " 0.551144 | \n",
198 | " 2.113533 | \n",
199 | " 0.521566 | \n",
200 | " 00:02 | \n",
201 | "
\n",
202 | " \n",
203 | " 13 | \n",
204 | " 0.535356 | \n",
205 | " 2.123089 | \n",
206 | " 0.523600 | \n",
207 | " 00:02 | \n",
208 | "
\n",
209 | " \n",
210 | " 14 | \n",
211 | " 0.526783 | \n",
212 | " 2.122413 | \n",
213 | " 0.524333 | \n",
214 | " 00:02 | \n",
215 | "
\n",
216 | " \n",
217 | "
"
218 | ],
219 | "text/plain": [
220 | ""
221 | ]
222 | },
223 | "metadata": {},
224 | "output_type": "display_data"
225 | }
226 | ],
227 | "source": [
228 | "learn = Learner(dls, LMModel5(len(vocab), 64, 2), loss_func=CrossEntropyLossFlat(), metrics=accuracy, cbs=ModelReseter)\n",
229 | "learn.fit_one_cycle(15, 3e-3)"
230 | ]
231 | },
232 | {
233 | "cell_type": "markdown",
234 | "metadata": {},
235 | "source": [
236 | "### Handling exploding or disappearing activations"
237 | ]
238 | },
239 | {
240 | "cell_type": "markdown",
241 | "metadata": {},
242 | "source": [
243 | "## LSTM"
244 | ]
245 | },
246 | {
247 | "cell_type": "markdown",
248 | "metadata": {},
249 | "source": [
250 | "### Building an LSTM from scratch"
251 | ]
252 | },
253 | {
254 | "cell_type": "code",
255 | "execution_count": null,
256 | "metadata": {},
257 | "outputs": [],
258 | "source": [
259 | "class LSTMCell(Module):\n",
260 | " def __init__(self, ni, nh):\n",
261 | " self.forget_gate = nn.Linear(ni + nh, nh)\n",
262 | " self.input_gate = nn.Linear(ni + nh, nh)\n",
263 | " self.cell_gate = nn.Linear(ni + nh, nh)\n",
264 | " self.output_gate = nn.Linear(ni + nh, nh)\n",
265 | "\n",
266 | " def forward(self, input, state):\n",
267 | " h,c = state\n",
268 | " h = torch.stack([x, input], dim=1)\n",
269 | " forget = torch.sigmoid(self.forget_gate(h))\n",
270 | " c = c * forget\n",
271 | " inp = torch.sigmoid(self.input_gate(h))\n",
272 | " cell = torch.tanh(self.cell_gate(h))\n",
273 | " c = c + inp * cell\n",
274 | " out = torch.sigmoid(self.output_gate(h))\n",
275 | " h = outgate * torch.tanh(c)\n",
276 | " return h, (h,c)"
277 | ]
278 | },
279 | {
280 | "cell_type": "code",
281 | "execution_count": null,
282 | "metadata": {},
283 | "outputs": [],
284 | "source": [
285 | "class LSTMCell(Module):\n",
286 | " def __init__(self, ni, nh):\n",
287 | " self.ih = nn.Linear(ni,4*nh)\n",
288 | " self.hh = nn.Linear(nh,4*nh)\n",
289 | "\n",
290 | " def forward(self, input, state):\n",
291 | " h,c = state\n",
292 | " #One big multiplication for all the gates is better than 4 smaller ones\n",
293 | " gates = (self.ih(input) + self.hh(h)).chunk(4, 1)\n",
294 | " ingate,forgetgate,outgate = map(torch.sigmoid, gates[:3])\n",
295 | " cellgate = gates[3].tanh()\n",
296 | "\n",
297 | " c = (forgetgate*c) + (ingate*cellgate)\n",
298 | " h = outgate * c.tanh()\n",
299 | " return h, (h,c)"
300 | ]
301 | },
302 | {
303 | "cell_type": "markdown",
304 | "metadata": {},
305 | "source": [
306 | "### Training a language model using LSTMs"
307 | ]
308 | },
309 | {
310 | "cell_type": "code",
311 | "execution_count": null,
312 | "metadata": {},
313 | "outputs": [],
314 | "source": [
315 | "class LMModel6(Module):\n",
316 | " def __init__(self, vocab_sz, n_hidden, n_layers):\n",
317 | " self.i_h = nn.Embedding(vocab_sz, n_hidden)\n",
318 | " self.rnn = nn.LSTM(n_hidden, n_hidden, n_layers, batch_first=True)\n",
319 | " self.h_o = nn.Linear(n_hidden, vocab_sz)\n",
320 | " self.h = [torch.zeros(2, bs, n_hidden) for _ in range(n_layers)]\n",
321 | " \n",
322 | " def forward(self, x):\n",
323 | " res,h = self.rnn(self.i_h(x), self.h)\n",
324 | " self.h = [h_.detach() for h_ in h]\n",
325 | " return self.h_o(res)\n",
326 | " \n",
327 | " def reset(self): \n",
328 | " for h in self.h: h.zero_()"
329 | ]
330 | },
331 | {
332 | "cell_type": "code",
333 | "execution_count": null,
334 | "metadata": {},
335 | "outputs": [
336 | {
337 | "data": {
338 | "text/html": [
339 | "\n",
340 | " \n",
341 | " \n",
342 | " epoch | \n",
343 | " train_loss | \n",
344 | " valid_loss | \n",
345 | " accuracy | \n",
346 | " time | \n",
347 | "
\n",
348 | " \n",
349 | " \n",
350 | " \n",
351 | " 0 | \n",
352 | " 3.031346 | \n",
353 | " 2.749381 | \n",
354 | " 0.279215 | \n",
355 | " 00:03 | \n",
356 | "
\n",
357 | " \n",
358 | " 1 | \n",
359 | " 2.219651 | \n",
360 | " 2.084450 | \n",
361 | " 0.204753 | \n",
362 | " 00:03 | \n",
363 | "
\n",
364 | " \n",
365 | " 2 | \n",
366 | " 1.659518 | \n",
367 | " 1.685639 | \n",
368 | " 0.479574 | \n",
369 | " 00:03 | \n",
370 | "
\n",
371 | " \n",
372 | " 3 | \n",
373 | " 1.410550 | \n",
374 | " 1.666663 | \n",
375 | " 0.509440 | \n",
376 | " 00:03 | \n",
377 | "
\n",
378 | " \n",
379 | " 4 | \n",
380 | " 1.204062 | \n",
381 | " 1.606485 | \n",
382 | " 0.541829 | \n",
383 | " 00:03 | \n",
384 | "
\n",
385 | " \n",
386 | " 5 | \n",
387 | " 1.021459 | \n",
388 | " 1.529109 | \n",
389 | " 0.592448 | \n",
390 | " 00:03 | \n",
391 | "
\n",
392 | " \n",
393 | " 6 | \n",
394 | " 0.785871 | \n",
395 | " 1.340280 | \n",
396 | " 0.642008 | \n",
397 | " 00:03 | \n",
398 | "
\n",
399 | " \n",
400 | " 7 | \n",
401 | " 0.547519 | \n",
402 | " 1.271710 | \n",
403 | " 0.688802 | \n",
404 | " 00:03 | \n",
405 | "
\n",
406 | " \n",
407 | " 8 | \n",
408 | " 0.339775 | \n",
409 | " 1.216605 | \n",
410 | " 0.753825 | \n",
411 | " 00:03 | \n",
412 | "
\n",
413 | " \n",
414 | " 9 | \n",
415 | " 0.197550 | \n",
416 | " 1.218557 | \n",
417 | " 0.743652 | \n",
418 | " 00:02 | \n",
419 | "
\n",
420 | " \n",
421 | " 10 | \n",
422 | " 0.114297 | \n",
423 | " 1.253571 | \n",
424 | " 0.751139 | \n",
425 | " 00:03 | \n",
426 | "
\n",
427 | " \n",
428 | " 11 | \n",
429 | " 0.071301 | \n",
430 | " 1.314827 | \n",
431 | " 0.752686 | \n",
432 | " 00:03 | \n",
433 | "
\n",
434 | " \n",
435 | " 12 | \n",
436 | " 0.049507 | \n",
437 | " 1.307375 | \n",
438 | " 0.765462 | \n",
439 | " 00:03 | \n",
440 | "
\n",
441 | " \n",
442 | " 13 | \n",
443 | " 0.038810 | \n",
444 | " 1.287779 | \n",
445 | " 0.767741 | \n",
446 | " 00:03 | \n",
447 | "
\n",
448 | " \n",
449 | " 14 | \n",
450 | " 0.033738 | \n",
451 | " 1.292951 | \n",
452 | " 0.767985 | \n",
453 | " 00:03 | \n",
454 | "
\n",
455 | " \n",
456 | "
"
457 | ],
458 | "text/plain": [
459 | ""
460 | ]
461 | },
462 | "metadata": {},
463 | "output_type": "display_data"
464 | }
465 | ],
466 | "source": [
467 | "learn = Learner(dls, LMModel6(len(vocab), 64, 2), loss_func=CrossEntropyLossFlat(), metrics=accuracy, cbs=ModelReseter)\n",
468 | "learn.fit_one_cycle(15, 1e-2)"
469 | ]
470 | },
471 | {
472 | "cell_type": "markdown",
473 | "metadata": {},
474 | "source": [
475 | "## Regularizing an LSTM"
476 | ]
477 | },
478 | {
479 | "cell_type": "markdown",
480 | "metadata": {},
481 | "source": [
482 | "### Dropout"
483 | ]
484 | },
485 | {
486 | "cell_type": "code",
487 | "execution_count": null,
488 | "metadata": {},
489 | "outputs": [],
490 | "source": [
491 | "class Dropout(Module):\n",
492 | " def __init__(self, p): self.p = p\n",
493 | " def forward(self, x):\n",
494 | " if self.training: return x\n",
495 | " mask = x.new(*x.shape).bernoulli_(1-p)\n",
496 | " return x * mask.div_(1-p)"
497 | ]
498 | },
499 | {
500 | "cell_type": "markdown",
501 | "metadata": {},
502 | "source": [
503 | "### AR and TAR regularization"
504 | ]
505 | },
506 | {
507 | "cell_type": "markdown",
508 | "metadata": {},
509 | "source": [
510 | "### Training a regularized LSTM"
511 | ]
512 | },
513 | {
514 | "cell_type": "code",
515 | "execution_count": 12,
516 | "metadata": {},
517 | "outputs": [],
518 | "source": [
519 | "class LMModel7(Module):\n",
520 | " def __init__(self, vocab_sz, n_hidden, n_layers, p):\n",
521 | " self.i_h = nn.Embedding(vocab_sz, n_hidden)\n",
522 | " self.rnn = nn.LSTM(n_hidden, n_hidden, n_layers, batch_first=True)\n",
523 | " self.drop = nn.Dropout(p)\n",
524 | " self.h_o = nn.Linear(n_hidden, vocab_sz)\n",
525 | " self.h = [torch.zeros(2, bs, n_hidden) for _ in range(n_layers)]\n",
526 | " \n",
527 | " def forward(self, x):\n",
528 | " raw,h = self.rnn(self.i_h(x), self.h)\n",
529 | " out = self.drop(raw)\n",
530 | " self.h = [h_.detach() for h_ in h]\n",
531 | " return self.h_o(out),raw,out\n",
532 | " \n",
533 | " def reset(self): \n",
534 | " for h in self.h: h.zero_()"
535 | ]
536 | },
537 | {
538 | "cell_type": "code",
539 | "execution_count": 15,
540 | "metadata": {},
541 | "outputs": [],
542 | "source": [
543 | "learn = Learner(dls, LMModel7(len(vocab), 64, 2, 0.4), loss_func=CrossEntropyLossFlat(), \n",
544 | " metrics=accuracy, cbs=[ModelReseter, RNNRegularizer(alpha=2, beta=1)])"
545 | ]
546 | },
547 | {
548 | "cell_type": "code",
549 | "execution_count": 14,
550 | "metadata": {},
551 | "outputs": [
552 | {
553 | "data": {
554 | "text/html": [
555 | "\n",
556 | " \n",
557 | " \n",
558 | " epoch | \n",
559 | " train_loss | \n",
560 | " valid_loss | \n",
561 | " accuracy | \n",
562 | " time | \n",
563 | "
\n",
564 | " \n",
565 | " \n",
566 | " \n",
567 | " 0 | \n",
568 | " 3.145553 | \n",
569 | " 2.495994 | \n",
570 | " 0.437581 | \n",
571 | " 00:03 | \n",
572 | "
\n",
573 | " \n",
574 | " 1 | \n",
575 | " 2.333189 | \n",
576 | " 1.674463 | \n",
577 | " 0.491862 | \n",
578 | " 00:03 | \n",
579 | "
\n",
580 | " \n",
581 | " 2 | \n",
582 | " 1.678753 | \n",
583 | " 1.500536 | \n",
584 | " 0.553955 | \n",
585 | " 00:03 | \n",
586 | "
\n",
587 | " \n",
588 | " 3 | \n",
589 | " 1.111904 | \n",
590 | " 1.040109 | \n",
591 | " 0.748779 | \n",
592 | " 00:03 | \n",
593 | "
\n",
594 | " \n",
595 | " 4 | \n",
596 | " 0.707829 | \n",
597 | " 0.773369 | \n",
598 | " 0.807699 | \n",
599 | " 00:02 | \n",
600 | "
\n",
601 | " \n",
602 | " 5 | \n",
603 | " 0.465899 | \n",
604 | " 0.621159 | \n",
605 | " 0.829346 | \n",
606 | " 00:03 | \n",
607 | "
\n",
608 | " \n",
609 | " 6 | \n",
610 | " 0.335249 | \n",
611 | " 0.649926 | \n",
612 | " 0.839193 | \n",
613 | " 00:03 | \n",
614 | "
\n",
615 | " \n",
616 | " 7 | \n",
617 | " 0.254418 | \n",
618 | " 0.586989 | \n",
619 | " 0.841064 | \n",
620 | " 00:03 | \n",
621 | "
\n",
622 | " \n",
623 | " 8 | \n",
624 | " 0.205191 | \n",
625 | " 0.527288 | \n",
626 | " 0.850179 | \n",
627 | " 00:02 | \n",
628 | "
\n",
629 | " \n",
630 | " 9 | \n",
631 | " 0.172876 | \n",
632 | " 0.460011 | \n",
633 | " 0.868652 | \n",
634 | " 00:02 | \n",
635 | "
\n",
636 | " \n",
637 | " 10 | \n",
638 | " 0.151452 | \n",
639 | " 0.500604 | \n",
640 | " 0.860677 | \n",
641 | " 00:03 | \n",
642 | "
\n",
643 | " \n",
644 | " 11 | \n",
645 | " 0.136872 | \n",
646 | " 0.480342 | \n",
647 | " 0.863525 | \n",
648 | " 00:03 | \n",
649 | "
\n",
650 | " \n",
651 | " 12 | \n",
652 | " 0.127576 | \n",
653 | " 0.496534 | \n",
654 | " 0.858398 | \n",
655 | " 00:03 | \n",
656 | "
\n",
657 | " \n",
658 | " 13 | \n",
659 | " 0.122187 | \n",
660 | " 0.475931 | \n",
661 | " 0.867025 | \n",
662 | " 00:03 | \n",
663 | "
\n",
664 | " \n",
665 | " 14 | \n",
666 | " 0.119538 | \n",
667 | " 0.490366 | \n",
668 | " 0.861165 | \n",
669 | " 00:03 | \n",
670 | "
\n",
671 | " \n",
672 | "
"
673 | ],
674 | "text/plain": [
675 | ""
676 | ]
677 | },
678 | "metadata": {},
679 | "output_type": "display_data"
680 | }
681 | ],
682 | "source": [
683 | "learn = TextLearner(dls, LMModel7(len(vocab), 64, 2, 0.4), loss_func=CrossEntropyLossFlat(), \n",
684 | " metrics=accuracy)\n",
685 | "learn.fit_one_cycle(15, 1e-2)"
686 | ]
687 | },
688 | {
689 | "cell_type": "markdown",
690 | "metadata": {},
691 | "source": [
692 | "## Conclusion"
693 | ]
694 | },
695 | {
696 | "cell_type": "code",
697 | "execution_count": null,
698 | "metadata": {},
699 | "outputs": [],
700 | "source": []
701 | }
702 | ],
703 | "metadata": {
704 | "jupytext": {
705 | "split_at_heading": true
706 | },
707 | "kernelspec": {
708 | "display_name": "Python 3",
709 | "language": "python",
710 | "name": "python3"
711 | },
712 | "language_info": {
713 | "codemirror_mode": {
714 | "name": "ipython",
715 | "version": 3
716 | },
717 | "file_extension": ".py",
718 | "mimetype": "text/x-python",
719 | "name": "python",
720 | "nbconvert_exporter": "python",
721 | "pygments_lexer": "ipython3",
722 | "version": "3.7.4"
723 | }
724 | },
725 | "nbformat": 4,
726 | "nbformat_minor": 2
727 | }
728 |
--------------------------------------------------------------------------------
/16_arch_details.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "#hide\n",
10 | "from utils import *"
11 | ]
12 | },
13 | {
14 | "cell_type": "markdown",
15 | "metadata": {},
16 | "source": [
17 | "# Application architectures deep dive"
18 | ]
19 | },
20 | {
21 | "cell_type": "markdown",
22 | "metadata": {},
23 | "source": [
24 | "## Computer vision"
25 | ]
26 | },
27 | {
28 | "cell_type": "markdown",
29 | "metadata": {},
30 | "source": [
31 | "### cnn_learner"
32 | ]
33 | },
34 | {
35 | "cell_type": "code",
36 | "execution_count": null,
37 | "metadata": {},
38 | "outputs": [
39 | {
40 | "data": {
41 | "text/plain": [
42 | "{'cut': -2,\n",
43 | " 'split': ,\n",
44 | " 'stats': ([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])}"
45 | ]
46 | },
47 | "execution_count": null,
48 | "metadata": {},
49 | "output_type": "execute_result"
50 | }
51 | ],
52 | "source": [
53 | "model_meta[resnet50]"
54 | ]
55 | },
56 | {
57 | "cell_type": "code",
58 | "execution_count": null,
59 | "metadata": {},
60 | "outputs": [
61 | {
62 | "data": {
63 | "text/plain": [
64 | "Sequential(\n",
65 | " (0): AdaptiveConcatPool2d(\n",
66 | " (ap): AdaptiveAvgPool2d(output_size=1)\n",
67 | " (mp): AdaptiveMaxPool2d(output_size=1)\n",
68 | " )\n",
69 | " (1): full: False\n",
70 | " (2): BatchNorm1d(20, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
71 | " (3): Dropout(p=0.25, inplace=False)\n",
72 | " (4): Linear(in_features=20, out_features=512, bias=False)\n",
73 | " (5): ReLU(inplace=True)\n",
74 | " (6): BatchNorm1d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
75 | " (7): Dropout(p=0.5, inplace=False)\n",
76 | " (8): Linear(in_features=512, out_features=2, bias=False)\n",
77 | ")"
78 | ]
79 | },
80 | "execution_count": null,
81 | "metadata": {},
82 | "output_type": "execute_result"
83 | }
84 | ],
85 | "source": [
86 | "create_head(20,2)"
87 | ]
88 | },
89 | {
90 | "cell_type": "markdown",
91 | "metadata": {},
92 | "source": [
93 | "### unet_learner"
94 | ]
95 | },
96 | {
97 | "cell_type": "markdown",
98 | "metadata": {},
99 | "source": [
100 | "## Natural language processing"
101 | ]
102 | },
103 | {
104 | "cell_type": "markdown",
105 | "metadata": {},
106 | "source": [
107 | "## Tabular"
108 | ]
109 | },
110 | {
111 | "cell_type": "markdown",
112 | "metadata": {},
113 | "source": [
114 | "## Wrapping up architectures"
115 | ]
116 | },
117 | {
118 | "cell_type": "code",
119 | "execution_count": null,
120 | "metadata": {},
121 | "outputs": [],
122 | "source": []
123 | }
124 | ],
125 | "metadata": {
126 | "jupytext": {
127 | "split_at_heading": true
128 | },
129 | "kernelspec": {
130 | "display_name": "Python 3",
131 | "language": "python",
132 | "name": "python3"
133 | },
134 | "language_info": {
135 | "codemirror_mode": {
136 | "name": "ipython",
137 | "version": 3
138 | },
139 | "file_extension": ".py",
140 | "mimetype": "text/x-python",
141 | "name": "python",
142 | "nbconvert_exporter": "python",
143 | "pygments_lexer": "ipython3",
144 | "version": "3.7.4"
145 | }
146 | },
147 | "nbformat": 4,
148 | "nbformat_minor": 2
149 | }
150 |
--------------------------------------------------------------------------------
/17_arch_details.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "#hide\n",
10 | "from utils import *"
11 | ]
12 | },
13 | {
14 | "cell_type": "markdown",
15 | "metadata": {},
16 | "source": [
17 | "## Computer vision"
18 | ]
19 | },
20 | {
21 | "cell_type": "markdown",
22 | "metadata": {},
23 | "source": [
24 | "### cnn_learner"
25 | ]
26 | },
27 | {
28 | "cell_type": "code",
29 | "execution_count": null,
30 | "metadata": {},
31 | "outputs": [
32 | {
33 | "data": {
34 | "text/plain": [
35 | "{'cut': -2,\n",
36 | " 'split': ,\n",
37 | " 'stats': ([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])}"
38 | ]
39 | },
40 | "execution_count": null,
41 | "metadata": {},
42 | "output_type": "execute_result"
43 | }
44 | ],
45 | "source": [
46 | "model_meta[resnet50]"
47 | ]
48 | },
49 | {
50 | "cell_type": "code",
51 | "execution_count": null,
52 | "metadata": {},
53 | "outputs": [
54 | {
55 | "data": {
56 | "text/plain": [
57 | "Sequential(\n",
58 | " (0): AdaptiveConcatPool2d(\n",
59 | " (ap): AdaptiveAvgPool2d(output_size=1)\n",
60 | " (mp): AdaptiveMaxPool2d(output_size=1)\n",
61 | " )\n",
62 | " (1): full: False\n",
63 | " (2): BatchNorm1d(20, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
64 | " (3): Dropout(p=0.25, inplace=False)\n",
65 | " (4): Linear(in_features=20, out_features=512, bias=False)\n",
66 | " (5): ReLU(inplace=True)\n",
67 | " (6): BatchNorm1d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
68 | " (7): Dropout(p=0.5, inplace=False)\n",
69 | " (8): Linear(in_features=512, out_features=2, bias=False)\n",
70 | ")"
71 | ]
72 | },
73 | "execution_count": null,
74 | "metadata": {},
75 | "output_type": "execute_result"
76 | }
77 | ],
78 | "source": [
79 | "create_head(20,2)"
80 | ]
81 | },
82 | {
83 | "cell_type": "markdown",
84 | "metadata": {},
85 | "source": [
86 | "### unet_learner"
87 | ]
88 | },
89 | {
90 | "cell_type": "markdown",
91 | "metadata": {},
92 | "source": [
93 | "## Natural language processing"
94 | ]
95 | },
96 | {
97 | "cell_type": "markdown",
98 | "metadata": {},
99 | "source": [
100 | "## Tabular"
101 | ]
102 | },
103 | {
104 | "cell_type": "markdown",
105 | "metadata": {},
106 | "source": [
107 | "## Wrapping up architectures"
108 | ]
109 | },
110 | {
111 | "cell_type": "code",
112 | "execution_count": null,
113 | "metadata": {},
114 | "outputs": [],
115 | "source": []
116 | }
117 | ],
118 | "metadata": {
119 | "kernelspec": {
120 | "display_name": "Python 3",
121 | "language": "python",
122 | "name": "python3"
123 | }
124 | },
125 | "nbformat": 4,
126 | "nbformat_minor": 2
127 | }
128 |
--------------------------------------------------------------------------------
/18_callbacks.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "#hide\n",
10 | "from utils import *"
11 | ]
12 | },
13 | {
14 | "cell_type": "markdown",
15 | "metadata": {},
16 | "source": [
17 | "# Callbacks"
18 | ]
19 | },
20 | {
21 | "cell_type": "markdown",
22 | "metadata": {},
23 | "source": [
24 | "## Introduction to callbacks"
25 | ]
26 | },
27 | {
28 | "cell_type": "markdown",
29 | "metadata": {},
30 | "source": [
31 | "## Creating a callback"
32 | ]
33 | },
34 | {
35 | "cell_type": "code",
36 | "execution_count": null,
37 | "metadata": {},
38 | "outputs": [],
39 | "source": [
40 | "class ModelReseter(Callback):\n",
41 | " def begin_train(self): self.model.reset()\n",
42 | " def begin_validate(self): self.model.reset()"
43 | ]
44 | },
45 | {
46 | "cell_type": "code",
47 | "execution_count": null,
48 | "metadata": {},
49 | "outputs": [],
50 | "source": [
51 | "class RNNRegularizer(Callback):\n",
52 | " def __init__(self, alpha=0., beta=0.): self.alpha,self.beta = alpha,beta\n",
53 | "\n",
54 | " def after_pred(self):\n",
55 | " self.raw_out,self.out = self.pred[1],self.pred[2]\n",
56 | " self.learn.pred = self.pred[0]\n",
57 | "\n",
58 | " def after_loss(self):\n",
59 | " if not self.training: return\n",
60 | " if self.alpha != 0.:\n",
61 | " self.learn.loss += self.alpha * self.out[-1].float().pow(2).mean()\n",
62 | " if self.beta != 0.:\n",
63 | " h = self.raw_out[-1]\n",
64 | " if len(h)>1:\n",
65 | " self.learn.loss += self.beta * (h[:,1:] - h[:,:-1]\n",
66 | " ).float().pow(2).mean()"
67 | ]
68 | },
69 | {
70 | "cell_type": "markdown",
71 | "metadata": {},
72 | "source": [
73 | "## Callback ordering and exceptions"
74 | ]
75 | },
76 | {
77 | "cell_type": "code",
78 | "execution_count": null,
79 | "metadata": {},
80 | "outputs": [],
81 | "source": [
82 | "class TerminateOnNaNCallback(Callback):\n",
83 | " run_before=Recorder\n",
84 | " def after_batch(self):\n",
85 | " if torch.isinf(self.loss) or torch.isnan(self.loss):\n",
86 | " raise CancelFitException"
87 | ]
88 | },
89 | {
90 | "cell_type": "markdown",
91 | "metadata": {},
92 | "source": [
93 | "## Summary"
94 | ]
95 | },
96 | {
97 | "cell_type": "code",
98 | "execution_count": null,
99 | "metadata": {},
100 | "outputs": [],
101 | "source": []
102 | }
103 | ],
104 | "metadata": {
105 | "jupytext": {
106 | "split_at_heading": true
107 | },
108 | "kernelspec": {
109 | "display_name": "Python 3",
110 | "language": "python",
111 | "name": "python3"
112 | },
113 | "language_info": {
114 | "codemirror_mode": {
115 | "name": "ipython",
116 | "version": 3
117 | },
118 | "file_extension": ".py",
119 | "mimetype": "text/x-python",
120 | "name": "python",
121 | "nbconvert_exporter": "python",
122 | "pygments_lexer": "ipython3",
123 | "version": "3.7.4"
124 | }
125 | },
126 | "nbformat": 4,
127 | "nbformat_minor": 2
128 | }
129 |
--------------------------------------------------------------------------------
/19_callbacks.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "#hide\n",
10 | "from utils import *"
11 | ]
12 | },
13 | {
14 | "cell_type": "markdown",
15 | "metadata": {},
16 | "source": [
17 | "# Callbacks"
18 | ]
19 | },
20 | {
21 | "cell_type": "markdown",
22 | "metadata": {},
23 | "source": [
24 | "## Introduction to callbacks"
25 | ]
26 | },
27 | {
28 | "cell_type": "markdown",
29 | "metadata": {},
30 | "source": [
31 | "## Creating a callback"
32 | ]
33 | },
34 | {
35 | "cell_type": "code",
36 | "execution_count": null,
37 | "metadata": {},
38 | "outputs": [],
39 | "source": [
40 | "class ModelReseter(Callback):\n",
41 | " def begin_train(self): self.model.reset()\n",
42 | " def begin_validate(self): self.model.reset()"
43 | ]
44 | },
45 | {
46 | "cell_type": "code",
47 | "execution_count": null,
48 | "metadata": {},
49 | "outputs": [],
50 | "source": [
51 | "class RNNRegularizer(Callback):\n",
52 | " def __init__(self, alpha=0., beta=0.): self.alpha,self.beta = alpha,beta\n",
53 | "\n",
54 | " def after_pred(self):\n",
55 | " self.raw_out,self.out = self.pred[1],self.pred[2]\n",
56 | " self.learn.pred = self.pred[0]\n",
57 | "\n",
58 | " def after_loss(self):\n",
59 | " if not self.training: return\n",
60 | " if self.alpha != 0.:\n",
61 | " self.learn.loss += self.alpha * self.out[-1].float().pow(2).mean()\n",
62 | " if self.beta != 0.:\n",
63 | " h = self.raw_out[-1]\n",
64 | " if len(h)>1:\n",
65 | " self.learn.loss += self.beta * (h[:,1:] - h[:,:-1]\n",
66 | " ).float().pow(2).mean()"
67 | ]
68 | },
69 | {
70 | "cell_type": "markdown",
71 | "metadata": {},
72 | "source": [
73 | "## Callback ordering and exceptions"
74 | ]
75 | },
76 | {
77 | "cell_type": "code",
78 | "execution_count": null,
79 | "metadata": {},
80 | "outputs": [],
81 | "source": [
82 | "class TerminateOnNaNCallback(Callback):\n",
83 | " run_before=Recorder\n",
84 | " def after_batch(self):\n",
85 | " if torch.isinf(self.loss) or torch.isnan(self.loss):\n",
86 | " raise CancelFitException"
87 | ]
88 | },
89 | {
90 | "cell_type": "markdown",
91 | "metadata": {},
92 | "source": [
93 | "## Summary"
94 | ]
95 | },
96 | {
97 | "cell_type": "code",
98 | "execution_count": null,
99 | "metadata": {},
100 | "outputs": [],
101 | "source": []
102 | }
103 | ],
104 | "metadata": {
105 | "kernelspec": {
106 | "display_name": "Python 3",
107 | "language": "python",
108 | "name": "python3"
109 | }
110 | },
111 | "nbformat": 4,
112 | "nbformat_minor": 2
113 | }
114 |
--------------------------------------------------------------------------------
/22_conclusion.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Concluding thoughts"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": null,
13 | "metadata": {},
14 | "outputs": [],
15 | "source": []
16 | }
17 | ],
18 | "metadata": {
19 | "jupytext": {
20 | "split_at_heading": true
21 | },
22 | "kernelspec": {
23 | "display_name": "Python 3",
24 | "language": "python",
25 | "name": "python3"
26 | },
27 | "language_info": {
28 | "codemirror_mode": {
29 | "name": "ipython",
30 | "version": 3
31 | },
32 | "file_extension": ".py",
33 | "mimetype": "text/x-python",
34 | "name": "python",
35 | "nbconvert_exporter": "python",
36 | "pygments_lexer": "ipython3",
37 | "version": "3.7.4"
38 | }
39 | },
40 | "nbformat": 4,
41 | "nbformat_minor": 2
42 | }
43 |
--------------------------------------------------------------------------------
/23_conclusion.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Concluding thoughts"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": null,
13 | "metadata": {},
14 | "outputs": [],
15 | "source": []
16 | }
17 | ],
18 | "metadata": {
19 | "kernelspec": {
20 | "display_name": "Python 3",
21 | "language": "python",
22 | "name": "python3"
23 | }
24 | },
25 | "nbformat": 4,
26 | "nbformat_minor": 2
27 | }
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # book_nbs
2 | Notebooks for upcoming fastai book (draft / incomplete)
3 |
--------------------------------------------------------------------------------
/app_blog.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "#hide\n",
10 | "from utils import *\n",
11 | "from fastai2.vision.widgets import *"
12 | ]
13 | },
14 | {
15 | "cell_type": "markdown",
16 | "metadata": {},
17 | "source": [
18 | "# Creating a blog"
19 | ]
20 | },
21 | {
22 | "cell_type": "markdown",
23 | "metadata": {},
24 | "source": [
25 | "## Blogging with GitHub Pages"
26 | ]
27 | },
28 | {
29 | "cell_type": "markdown",
30 | "metadata": {},
31 | "source": [
32 | "### Creating the repository"
33 | ]
34 | },
35 | {
36 | "cell_type": "markdown",
37 | "metadata": {},
38 | "source": [
39 | "### Setting up your homepage"
40 | ]
41 | },
42 | {
43 | "cell_type": "markdown",
44 | "metadata": {},
45 | "source": [
46 | "### Creating posts"
47 | ]
48 | },
49 | {
50 | "cell_type": "markdown",
51 | "metadata": {},
52 | "source": [
53 | "### Synchronizing GitHub and your computer"
54 | ]
55 | },
56 | {
57 | "cell_type": "markdown",
58 | "metadata": {},
59 | "source": [
60 | "### Jupyter for blogging"
61 | ]
62 | },
63 | {
64 | "cell_type": "code",
65 | "execution_count": null,
66 | "metadata": {},
67 | "outputs": [],
68 | "source": []
69 | }
70 | ],
71 | "metadata": {
72 | "jupytext": {
73 | "split_at_heading": true
74 | },
75 | "kernelspec": {
76 | "display_name": "Python 3",
77 | "language": "python",
78 | "name": "python3"
79 | }
80 | },
81 | "nbformat": 4,
82 | "nbformat_minor": 2
83 | }
84 |
--------------------------------------------------------------------------------
/images/0_jupyter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/0_jupyter.png
--------------------------------------------------------------------------------
/images/Dropout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/Dropout.png
--------------------------------------------------------------------------------
/images/Dropout1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/Dropout1.png
--------------------------------------------------------------------------------
/images/LSTM.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/LSTM.png
--------------------------------------------------------------------------------
/images/analytics_chain.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/analytics_chain.gif
--------------------------------------------------------------------------------
/images/att_00000.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00000.png
--------------------------------------------------------------------------------
/images/att_00001.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00001.png
--------------------------------------------------------------------------------
/images/att_00002.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00002.png
--------------------------------------------------------------------------------
/images/att_00003.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00003.png
--------------------------------------------------------------------------------
/images/att_00004.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00004.png
--------------------------------------------------------------------------------
/images/att_00005.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00005.png
--------------------------------------------------------------------------------
/images/att_00006.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00006.png
--------------------------------------------------------------------------------
/images/att_00007.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00007.png
--------------------------------------------------------------------------------
/images/att_00008.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00008.png
--------------------------------------------------------------------------------
/images/att_00009.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00009.png
--------------------------------------------------------------------------------
/images/att_00010.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00010.png
--------------------------------------------------------------------------------
/images/att_00011.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00011.png
--------------------------------------------------------------------------------
/images/att_00012.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00012.png
--------------------------------------------------------------------------------
/images/att_00013.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00013.png
--------------------------------------------------------------------------------
/images/att_00014.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00014.png
--------------------------------------------------------------------------------
/images/att_00015.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00015.png
--------------------------------------------------------------------------------
/images/att_00016.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00016.png
--------------------------------------------------------------------------------
/images/att_00017.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00017.png
--------------------------------------------------------------------------------
/images/att_00018.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00018.png
--------------------------------------------------------------------------------
/images/att_00019.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00019.png
--------------------------------------------------------------------------------
/images/att_00020.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00020.png
--------------------------------------------------------------------------------
/images/att_00021.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00021.png
--------------------------------------------------------------------------------
/images/att_00022.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00022.png
--------------------------------------------------------------------------------
/images/att_00023.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00023.png
--------------------------------------------------------------------------------
/images/att_00024.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00024.png
--------------------------------------------------------------------------------
/images/att_00025.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00025.png
--------------------------------------------------------------------------------
/images/att_00026.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00026.png
--------------------------------------------------------------------------------
/images/att_00027.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00027.png
--------------------------------------------------------------------------------
/images/att_00028.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00028.png
--------------------------------------------------------------------------------
/images/att_00029.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00029.png
--------------------------------------------------------------------------------
/images/att_00030.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00030.png
--------------------------------------------------------------------------------
/images/att_00031.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00031.png
--------------------------------------------------------------------------------
/images/att_00032.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00032.png
--------------------------------------------------------------------------------
/images/att_00033.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00033.png
--------------------------------------------------------------------------------
/images/att_00034.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00034.png
--------------------------------------------------------------------------------
/images/att_00035.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00035.png
--------------------------------------------------------------------------------
/images/att_00036.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00036.png
--------------------------------------------------------------------------------
/images/att_00037.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00037.png
--------------------------------------------------------------------------------
/images/att_00038.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00038.png
--------------------------------------------------------------------------------
/images/att_00039.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00039.png
--------------------------------------------------------------------------------
/images/att_00040.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00040.png
--------------------------------------------------------------------------------
/images/att_00041.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00041.png
--------------------------------------------------------------------------------
/images/att_00042.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00042.png
--------------------------------------------------------------------------------
/images/att_00043.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00043.png
--------------------------------------------------------------------------------
/images/att_00044.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00044.png
--------------------------------------------------------------------------------
/images/att_00045.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00045.png
--------------------------------------------------------------------------------
/images/att_00046.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00046.png
--------------------------------------------------------------------------------
/images/att_00047.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00047.png
--------------------------------------------------------------------------------
/images/att_00048.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00048.png
--------------------------------------------------------------------------------
/images/att_00049.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00049.png
--------------------------------------------------------------------------------
/images/att_00050.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00050.png
--------------------------------------------------------------------------------
/images/att_00051.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00051.png
--------------------------------------------------------------------------------
/images/att_00052.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00052.png
--------------------------------------------------------------------------------
/images/att_00053.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00053.png
--------------------------------------------------------------------------------
/images/att_00054.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00054.png
--------------------------------------------------------------------------------
/images/att_00055.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00055.png
--------------------------------------------------------------------------------
/images/att_00056.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00056.png
--------------------------------------------------------------------------------
/images/att_00057.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00057.png
--------------------------------------------------------------------------------
/images/att_00058.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00058.png
--------------------------------------------------------------------------------
/images/att_00059.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00059.png
--------------------------------------------------------------------------------
/images/att_00060.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00060.png
--------------------------------------------------------------------------------
/images/att_00061.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00061.png
--------------------------------------------------------------------------------
/images/att_00062.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00062.png
--------------------------------------------------------------------------------
/images/att_00063.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00063.png
--------------------------------------------------------------------------------
/images/att_00064.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00064.png
--------------------------------------------------------------------------------
/images/att_00065.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00065.png
--------------------------------------------------------------------------------
/images/att_00066.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00066.png
--------------------------------------------------------------------------------
/images/att_00067.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00067.png
--------------------------------------------------------------------------------
/images/att_00068.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00068.png
--------------------------------------------------------------------------------
/images/att_00069.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00069.png
--------------------------------------------------------------------------------
/images/att_00070.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00070.png
--------------------------------------------------------------------------------
/images/att_00071.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/att_00071.png
--------------------------------------------------------------------------------
/images/chapter1_add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter1_add.png
--------------------------------------------------------------------------------
/images/chapter1_busy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter1_busy.png
--------------------------------------------------------------------------------
/images/chapter1_cat_example.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter1_cat_example.jpg
--------------------------------------------------------------------------------
/images/chapter1_markdown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter1_markdown.png
--------------------------------------------------------------------------------
/images/chapter1_new_notebook.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter1_new_notebook.png
--------------------------------------------------------------------------------
/images/chapter1_run.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter1_run.png
--------------------------------------------------------------------------------
/images/chapter1_save.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter1_save.png
--------------------------------------------------------------------------------
/images/chapter1_terminal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter1_terminal.png
--------------------------------------------------------------------------------
/images/chapter2_bouncing.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter2_bouncing.PNG
--------------------------------------------------------------------------------
/images/chapter2_bouncy.svg:
--------------------------------------------------------------------------------
1 |
2 |
88 |
--------------------------------------------------------------------------------
/images/chapter2_derivative.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter2_derivative.PNG
--------------------------------------------------------------------------------
/images/chapter2_div.svg:
--------------------------------------------------------------------------------
1 |
2 |
79 |
--------------------------------------------------------------------------------
/images/chapter2_layer1and2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter2_layer1and2.PNG
--------------------------------------------------------------------------------
/images/chapter2_layer3.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter2_layer3.PNG
--------------------------------------------------------------------------------
/images/chapter2_layer4and5.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter2_layer4and5.PNG
--------------------------------------------------------------------------------
/images/chapter2_perfect.svg:
--------------------------------------------------------------------------------
1 |
2 |
79 |
--------------------------------------------------------------------------------
/images/chapter2_sgd.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter2_sgd.PNG
--------------------------------------------------------------------------------
/images/chapter2_small.svg:
--------------------------------------------------------------------------------
1 |
2 |
91 |
--------------------------------------------------------------------------------
/images/chapter4_1cycle_schedule.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter4_1cycle_schedule.png
--------------------------------------------------------------------------------
/images/chapter4_overfit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter4_overfit.png
--------------------------------------------------------------------------------
/images/chapter7_neuron.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter7_neuron.png
--------------------------------------------------------------------------------
/images/chapter9_bottleneck.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter9_bottleneck.png
--------------------------------------------------------------------------------
/images/chapter9_cat_conv.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter9_cat_conv.png
--------------------------------------------------------------------------------
/images/chapter9_conv_basic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter9_conv_basic.png
--------------------------------------------------------------------------------
/images/chapter9_conv_pad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter9_conv_pad.png
--------------------------------------------------------------------------------
/images/chapter9_conv_rgb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter9_conv_rgb.png
--------------------------------------------------------------------------------
/images/chapter9_conv_stride.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter9_conv_stride.png
--------------------------------------------------------------------------------
/images/chapter9_loss_landscape.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter9_loss_landscape.png
--------------------------------------------------------------------------------
/images/chapter9_nopadconv.svg:
--------------------------------------------------------------------------------
1 |
2 |
34 |
--------------------------------------------------------------------------------
/images/chapter9_padconv.svg:
--------------------------------------------------------------------------------
1 |
2 |
48 |
--------------------------------------------------------------------------------
/images/chapter9_rgb_conv_stack.svg:
--------------------------------------------------------------------------------
1 |
2 |
47 |
--------------------------------------------------------------------------------
/images/chapter9_rgbconv.svg:
--------------------------------------------------------------------------------
1 |
2 |
91 |
--------------------------------------------------------------------------------
/images/chapter9_skip_connection.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/chapter9_skip_connection.png
--------------------------------------------------------------------------------
/images/chapter9_strideconv.svg:
--------------------------------------------------------------------------------
1 |
2 |
34 |
--------------------------------------------------------------------------------
/images/colorful_dist.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/colorful_dist.jpeg
--------------------------------------------------------------------------------
/images/colorful_summ.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/colorful_summ.png
--------------------------------------------------------------------------------
/images/cover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/cover.png
--------------------------------------------------------------------------------
/images/driver_phone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/driver_phone.png
--------------------------------------------------------------------------------
/images/driver_phone2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/driver_phone2.png
--------------------------------------------------------------------------------
/images/drivetrain-approach.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/drivetrain-approach.png
--------------------------------------------------------------------------------
/images/ethics/image1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image1.png
--------------------------------------------------------------------------------
/images/ethics/image10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image10.png
--------------------------------------------------------------------------------
/images/ethics/image11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image11.png
--------------------------------------------------------------------------------
/images/ethics/image12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image12.png
--------------------------------------------------------------------------------
/images/ethics/image13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image13.png
--------------------------------------------------------------------------------
/images/ethics/image14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image14.png
--------------------------------------------------------------------------------
/images/ethics/image15.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image15.jpeg
--------------------------------------------------------------------------------
/images/ethics/image16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image16.png
--------------------------------------------------------------------------------
/images/ethics/image17.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image17.jpeg
--------------------------------------------------------------------------------
/images/ethics/image17.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image17.png
--------------------------------------------------------------------------------
/images/ethics/image18.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image18.jpeg
--------------------------------------------------------------------------------
/images/ethics/image2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image2.png
--------------------------------------------------------------------------------
/images/ethics/image3.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image3.jpeg
--------------------------------------------------------------------------------
/images/ethics/image4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image4.png
--------------------------------------------------------------------------------
/images/ethics/image5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image5.png
--------------------------------------------------------------------------------
/images/ethics/image6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image6.png
--------------------------------------------------------------------------------
/images/ethics/image7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image7.png
--------------------------------------------------------------------------------
/images/ethics/image8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image8.png
--------------------------------------------------------------------------------
/images/ethics/image9.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/ethics/image9.jpeg
--------------------------------------------------------------------------------
/images/fast_template/image1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/fast_template/image1.png
--------------------------------------------------------------------------------
/images/fast_template/image10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/fast_template/image10.png
--------------------------------------------------------------------------------
/images/fast_template/image11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/fast_template/image11.png
--------------------------------------------------------------------------------
/images/fast_template/image12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/fast_template/image12.png
--------------------------------------------------------------------------------
/images/fast_template/image13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/fast_template/image13.png
--------------------------------------------------------------------------------
/images/fast_template/image14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/fast_template/image14.png
--------------------------------------------------------------------------------
/images/fast_template/image15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/fast_template/image15.png
--------------------------------------------------------------------------------
/images/fast_template/image16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/fast_template/image16.png
--------------------------------------------------------------------------------
/images/fast_template/image2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/fast_template/image2.png
--------------------------------------------------------------------------------
/images/fast_template/image3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/fast_template/image3.png
--------------------------------------------------------------------------------
/images/fast_template/image4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/fast_template/image4.png
--------------------------------------------------------------------------------
/images/fast_template/image5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/fast_template/image5.png
--------------------------------------------------------------------------------
/images/fast_template/image6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/fast_template/image6.png
--------------------------------------------------------------------------------
/images/fast_template/image7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/fast_template/image7.png
--------------------------------------------------------------------------------
/images/fast_template/image8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/fast_template/image8.png
--------------------------------------------------------------------------------
/images/fast_template/image9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/fast_template/image9.png
--------------------------------------------------------------------------------
/images/gitblog/commit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/gitblog/commit.png
--------------------------------------------------------------------------------
/images/gitblog/image1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/gitblog/image1.png
--------------------------------------------------------------------------------
/images/gitblog/image2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/gitblog/image2.png
--------------------------------------------------------------------------------
/images/gitblog/image3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/gitblog/image3.png
--------------------------------------------------------------------------------
/images/gitblog/image4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/gitblog/image4.png
--------------------------------------------------------------------------------
/images/gitblog/image5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/gitblog/image5.png
--------------------------------------------------------------------------------
/images/grad_illustration.svg:
--------------------------------------------------------------------------------
1 |
2 |
71 |
--------------------------------------------------------------------------------
/images/grizzly.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/grizzly.jpg
--------------------------------------------------------------------------------
/images/healthy_skin.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/healthy_skin.gif
--------------------------------------------------------------------------------
/images/mnist3_xl.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/mnist3_xl.gif
--------------------------------------------------------------------------------
/images/mnist3_xl_300.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/mnist3_xl_300.gif
--------------------------------------------------------------------------------
/images/mnist3_xl_custom.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/mnist3_xl_custom.gif
--------------------------------------------------------------------------------
/images/pratchett.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/pratchett.png
--------------------------------------------------------------------------------
/images/profit_drivers.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/profit_drivers.gif
--------------------------------------------------------------------------------
/images/sklearn_features.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/sklearn_features.png
--------------------------------------------------------------------------------
/images/tarsier.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/tarsier.png
--------------------------------------------------------------------------------
/images/timeseries1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/timeseries1.png
--------------------------------------------------------------------------------
/images/timeseries2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/timeseries2.png
--------------------------------------------------------------------------------
/images/timeseries3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/timeseries3.png
--------------------------------------------------------------------------------
/images/turing.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/turing.jpg
--------------------------------------------------------------------------------
/images/turing_300.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastai/book_nbs/a7548b8d7f81cc04d0a2d035d05497c6833048c1/images/turing_300.jpg
--------------------------------------------------------------------------------
/utils.py:
--------------------------------------------------------------------------------
1 | # Numpy and pandas by default assume a narrow screen - this fixes that
2 | from fastai2.vision.all import *
3 | from nbdev.showdoc import *
4 | from ipywidgets import widgets
5 | from pandas.api.types import CategoricalDtype
6 |
7 | import matplotlib as mpl
8 | # mpl.rcParams['figure.dpi']= 200
9 | mpl.rcParams['savefig.dpi']= 200
10 | mpl.rcParams['font.size']=12
11 |
12 | set_seed(42)
13 | torch.backends.cudnn.deterministic = True
14 | torch.backends.cudnn.benchmark = False
15 | pd.set_option('display.max_columns',999)
16 | np.set_printoptions(linewidth=200)
17 | torch.set_printoptions(linewidth=200)
18 |
19 | import graphviz
20 | def gv(s): return graphviz.Source('digraph G{ rankdir="LR"' + s + '; }')
21 |
22 | def get_image_files_sorted(path, recurse=True, folders=None): return get_image_files(path, recurse, folders).sorted()
23 |
24 |
25 | # +
26 | # pip install azure-cognitiveservices-search-imagesearch
27 |
28 | from azure.cognitiveservices.search.imagesearch import ImageSearchClient as api
29 | from msrest.authentication import CognitiveServicesCredentials as auth
30 |
31 | def search_images_bing(key, term, min_sz=128):
32 | client = api('https://api.cognitive.microsoft.com', auth(key))
33 | return L(client.images.search(query=term, count=150, min_height=min_sz, min_width=min_sz).value)
34 |
35 |
36 | # -
37 |
38 | def plot_function(f, tx=None, ty=None, title=None, min=-2, max=2, figsize=(6,4)):
39 | x = torch.linspace(min,max)
40 | fig,ax = plt.subplots(figsize=figsize)
41 | ax.plot(x,f(x))
42 | if tx is not None: ax.set_xlabel(tx)
43 | if ty is not None: ax.set_ylabel(ty)
44 | if title is not None: ax.set_title(title)
45 |
46 | # +
47 | from sklearn.tree import export_graphviz
48 |
49 | def draw_tree(t, df, size=10, ratio=0.6, precision=0, **kwargs):
50 | s=export_graphviz(t, out_file=None, feature_names=df.columns, filled=True, rounded=True,
51 | special_characters=True, rotate=False, precision=precision, **kwargs)
52 | return graphviz.Source(re.sub('Tree {', f'Tree {{ size={size}; ratio={ratio}', s))
53 |
54 |
55 | # +
56 | from scipy.cluster import hierarchy as hc
57 |
58 | def cluster_columns(df, figsize=(10,6), font_size=12):
59 | corr = np.round(scipy.stats.spearmanr(df).correlation, 4)
60 | corr_condensed = hc.distance.squareform(1-corr)
61 | z = hc.linkage(corr_condensed, method='average')
62 | fig = plt.figure(figsize=figsize)
63 | hc.dendrogram(z, labels=df.columns, orientation='left', leaf_font_size=font_size)
64 | plt.show()
65 |
--------------------------------------------------------------------------------