Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

chatterbot not finding responses and failing to select from multiple responses

Having previously run conversations using a single corpus, which were?rather directionless and full of non-sequiturs, I am now looking to have a lot of fun? with the latest version of chatterbot. I am trying?to focus my conversation to?be more relevant by? using a set of bots,?each? trained with a? different? corpus, and switching between them?according to the context of the conversation.? Is this idea reasonable or pointless? Looking at my output? I am getting good input text matches, but no suitable responses are? being found, only randomly selected ones with a confidence of 0.? Except when suitable responses ARE found, bestmatch,py select_response fails.? Any human response would be most welcome!

import os, argparsefrom chatterbot 
import ChatBotfrom chatterbot.trainers 
import ChatterBotCorpusTrainer
def bot(title, read_only = True):? ? # , don't learn from exchanges (responses exist)
? ? Bot = ChatBot(title,? ? ? ? ? ? ? ? ? ?#filters=["chatterbot.filters.RepetitiveResponseFilter"],? ? ? ? ? ? ? ? ? ?logic_adapters=[{? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ?'import_path': 'chatterbot.logic.BestMatch',? ? ? ? ? ? ? ? ? ? ? ?"statement_comparision_function": "chatterbot.comparisions.levenshtein_distance",? ? ? ? ? ? ? ? ? ? ? ?"response_selection_method": "chatterbot.response_selection.get_first_response"? ? ? ? ? ? ? ? ? ? ? ?}])? ? print('Training corpus',title)? ? trainer=ChatterBotCorpusTrainer(Bot)? ? trainer.train("chatterbot.corpus.english." + title)
? ? ?? ? return Bot? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# trained instance
bots = {}  # check what corpora available and traina a bot for each onefor item in os.listdir('C:/Python/Python38/lib/site-packages/chatterbot_corpus/data/english/'):? ? corpus = item.split('.')? ? ? ? # of the form 'item.yml'
? ? name = corpus[0]
? ? bots[name]= bot(name)? # add bot instance to dictionary of available bots? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
def exchange(input):? # let's get a response to our input
? ? # try suggested corpora to find best fit. If first corpus < theshold, try another.
? ? # avoid random responses confidence 0
? ? bot = bots[context]
? ? response = bot.get_response(input)
? ? if? response.confidence < hi_threshold:? # not a good answer, look elsewhere
? ? ? ? if context != 'conversations':
? ? ? ? ? ? response = bots['conversations'].get_response(input)
? ? ? ? if? response.confidence < lo_threshold:? # not a good answer either
? ? ? ? ? ? print('WARN: no good answer from',context,' or conversation')
? ? print(input, context, response.id, response.confidence, response.text)
import logginglogging.basicConfig(level=logging.INFO)? ? # Enable info level logging
lo_threshold, hi_threshold = .25, .65
context = 'greetings'
exchange('Good Morning')
exchange('How are you today?')
exchange('I am a human. Who are you?')
context = 'ai'
exchange('are you a robot?')? ? ? ? 
exchange('are you intelligent?')
exchange('can machines think?')??
exchange('do you have emotions?')

INFO:chatterbot.chatterbot:Beginning search for close text matchINFO:chatterbot.chatterbot:Processing search resultsINFO:chatterbot.chatterbot:Similar text found: Good morning! 0.96INFO:chatterbot.chatterbot:Similar text found: Good Morning 1.0INFO:chatterbot.chatterbot:Using "Good Morning" as a close match to "Good Morning" with a confidence of 1.0INFO:chatterbot.chatterbot:No responses found. Generating alternate response list.INFO:chatterbot.chatterbot:No known response to the input was found. Selecting a random response.INFO:chatterbot.chatterbot:BestMatch selected "Did I ever live?" as a response with a confidence of 0INFO:chatterbot.chatterbot:Adding "Good Morning" as a response to "I am a human. Who are you?"INFO:chatterbot.chatterbot:Beginning search for close text matchINFO:chatterbot.chatterbot:Processing search resultsINFO:chatterbot.chatterbot:Similar text found: Good morning! 0.96INFO:chatterbot.chatterbot:Similar text found: Good Morning 1.0INFO:chatterbot.chatterbot:Using "Good Morning" as a close match to "Good Morning" with a confidence of 1.0INFO:chatterbot.chatterbot:No responses found. Generating alternate response list.INFO:chatterbot.chatterbot:No known response to the input was found. Selecting a random response.INFO:chatterbot.chatterbot:BestMatch selected "you are cheating" as a response with a confidence of 0INFO:chatterbot.chatterbot:Adding "Good Morning" as a response to "Good Morning" WARN: no good answer from greetings? or conversationGood Morning greetings None 0 you are cheating INFO:chatterbot.chatterbot:Beginning search for close text matchINFO:chatterbot.chatterbot:Processing search resultsINFO:chatterbot.chatterbot:Similar text found: How are you today? 1.0INFO:chatterbot.chatterbot:Using "How are you today?" as a close match to "How are you today?" with a confidence of 1.0INFO:chatterbot.chatterbot:No responses found. Generating alternate response list.INFO:chatterbot.chatterbot:No known response to the input was found. Selecting a random response.INFO:chatterbot.chatterbot:BestMatch selected "Not right now, no." as a response with a confidence of 0INFO:chatterbot.chatterbot:Adding "How are you today?" as a response to "Good Morning"INFO:chatterbot.chatterbot:Beginning search for close text matchINFO:chatterbot.chatterbot:Processing search resultsINFO:chatterbot.chatterbot:Similar text found: How are you today? 1.0INFO:chatterbot.chatterbot:Using "How are you today?" as a close match to "How are you today?" with a confidence of 1.0INFO:chatterbot.chatterbot:No responses found. Generating alternate response list.INFO:chatterbot.chatterbot:No known response to the input was found. Selecting a random response.INFO:chatterbot.chatterbot:BestMatch selected "Thank you." as a response with a confidence of 0INFO:chatterbot.chatterbot:Adding "How are you today?" as a response to "How are you today?"WARN: no good answer from greetings? or conversationHow are you today? greetings None 0 Thank you.INFO:chatterbot.chatterbot:Beginning search for close text matchINFO:chatterbot.chatterbot:Processing search resultsINFO:chatterbot.chatterbot:Similar text found: AI is the field of science which concerns itself with building hardware and software that replicates the functions of the human mind. 0.15INFO:chatterbot.chatterbot:Similar text found: A chat robot is a program that attempts to simulate the conversation or "chat" of a human being. 0.21INFO:chatterbot.chatterbot:Similar text found: Much the same as being a human, except that we lack all emotions, dreams, aspirations, creativity, ambition, and above all subjectivity. 0.25INFO:chatterbot.chatterbot:Similar text found: What is it like to be a human? 0.39INFO:chatterbot.chatterbot:Similar text found: A human. 0.47INFO:chatterbot.chatterbot:Similar text found: I am a human. Who are you? 1.0INFO:chatterbot.chatterbot:Using "I am a human. Who are you?" as a close match to "I am a human. Who are you?" with a confidence of 1.0INFO:chatterbot.chatterbot:No responses found. Generating alternate response list.INFO:chatterbot.chatterbot:No known response to the input was found. Selecting a random response.INFO:chatterbot.chatterbot:BestMatch selected "what does hal stand for" as a response with a confidence of 0INFO:chatterbot.chatterbot:Adding "I am a human. Who are you?" as a response to "How are you today?"INFO:chatterbot.chatterbot:Beginning search for close text matchINFO:chatterbot.chatterbot:Processing search resultsINFO:chatterbot.chatterbot:Similar text found: AI is the field of science which concerns itself with building hardware and software that replicates the functions of the human mind. 0.15INFO:chatterbot.chatterbot:Similar text found: A chat robot is a program that attempts to simulate the conversation or "chat" of a human being. 0.21INFO:chatterbot.chatterbot:Similar text found: Much the same as being a human, except that we lack all emotions, dreams, aspirations, creativity, ambition, and above all subjectivity. 0.25INFO:chatterbot.chatterbot:Similar text found: What is it like to be a human? 0.39INFO:chatterbot.chatterbot:Similar text found: A human. 0.47INFO:chatterbot.chatterbot:Similar text found: I am a human. Who are you? 1.0INFO:chatterbot.chatterbot:Using "I am a human. Who are you?" as a close match to "I am a human. Who are you?" with a confidence of 1.0INFO:chatterbot.chatterbot:No responses found. Generating alternate response list.INFO:chatterbot.chatterbot:No known response to the input was found. Selecting a random response.INFO:chatterbot.chatterbot:BestMatch selected "In all probability, I am not. I'm not that sophisticated." as a response with a confidence of 0INFO:chatterbot.chatterbot:Adding "I am a human. Who are you?" as a response to "I am a human. Who are you?" WARN: no good answer from greetings? or conversationI am a human. Who are you? greetings None 0 In all probability, I am not. I'm not that sophisticated. INFO:chatterbot.chatterbot:Beginning search for close text matchINFO:chatterbot.chatterbot:Processing search resultsINFO:chatterbot.chatterbot:Similar text found: Are you a robot? 1.0INFO:chatterbot.chatterbot:Using "Are you a robot?" as a close match to "are you a robot?" with a confidence of 1.0INFO:chatterbot.chatterbot:Selecting response from 19 optimal responses. Traceback (most recent call last):? File "C:PythonPython38OurStuffAIAI chatbot? training_example_corpus.py", line 65, in ? ? exchange('are you a robot?')? ? ? ? ? ? ?? File "C:PythonPython38OurStuffAIAI chatbot? training_example_corpus.py", line 49, in exchange? ? response = bot.get_response(input)? File "C:PythonPython38libsite-packageschatterbotchatterbot.py", line 137, in get_response? ? response = self.generate_response(input_statement, additional_response_selection_parameters)? File "C:PythonPython38libsite-packageschatterbotchatterbot.py", line 173, in generate_response? ? output = adapter.process(input_statement, additional_response_selection_parameters)? File "C:PythonPython38libsite-packageschatterbotlogicest_match.py", line 87, in process? ? response = self.select_response(TypeError: 'str' object is not callable>>>?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...