I'm new to coding and am following Tech with Tim's chatbot tutorial. I believe everything is copied exactly how he wrote it but it keeps throwing that error. I'm using tflearn and tensor flow 1.15 It keeps giving me warnings for deprecation so i had to add the ignore warnings part import warnings warnings.filterwarnings("ignore")
import nltk
from nltk.stem.lancaster import LancasterStemmer
stemmer = LancasterStemmer()
import numpy
import tflearn
import tensorflow
import random
import json
import pickle
with open("/Users/Jerrod/Documents/intents.json") as file:
data = json.load(file)
try:
with open("data.pickle", "rb") as f:
words, labels, training, output = pickle.load(f)
except:
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"])
words = [stemmer.stem(w.lower()) for w in words if w not in "?"]
words = sorted(list(set(words)))
labels = sorted(labels)
training = []
output = []
out_empty = [0 for _ in range(len(labels))]
for x, doc in enumerate(docs_x):
bag = []
wrds = [stemmer.stem(w.lower()) for w in words if w != "?"]
for w in words:
if w in wrds:
bag.append(1)
else:
bag.append(0)
output_row = out_empty[:]
output_row[labels.index(docs_y[x])] = 1
training.append(bag)
output.append(output_row)
training = numpy.array(training)
output = numpy.array(output)
with open("data.pickle", "wb") as f:
pickle.dump((words, labels, training, output), f)
tensorflow.reset_default_graph()
net = tflearn.input_data(shape=[None, len(training[0])])
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, len(output[0]), activation="softmax")
net = tflearn.regression(net)
model = tflearn.DNN(net)
try:
model.load("model.tflearn")
except:
model.fit(training, output, n_epoch=1000, batch_size=8, show_metric=True)
model.save("model.tflearn")
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("Start talking with the bot (type quit to stop!")
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()
WARNING:tensorflow:From /Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/collections.py:13: The name tf.GraphKeys is deprecated. Please use tf.compat.v1.GraphKeys instead.
WARNING:tensorflow:From /Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/main.py:71: The name tf.reset_default_graph is deprecated. Please use tf.compat.v1.reset_default_graph instead.
WARNING:tensorflow:From /Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/layers/core.py:66: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.
WARNING:tensorflow:From /Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/layers/core.py:69: The name tf.add_to_collection is deprecated. Please use tf.compat.v1.add_to_collection instead.
WARNING:tensorflow:From /Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/initializations.py:173: calling TruncatedNormal.init (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version. Instructions for updating: Call initializer instance with the dtype argument instead of passing it to the constructor WARNING:tensorflow:From /Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/variables.py:44: The name tf.get_variable is deprecated. Please use tf.compat.v1.get_variable instead.
WARNING:tensorflow:From /Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/optimizers.py:238: The name tf.train.AdamOptimizer is deprecated. Please use tf.compat.v1.train.AdamOptimizer instead.
WARNING:tensorflow:From /Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/layers/estimator.py:96: The name tf.get_collection is deprecated. Please use tf.compat.v1.get_collection instead.
WARNING:tensorflow:From /Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/objectives.py:114: calling reduce_sum_v1 (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version. Instructions for updating: keep_dims is deprecated, use keepdims instead WARNING:tensorflow:From /Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/objectives.py:118: The name tf.log is deprecated. Please use tf.math.log instead.
WARNING:tensorflow:From /Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/layers/estimator.py:141: The name tf.trainable_variables is deprecated. Please use tf.compat.v1.trainable_variables instead.
WARNING:tensorflow:From /Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/helpers/trainer.py:457: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.
WARNING:tensorflow:From /Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/config.py:130: The name tf.assign is deprecated. Please use tf.compat.v1.assign instead.
WARNING:tensorflow:From /Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/helpers/trainer.py:95: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.
2020-01-11 13:22:30.927045: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA 2020-01-11 13:22:30.940158: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7f9fba93cac0 initialized for platform Host (this does not guarantee that XLA will be used). Devices: 2020-01-11 13:22:30.940171: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version Traceback (most recent call last): File "/Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/main.py", line 79, in model = tflearn.DNN(net) File "/Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/models/dnn.py", line 57, in init session=session) File "/Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/helpers/trainer.py", line 111, in init clip_gradients) File "/Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/helpers/trainer.py", line 561, in initialize_training_ops ema_num_updates=self.training_steps) File "/Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/summaries.py", line 243, in add_loss_summaries summaries_collection_key) File "/Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tflearn/summaries.py", line 46, in get_summary summ = tf.scalar_summary(tag, value) File "/Users/Jerrodthompson/PycharmProjects/justanotherchatbotattempt/venv/lib/python3.6/site-packages/tensorflow_core/python/util/module_wrapper.py", line 193, in getattr attr = getattr(self._tfmw_wrapped_module, name) AttributeError: module 'tensorflow' has no attribute 'scalar_summary'