#πŸ”’ Tensorflow error

87 messages Β· Page 1 of 1 (latest)

rose parrot
#

from tensorflow.keras.models import load_model <------ Getting an error and I've downloaded the most recent version of tensorflow? Is this package outdated?

rocky horizonBOT
#

@rose parrot

Python help channel opened

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.

autumn trench
rose parrot
#

let me check

#

nope its still not being recognized

autumn trench
#

what version of tf are you using

rose parrot
#

How do I find out but im pretty sure its the latest

autumn trench
#

pip show tensorflow

rose parrot
#

2.18.0

autumn trench
#

send the error please

#

the full traceback

#

I just downloaded that version of tf, ran the code, and got a warning but no error

rose parrot
#

how do I send you the traceback on this?

autumn trench
#

just copy paste it and dump it in a markdown block

#

```

stuff

```

rose parrot
#

'''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'''
rocky horizonBOT
#

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.
rose parrot
#

oops

autumn trench
#

` vs '

rose parrot
#
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```
autumn trench
#

nice

#

and the traceback too pls

rose parrot
#

I have no idea what that means

#

im a little new

autumn trench
#

all good

#

when you get an error message all the text that comes with it

#

!trace

rocky horizonBOT
#
Traceback

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.

rose parrot
#

oh alright

#

Oh wait it might be a warning

#

im not used to using vs code

#

which is what im currently using

autumn trench
#

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

rose parrot
#

Import "tensorflow.keras.models" could not be resolvedPylancereportMissingImports

autumn trench
#

oh

#

it's a linter warning

#

not even python lol

rose parrot
#

ohhhh wtf

autumn trench
#

does vscode in the bottom say something like "restricted mode"?

rose parrot
#

no would you like a screenshot?

autumn trench
#

sure

#

sometimes restricted workspaces can cause that issue

rose parrot
autumn trench
#

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

rose parrot
#

oh alright

autumn trench
#

you can even hover over and right click -> ignore smth like that to make it not highlight

rose parrot
#

oh okay

#

I did it

#

lol

#

Well anyways thanks this is my 2nd ever chatbot this time using tensorflow

#

its very confusing for me

autumn trench
#

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

rose parrot
#

Yeah lol

autumn trench
rose parrot
#

Yes

autumn trench
#

tf hasn't supported windows natively since 2.10

#

you might have to play around with downloading wsl or downgrading to an older version

rose parrot
#

so I gotta delete my version and download 2.10?

#

Because everything I have is supported till 2.8

autumn trench
#

basically

rose parrot
#

okay let me try that

#

I think I messed up

autumn trench
#

pip install tensorflow==2.10.0

rose parrot
#

oh thank you

#

NOOOOOOOOOOOOOO

#

This is the end of the world.

autumn trench
#

you can probably get the old wheel files and download from one of those

#

or install wsl

rose parrot
#

wsl?

autumn trench
#

windows subsystem linux

rose parrot
#

how do I download that

autumn trench
#

it's a microsoft software that basically emulates linux

rose parrot
#

oh alright

#

how do I download and integrate that?

autumn trench
rose parrot
#

So im downloading it right now, after will I just be able to run my code?

autumn trench
#

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

rose parrot
#

ohhhh alright thank you

rocky horizonBOT
#
Python help channel closed

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.