1
votes
    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/Jerrodthompson/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()

Error Code:

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:70: 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:40:33.068166: 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:40:33.085284: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fbfbc0cbc80 initialized for platform Host (this does not guarantee that XLA will be used). Devices: 2020-01-11 13:40:33.085301: 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 78, 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'

2

2 Answers

0
votes

A warning is not an error. In this case it is just giving you information that advises you to use a different API method, as the one you are currently using is 'deprecated' (it will not be available in future releases but works for now).

Try replacing

tf.GraphKeys

with

tf.compat.v1.GraphKeys

as it suggests and the error should disappear.

0
votes

There is no error in your code but libraries you use they are old for the first part you can use

import warnings
warnings.simplefilter('ignore', FutureWarning)

at top of code, and then you will only get

WARNING:tensorflow

for that you either have to edit code in

~/.local/lib/python3.7/site-packages/LibrabrName

Or if just don't want to see a warning and don't care about them use

import os
os.system("clear")

at end of imports