Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Cannot feed value of shape (61,) for Tensor 'InputData/X:0', which has shape '(?, 61)' #1164

Open
monibaka opened this issue Apr 5, 2021 · 1 comment

Comments

@monibaka
Copy link

monibaka commented Apr 5, 2021

HELP needed.
How can I fix this error?

`
def bag_of_words(s, words):
bag = [0 for _ in range(len(words))]

s_words = nltk.word_tokenize(s)
s_words = [stemmer.stem(word.lower()) for word in s_words]

for se in s_words:
    for i, w in enumerate(words):
        if w == se:
            bag[i] = 1

return np.array(bag)

def chat():
print("Start talking with the bot! (type quit to stop)")
while True:
inp = input("You: ")
if inp.lower() == "quit":
break

    result = model.predict([bag_of_words(inp, words)])[0]
    result_index = np.argmax(result)
    tag = labels[result_index]

    if result[result_index] > 0.7:
        for tg in data["intents"]:
            if tg['tag'] == tag:
                responses = tg['responses']
        print(random.choice(responses))

    else:
        print("I didnt get that. Can you explain or try again.")

chat()`

And when I run it I get:
Start talking with the bot! (type quit to stop)

You: j
Traceback (most recent call last):

File "", line 22, in
chat()

File "", line 8, in chat
result = model.predict([bag_of_words(inp, words)])

File "C:\Users\monik\anaconda3\lib\site-packages\tflearn\models\dnn.py", line 251, in predict
return self.predictor.predict(feed_dict)

File "C:\Users\monik\anaconda3\lib\site-packages\tflearn\helpers\evaluator.py", line 69, in predict
return self.session.run(self.tensors[0], feed_dict=feed_dict)

File "C:\Users\monik\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\client\session.py", line 967, in run
result = self._run(None, fetches, feed_dict, options_ptr,

File "C:\Users\monik\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\client\session.py", line 1164, in _run
raise ValueError(

ValueError: Cannot feed value of shape (61,) for Tensor 'InputData/X:0', which has shape '(?, 61)'

I tried to reshape it, but still it doesn't work

@rojagtap
Copy link

rojagtap commented Jan 9, 2022

Can you try using model.predict(np.expand_dims(bag_of_words(inp, words), axis=0))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants