简体   繁体   English

创建一个 AI 聊天机器人,无需学习如何回答用户提出的每个问题即可学习如何聊天

[英]Create a AI chatbot that learns how to chat without learning how to answer every question given by the user

My code is only this and it would only recognize specific questions... else it asks for the answer... but I want it to be able to learn and try to self-answer my new question.我的代码只是这个,它只会识别特定的问题......否则它会要求答案......但我希望它能够学习并尝试自我回答我的新问题。

example:例子:

input("hello")

output("Hi, how are you?")

without teaching the ai chatbot about what to respond to "hi", I would want it to be able to respond back too在不教人工智能聊天机器人如何回应“嗨”的情况下,我希望它也能够回应

Like:喜欢:

 input("Hi")

 output("Hello, how are you?")

It is very difficult for me and that is why I am requesting for an answer for it这对我来说非常困难,这就是为什么我要求回答

My current code:我当前的代码:

said = []
output = []
text = ""

global n

while True:
    text = input("Say something: ")
    if not(text == ""):
        if not(text == "print(input, output)"):
            input_contain = text.lower() in said

            if input_contain:
                n = 0
                found = False
                while not found:
                    if said[n] == str(text.lower()):
                        print(output[n])
                        found = True
                    else:
                        n = n + 1
            else:

                output_add = input("What should I respond to that? ")
                if not output_add == "":
                    said.append(text.lower())
                    output.append(output_add)
                else:
                    print("Error in output")
        else:

            for qn in said:
                if not qn == int(len(said)) - 1:
                    print(str(qn), end=", ")
                else:
                    print(qn)

            for out in output:
                if not out == int(len(output)) - 1:
                    print(str(out), end=", ")
                else:
                    print(out)

    else:
        print("Error in input") 

If you have a prebuilt set of responses, such as the "Hi, how are you", you could build a set of appropiate prompt questions for such responses, and compare the similarity (using eg spacy nlp ) between the user input and your known prompt questions.如果您有一组预先构建的响应,例如“嗨,你好吗”,您可以为此类响应构建一组适当的提示问题,并比较用户输入和您已知的相似度(例如使用spacy nlp )提示问题。

You could take the highest similar prompt question in order to identify the most similar question that has previoulsy been mapped to a response - then answer that questions answer, as the response.您可以采用相似度最高的提示问题,以识别先前已映射到响应的最相似问题 - 然后回答该问题的答案作为响应。


For example, "Hello" and "Hi" have much higher similarity (0.9 or so) than "Hello" and "What is a scary animal?"例如,“你好”和“嗨”的相似度比“你好”和“什么是可怕的动物?”具有更高的相似度(0.9 左右)。 do (near 0)..做(接近0)..

So if you had所以如果你有

"What is a scary animal?" “什么是可怕的动物?” ==> "Tiger", ==> "老虎",

"Hi" => "Hello, how are you"? “嗨” => “你好,你好吗”?

"Hello" would map 0.9 to "Hi" and near 0 to "What is a scary animal", so pick "Hello"s answer, which is "Hello, how are you?" “你好”会 map 0.9 到“嗨”,接近 0 到“什么是可怕的动物”,所以选择“你好”的答案,即“你好,你好吗?”

"What is a fierce animal" would map closer to "What is a scary animal", so pick Tiger for that.. “什么是凶猛的动物”会 map 更接近“什么是可怕的动物”,所以选择老虎。


To allow your program to improve, you would need to save the mappings somewhere and add more.. this is roughly how GOFAI chat bots work为了让您的程序改进,您需要将映射保存在某处并添加更多.. 这大致是 GOFAI 聊天机器人的工作方式

Machine Learning is a statistical mechanism.机器学习是一种统计机制。 Here is a link somewhat related: "Estimate" the amount of training needed in advance这是一个有点相关的链接: “估计”提前需要的培训量

Personally, that is not "intelligence".就个人而言,这不是“智能”。 Imagine having to retrain the bot on the live, when the user says something to be reused in future questions.想象一下,当用户说出要在未来问题中重复使用的内容时,必须在现场重新训练机器人。

There is another approach to replying questions in chatbot fashion, that is called Natural Language Processing (check stackoverflow tag NLP).还有另一种以聊天机器人方式回答问题的方法,称为自然语言处理(检查 stackoverflow 标签 NLP)。 Specially Logic/Semantic processing can break down the user input into its constituents and from there develop the appropriate response.特别是逻辑/语义处理可以将用户输入分解为其组成部分,并从那里开发出适当的响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何构建一个从语料库中学习的人工智能系统,并在用户询问与该语料库相关的任何内容时回答用户 - How to build an AI system which learns from corpus and answers to the user whenever they ask anything related to that corpus 有没有学习如何缩放的层? - is there a layer, that learns how to scale? 如何使用 python 中给出的预定义输入和响应创建聊天机器人? - How to create chatbot with predefined inputs and responses are given in python? 如何连接Python chatbot和Java chat room - How to connect Python chatbot and Java chat room 如何使用 html 和 flask 与聊天机器人聊天 - How do I chat with the chatbot with html and flask 用户点击botframework chatbot中的按钮后如何聊天窗口显示所选值? - how to chat window to display the selected value after the user clicks the button in the botframework chatbot? Python Telegram Bot 如何等待用户回答问题并返回 - Python Telegram Bot how to wait for user answer to a question And Return It 将从给定的信息/文档中回答的聊天机器人 - Chatbot that will answer from the given Information/Documents 如何设置答案将关联的问题? - How to set the question that an answer will be associated with? 如何回答是和否问题 paramiko - How to answer Yes and No question paramiko
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM