Search code examples
tensorflowdeep-learningnlpchatbot

Intent chatbot with numeric and strings data


I am trying to build a chatbot using intents as json file, an example of the intent is

{"tag": "thanks",
         "patterns": ["Thanks", "Thank you", "That's helpful"],
         "responses": ["Happy to help!", "Any time!", "My pleasure"]
        },

I have a lot of other tags but I want the chatbot to detect the response based on the input text and other factors for example speech intensity which will be a value ranges from 1-10. The chatbot has been trained using tensorflow. How can I modify the intent file and input to the chatbot a text together with some information.

Chatbot operates by this code


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("Chatbot: ",random.choice(responses))

What I want is that for example speech intensity is 8 and the sentence is “what do you want” the response should be something like this “Why are you nervous?”


Solution

  • You can add to the intent file a function that can do any purpose in each intent. for example

    {"tag": "thanks",
             "patterns": ["Thanks", "Thank you", "That's helpful"],
             "responses": ["Happy to help!", "Any time!", "My pleasure"]
             "action": getname()
            },