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 (1, 46) for Tensor 'InputData/X:0', which has shape '(?, 4)' #1136

Open
karun12213 opened this issue Sep 10, 2019 · 0 comments

Comments

@karun12213
Copy link

How can i fix this error ?
please help

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 numpy.array(bag)

def chat():

print("Hey ! I'm Mick The Mechanic! Having a problem with your vehicle ?")

while True:
    inp = input("You:")
    if inp.lower() == "quit":
        break
    
    results = model.predict([bag_of_words(inp, words)])
    results_index = numpy.argmax(results)
    tag = labels[results_index]
    
    for tg in data["intents"]:
        if tg['tag'] == tag:
            responses = tg['responses']
            
    print(random.choice(responses))

chat()


ValueError Traceback (most recent call last)
in
35
36
---> 37 chat()
38
39

in chat()
22 break
23
---> 24 results = model.predict([bag_of_words(inp, words)])
25 results_index = numpy.argmax(results)
26 tag = labels[results_index]

~/anaconda3/lib/python3.7/site-packages/tflearn/models/dnn.py in predict(self, X)
255 """
256 feed_dict = feed_dict_builder(X, None, self.inputs, None)
--> 257 return self.predictor.predict(feed_dict)
258
259 def predict_label(self, X):

~/anaconda3/lib/python3.7/site-packages/tflearn/helpers/evaluator.py in predict(self, feed_dict)
67 prediction = []
68 if len(self.tensors) == 1:
---> 69 return self.session.run(self.tensors[0], feed_dict=feed_dict)
70 else:
71 for output in self.tensors:

~/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
948 try:
949 result = self._run(None, fetches, feed_dict, options_ptr,
--> 950 run_metadata_ptr)
951 if run_metadata:
952 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

~/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
1147 'which has shape %r' %
1148 (np_val.shape, subfeed_t.name,
-> 1149 str(subfeed_t.get_shape())))
1150 if not self.graph.is_feedable(subfeed_t):
1151 raise ValueError('Tensor %s may not be fed.' % subfeed_t)
ValueError: Cannot feed value of shape (1, 46) for Tensor 'InputData/X:0', which has shape '(?, 4)'

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

1 participant