Issue
I'm following a tutorial to create a AI Chatbot in Python with deep learning (code from tutorial here: https://www.techwithtim.net/tutorials/ai-chatbot/part-1/) and I can't figure out why I'm getting "JSONDecodeError: Expecting value" when I try run my code. I've looked at the other threads getting this information but they either lack an answer or the problem seems to be in the user's coding logic as opposed to it being a general solution that I could also apply here. I've also used the Cmd prompt to make sure my environment (py36) is running python 3.6 as directed by the tutorial and has the necessary libraries installed. I'm hoping someone here could give me a hand?
Traceback of the error
Traceback (most recent call last):
File "C:\Users\mecha\Documents\AI\ChatbotCode.py", line 12, in <module>
data = json.load(file)
File "C:\ProgramData\Anaconda3\envs\py36\lib\json\__init__.py", line 299, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "C:\ProgramData\Anaconda3\envs\py36\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\ProgramData\Anaconda3\envs\py36\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\ProgramData\Anaconda3\envs\py36\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
JSONDecodeError: Expecting value
The code
import nltk
from nltk.stem.lancaster import LancasterStemmer
stemmer = LancasterStemmer()
import numpy
import tflearn
import tensorflow
import random
import json
with open('intents.json') as file:
data = json.load(file)
words = []
labels = []
docs_x = []
docs_y = []
for intent in data['intents']:
for pattern in intent['patterns']:
wrds = nltk.word_tokenize(pattern)
words.extend(wrds)
docs_x.append(wrds)
docs_y.append(intent["tag"])
if intent['tag'] not in labels:
labels.append(intent['tag'])
JSON File (intents.json)
{"intents": [
{"tag": "greeting",
"patterns": ["Hi", "How are you", "Is anyone there?", "Hello", "Good day"],
"responses": ["Hello, thanks for visiting", "Good to see you again", "Hi there, how can I help?"],
"context_set": ""
},
{"tag": "goodbye",
"patterns": ["Bye", "See you later", "Goodbye"],
"responses": ["See you later, thanks for visiting", "Have a nice day", "Bye! Come back again soon."]
},
{"tag": "thanks",
"patterns": ["Thanks", "Thank you", "That's helpful"],
"responses": ["Happy to help!", "Any time!", "My pleasure"]
},
{"tag": "hours",
"patterns": ["What hours are you open?", "What are your hours?", "When are you open?" ],
"responses": ["We're open every day 9am-9pm", "Our hours are 9am-9pm every day"]
},
{"tag": "payments",
"patterns": ["Do you take credit cards?", "Do you accept Mastercard?", "Are you cash only?" ],
"responses": ["We accept VISA, Mastercard and AMEX", "We accept most major credit cards"]
},
{"tag": "opentoday",
"patterns": ["Are you open today?", "When do you open today?", "What are your hours today?"],
"responses": ["We're open every day from 9am-9pm", "Our hours are 9am-9pm every day"]
}
]
}
Solution
The problem was that my program was calling intents.json as well as data.pickle in a later version but of course the data pickle wasn't initialised yet in this segment of the code so I kept getting a null error.
Answered By - Mech no.44
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.