Hello guys!
I am facing this issues. NameError: name ‘tensorflow’ is not defined
Is there any suggestions? Pretty much appreciated all the answer.
Thanks in advance.
Cheers
Can you please share some code images…
There is mostly an import issue in your code
Here is my code:
def features_and_labels(input_sequences, total_words):
features = input_sequences[:,:-1]
labels = input_sequences[:,-1]
one_hot_labels = tensorflow.keras.utils.to_categorical(labels, num_classes=total_words)
return features, one_hot_labels
usually we import tensorflow like this:
import tensorflow as tf
so whenever you want to use tensorflow
you write it as tf
, so the one_hot_labels
will be:
one_hot_labels = tf.keras.utils.to_categorical(labels, num_classes=total_words)
hope this helps.
Thanks for your suggestion. I tried it, too. I got the error, no module named “tf”.
I tried install tensorflow again, too. but still
Check if you have imported tensorflow correctly and also check if you are running the cell which has imports inside of it. If this still doesn’t work, try restarting the notebook again, by clicking on kernel > restart and clear output. Maybe this might help.
Thank you, I replace tensorflow by tf in the error cell and it worked.
But in the second cell is like this:
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.layers import Embedding, LSTM, Dense, Bidirectional
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.models import Sequential
from tensorflow.keras.optimizers import Adam
It worked but there are yellow underline for all the tensorflow in this cell
I don’t understand…
Anyway, thanks for your help
You can always ignore the yellow underlines. Yellow underline means a warning
. Warnings can be ignored.
Thank you very much for your help!
import tensorflow as tf
and use tf. instead of tensorflow.
solved my problem…