Lesson 4 - Official Topic

My daughter made me this

mask and even sewed a pocket on the inside so that I can put a coffee filter.

7 Likes

Is anyone else getting this error on notebook 5? I had already done a git pull.
Softmax is similar to the sigmoid function, which we saw earlier; sigmoid looks like this:

plot_function(torch.sigmoid, min=-4,max=4)

NameError Traceback (most recent call last)
in
----> 1 plot_function(torch.sigmoid, min=-4,max=4)

NameError: name ‘plot_function’ is not defined

You need to import the functions from utils.py where the function is written. It’s the first import statement on top of every notebook.

Did you git pull fastcore as well?

Just posted the video: https://youtu.be/p50s63nPq9I

6 Likes

To be precise, it is utils of fastbook(not fastai2).

You have probably already figured things out by now, but just for future reference, some more detail.

To find out where plot_function is defined, run

plot_function?

in a cell, and information will be displayed in a separate banner at the bottom of the browser. File gives the path to the file where plot_function is located.

Alternatively,

import inspect
print(inspect.getmodule(plot_function))

will print directly the path to the module utils. For example, I get

<module 'utils' from '/Users/antoine/fastai/fastbook/utils.py'>

Note that this file utils.py is in the same folder as the notebook. Thus, this module can be loaded with

import utils

in which case plot_function is accessible with utils.plot_function.

Alternatively, run

from utils import plot_function

to load only plot_function or, as is done in the first cell of the notebook (as pointed out by harish3110), load everything from utils with

from utils import *

Thanks for the detailed explanation. Yes, it’s working. I do normally run the from utils import * at the top of the notebook, but for some reason, it wasn’t working so I had to reload a new version of the jupyter notebook

thanks

No, I normally don’t pull from fastcore. I had run the from utils import * at the top of the notebook but it wasn’t working for some reason so I ended up loading a new version of the notebook and re-running it.

I am realizing that my detailed explanation is a non-answer to your question: it provides absolutely no help if the function cannot be found to begin with.

To redeem myself, I will paraphrase harish3110’s answer:

In case of
NameError: name [whatever] is not defined
the solution is almost always to reload the first cell in the Jupiter notebook.

Hi @jeremy, would the links to the paper and masks4all be appropriate here? Or is that only for the Covid-19 category?
FYI, I’d be happy to add it myself. Just wondering if we want that here or somewhere else.

EDIT: I’ve just gone ahead and done it since I am assuming you’re quite busy :slight_smile: Tagging @init_27 since he’s a moderator too, just to be sure.

Saturday 18th April 9.00am I have just completed my viewing 2 parts of lesson4. And my comment I am going to place here rather than any other category to do with as you wish.

RE: Masks

Yesterday I went to a local supermarket for my fortnightly shop and I am waiting in the queue at the check out wearing my mask. A lady behind me says what’s the good of the mask, see says she worked 40 years in the NHS till 1992 and masks were banned because they spread disease as the carry disease after use. Unfortunately we got into a mildly heated debate to the point she called me argumentative. I would be happy with that if she later looked more clearly at the evidence at masksforall and the early uptake of the Czech mask law. Her final question to me was why certain populations are more prone to the virus which I did not answer. If I was to answer it would be physical health, unfortunately many can’t improve that part of there physiology because of prior ailments.

So the point here is related to the ending of Lesson 4, there are many such people who need convincing such as this lady, and would just like to say thank you for your heart felt efforts, please keep going with these endeavours.

1 Like

Thanks for adding it!
I think it’s okay to link it here as well since it was a part of the lecture (and is imp too) :white_check_mark:

1 Like

params.data has 3 values in the tensor. I expected it to only have 2 i.e. weights and biases or 1 value that stores the value of each run of the params calculation in SGD. Why do I see 3 values and what are these 3 values?

tensor([ 0.1420, -0.6921, 1.3573])

I executed the params.data before the code below:

def train_epoch(model, lr, params):
for xb,yb in dl:
calc_grad(xb, yb, model)
for p in params:
p.data -= p.grad*lr
p.grad.zero_()

1 Like

Running params.data before the training loop will show the values that you initialised it to.

What’s the model that you’re trying to learn? Perhaps you’re learning the parameters of a quadratic function, like in the lecture? In that case, params is a tensor containing the parameters of the quadratic function namely, ‘a’, ‘b’ and ‘c’.
You’ll just have to see what you did with the params tensor before coming to that training loop.

I am running the 04_mnist_basics.ipynb notebook and the equation that is used is y=mx+c (equation of a line) and not a quadratic equation. Hence I am not sure why there are 3 values in the tensor.

Also, params.name returns None and hence I am not sure which are the params that the tensor currently has.

params is of size 3 because of this line earlier in the notebook where it was used for the quadratic equation: params = torch.randn(3).requires_grad_().

When you start working on the MNIST loss function section, note that this command comes a few cells after the def train_epoch section that you copied: params = weights,bias. That changes params before you actually run train_epoch with:

lr = 1.
params = weights,bias
train_epoch(linear1, lr, params)
validate_epoch(linear1)

Note again, in the code section that you have pasted, we’re only defining the function and not running it. Hope this helps.

Ok. Thanks

1 Like

A question from the study group :slightly_smiling_face:

Why is the negative sign in the log likelihood formula. In the fastbook, it is represented as:
-sm_acts[idx, targ]
Jeremy said he was a bit tired so he couldn’t explain it in the last class. Thank you!

1 Like