#π Tensorflow error
87 messages Β· Page 1 of 1 (latest)
@rose parrot
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
can you just use keras.models instead of tensorflow.keras.models?
what version of tf are you using
How do I find out but im pretty sure its the latest
pip show tensorflow
2.18.0
send the error please
the full traceback
I just downloaded that version of tf, ran the code, and got a warning but no error
how do I send you the traceback on this?
'''import random
import json
import pickle
import numpy as np
import nltk
from nltk.stem import WordNetLemmatizer
from tensorflow.keras.models import load_model
lemmatizer = WordNetLemmatizer
intents = json.loads(open('intents.json').read())
words = pickle.load(open('words.pkl', 'rb'))
classes = pickle.load(open('classes.pkl', 'rb'))
model = load_model('chatbot_model.model')
def clean_up_sentence(sentence):
sentence_words = nltk.word_tokenize(sentence)
sentence_words = [lemmatizer.lemmatize(words) for word in sentence_words]
return sentence_words
def bag_of_words(sentence):
sentence_words = clean_up_sentence(sentence)
bag = [0] * len(words)
for w in sentence_words:
for i, word in enumerate(words):
if word == w:
bag[i] = 1
return np.array()
def predict_class(sentence):
bow = bag_of_words(sentence)
res = model.predict(np.array[(bow)])[0]
ERROR_THRESHOLD = 0.25
results = [[i, r] for i, r in enumerate(res) if r > ERROR_THRESHOLD]
results.sort(key=lambda x: x[1], reverse=True)
return_list = []
for r in results:
return_list.append({'intent': classes[r[0]], 'probability': str(r[1])})
return return_list'''
Hey @rose parrot!
It looks like you are trying to paste code into this channel.
You seem to be using the wrong symbols to indicate where the code block should start. The correct symbols would be ```, not '''.
Furthermore, it looks like you pasted Python code without syntax highlighting. Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.
To do this, use the following method:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
You can **edit your original message** to correct your code block.
oops
` vs '
import json
import pickle
import numpy as np
import nltk
from nltk.stem import WordNetLemmatizer
from tensorflow.keras.models import load_model
lemmatizer = WordNetLemmatizer
intents = json.loads(open('intents.json').read())
words = pickle.load(open('words.pkl', 'rb'))
classes = pickle.load(open('classes.pkl', 'rb'))
model = load_model('chatbot_model.model')
def clean_up_sentence(sentence):
sentence_words = nltk.word_tokenize(sentence)
sentence_words = [lemmatizer.lemmatize(words) for word in sentence_words]
return sentence_words
def bag_of_words(sentence):
sentence_words = clean_up_sentence(sentence)
bag = [0] * len(words)
for w in sentence_words:
for i, word in enumerate(words):
if word == w:
bag[i] = 1
return np.array()
def predict_class(sentence):
bow = bag_of_words(sentence)
res = model.predict(np.array[(bow)])[0]
ERROR_THRESHOLD = 0.25
results = [[i, r] for i, r in enumerate(res) if r > ERROR_THRESHOLD]
results.sort(key=lambda x: x[1], reverse=True)
return_list = []
for r in results:
return_list.append({'intent': classes[r[0]], 'probability': str(r[1])})
return return_list```
Please provide the full traceback for your exception in order to help us identify your issue.
While the last line of the error message tells us what kind of error you got,
the full traceback will tell us which line, and other critical information to solve your problem.
Please avoid screenshots so we can copy and paste parts of the message.
A full traceback could look like:
Traceback (most recent call last):
File "my_file.py", line 5, in <module>
add_three("6")
File "my_file.py", line 2, in add_three
a = num + 3
~~~~^~~
TypeError: can only concatenate str (not "int") to str
If the traceback is long, use our pastebin.
oh alright
Oh wait it might be a warning
im not used to using vs code
which is what im currently using
ah
if it's a warning then you don't need to worry about it
or I mean read it and see what it says but it won't stop you from using tf
Import "tensorflow.keras.models" could not be resolvedPylancereportMissingImports
ohhhh wtf
does vscode in the bottom say something like "restricted mode"?
no would you like a screenshot?
another thing could be that pylance is pointing to the wrong interpreter, one you haven't installed tensorflow on so it can't resolve the import
but that's not really anything to worry about it's just annoying at most
oh alright
you can even hover over and right click -> ignore smth like that to make it not highlight
oh okay
I did it
lol
Well anyways thanks this is my 2nd ever chatbot this time using tensorflow
its very confusing for me
np and good luck, language models are definitely fun projects even if they require you to get a little in the weeds to train and modify
Yeah lol
Wait I have another issue
are you on windows?
Yes
tf hasn't supported windows natively since 2.10
you might have to play around with downloading wsl or downgrading to an older version
so I gotta delete my version and download 2.10?
Because everything I have is supported till 2.8
basically
pip install tensorflow==2.10.0
you can probably get the old wheel files and download from one of those
or install wsl
wsl?
windows subsystem linux
how do I download that
it's a microsoft software that basically emulates linux
So im downloading it right now, after will I just be able to run my code?
once you do all the stuff and get a linux environment set up you run it from your wsl terminal
and it should work fine
ohhhh alright thank you
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.