Hi, I have entered the correct code and have compiled it. But it’s showing error as “NameError: name ‘tf’ is not defined”. Also not only tf but Model is also not defined error is appearing repeatedly. Can you please look into it?
Hi,
Is it possible that the jupyter notebook kernel was restarted and the first code cell needs to be re-run?
Yes I have tried that, but no use
Are you by any chance re-using the tf variable someplace else? like re-assigning it a value?
Hi!
Looks like there is now a different error, progress!
The line causing the error should be changed to:
model = tf.keras.Model([input_user, input_item], output)
Ok, please re-run the cell that imports tensorflow as tf
that section of code passed in your last screenshot, which leads me to believe that the jupyter notebook kernel was shutdown and needs to be re-run from the beginning. This can happen if you’ve closed the lab or left it alone for an extended period of time.
For more information about jupyter notebooks see their documentation: What is the Jupyter Notebook? — Jupyter Notebook 6.5.2 documentation
Click the double >> at the top and do a run all.
When the notebooks are shutdown they do not keep the results of what was run.
This means the notebook starts fresh when it is started from a shutdown.
Shutdowns happen when you leave the page or it is left unattended for too long.
If something important was run in a cell and then the notebook was shutdown it needs to be rerun in order for the results to be available further in the notebook.
This code cell should be after the code cell starting with
# GRADED_CELL
# UNQ_C1
Was the order of the code cells changed or were some of the code cells deleted?
If this is the case, I suggest saving the code between sections labeled:
### START CODE HERE ###
### END CODE HERE ###
and following these directions, to get your notebook into a correct state.
Everything is same as it was from beginning. I had just entered the code and it started showing those errors repeatedly. I am facing a huge issue with this assignment completion. I want support from the required team, as I am due to get my certificate which I have to submit for the MOOC a credit course in my semester.
Please do the needful
Thank You
Hi @SAINATH_BOREDA,
All error messages in this topic is about a name not being defined. Whenever this error comes to us, we have to check whether we have defined the name or not. There are 4 common ways of defining stuff in Python and they are often used in our assignments:
- a variable, defined by assigning a value to it, e.g.:
variable_name = 'This variable contains text'
- a function, defined with a
def
line, e.g.:
def function_name(input_argument_1, input_argument_2):
return 'This function returns text'
- a lambda function, defined with a
lambda
function assignment, e.g.:
lambda_function_name = lambda input_argument: 'This lambda function return text'
- a package or a part of a package, defined with an
import
line, e.g.:
import tensorflow as tf
from tensorflow.keras import Model
Next time, when you see an “XXX is not defined” error,
-
please look for the code that defines the name in error, run the code, and try again
-
if you can’t find the code for definition, it is either your notebook is incomplete (then follow Sam’s suggestion to reset your notebook and avoid changing any code outside of the exercise section), or it is your job to define it but you didn’t define it properly.
-
As a rule of thumb, everytime you start to work on a notebook, please make sure you run all the code cells from the very first one, then one by one and make sure each and every one of them is successful. If a cell is unsuccessful, stop there and fix the problem before moving on.
If you encounter other errors and if you want to look for how others fix that error immediately, then I would suggest you to google the error message. For example, you could have googled “Python tf is not defined”, or you can google “Python <error message>”.
Cheers,
Raymond