Chatterbot: How can chatterbot only output the matching answer, and only one of these answers?

Created on 8 Jun 2017  ·  13Comments  ·  Source: gunthercox/ChatterBot

I have used mango db to train my bot.

["大海","蓝蓝的一望无际"],
["大海","好想陪你去看海"],

I have used chatterbot filters in my python file

filters=['chatterbot.filters.RepetitiveResponseFilter'],

when I input first time "大海",chatterbot response is "蓝蓝的一望无际"
when I input second time "大海", chatterbot response is "好想陪你去看海"
when I input third time "大海",chatterbot response neither "蓝蓝的一望无际" nor "好想陪你去看海" ,

When i removed filters from my python the response are differ from previous and

filters=['chatterbot.filters.RepetitiveResponseFilter'],

when I input first time "大海",chatterbot response is "蓝蓝的一望无际"
when I input second time "大海",chatterbot response is "蓝蓝的一望无际"
when I third input "大海",chatterbot response is "蓝蓝的一望无际"
always reponse "蓝蓝的一望无际"

Now, I want chatterbot has to reply one of both ("蓝蓝的一望无际" and "好想陪你去看海" ), when i input "大海" and No matter how many times i input "大海"

All 13 comments

@gunthercox @vkosuri matser

@gunthercox master, this question and #725 is different question.

Apologies, I don't understand Chinese language could you please elaborated in English?

Please correct me if I'm wrong. I want to try to paraphrase the problem you are describing to make sure that I understand it.

Your chat bot always returns the same output, regardless of what input it receives. Am I correct?

@vkosuri using Chinese is question and answer. ["大海","蓝蓝的一望无际"] equal ["sea,"blue and vast"], this is question and answer.

@gunthercox when i used RepetitiveResponseFilter chatterbot returns only answer,

when I haven't included response filter, chatterbot returns other responses that is not expected

So then i have rewrite RepetitiveResponseFilter filter like this

class ResponseFilter(Filter):
    def filter_selection(self, chatterbot, session_id):
        session=chatterbot.conversation_sessions.get(session_id)

        if session.conversation.empty():
            return chatterbot.storage.base_query

        text_of_recent_responses = []

        for statement, response in session.conversation:
            text_of_recent_responses.append(response.text)

        query = chatterbot.storage.base_query.get_random(text_of_recent_responses)
        return query

@Air-boy Is it possible that the response is being given on every input because there isn't another alternative for the chat bot to respond with?

I just want it to output one of the answers I give

    def filter_selection(self, chatterbot, session_id):

        session = chatterbot.conversation_sessions.get(session_id)

        if session.conversation.empty():
            return chatterbot.storage.base_query

        text_of_recent_responses = []

        for statement, response in session.conversation:
            text_of_recent_responses.append(response.text)

#        query = chatterbot.storage.base_query.statement_text_in(
            text_of_recent_responses
        )

        return query

@Air-boy I apologize, I don't think I fully understand what you are asking.

@gunthercox i give you my server address http://47.92.106.197:8890/?message=你吃了吗
and my sample corpus.json

{
    "testFilter":[        
        ["你吃了吗","我不需要吃东西,也会有无穷的力量滴。哈哈哈哈哈"],
        ["你吃了吗","您要给我吃的东西吗?是什么是什么?我很好奇。"],
        ["你吃了吗","还没还没,您要是带给我东西吃我是不会介意滴,尽管来!"]        
    ]
}

and my example chatterbot,py file

import tornado.ioloop
import tornado.web

from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer

bot = ChatBot("hebi",
    read_only=True,
    storage_adapter="chatterbot.storage.MongoDatabaseAdapter",
    logic_adapters=[
        {
            'import_path':"chatterbot.logic.BestMatch"
        },
        {
            'import_path':'chatterbot.logic.LowConfidenceAdapter',
            'threshold': 1.0,
            'default_response': 'I din't understand'
        }
    ],
    #filters=['chatterbot.filters.RepetitiveResponseFilter'],
    database="chatterbot-testFilter-database",
    database_uri="mongodb://*********:27017"
)

#指定语料数据集的training class
bot.set_trainer(ChatterBotCorpusTrainer)
bot.train("./testFilter.corpus.json")

class MainHandler( tornado.web.RequestHandler ):
    def get( self ):
        response = bot.get_response(self.get_argument('message'))
        self.write(str(response))
        application = tornado.web.Application( [( r'/', MainHandler ), ])

if name == 'main':
    application.listen( 8890 )
    print( 'Listening port : 8890 ...' )

    tornado.ioloop.IOLoop.instance().start()  
    print( 'Tornado Instance started ...' )

you can use server address request message.

Maybe my English is so bad, I can't describe it clearly. i am sorry @vkosuri @gunthercox

@Air-boy I apologies, I have modified your post to understand more, From your question i understood like this, correct me if i am wrong.

The RepetitiveResponseFilter isn't working as expected, then you have written your own filters, is this correct?

You are suggesting here, If you use RepetitiveResponseFilter the response should be corresponding statement only in your corpus file, even if you have tried n number times that should not change, this is correct?

If you feel it is a bug, please submit a PR

yes ,you are right! language is a big obstacles

@vkosuri @gunthercox i am so sorry ,i hava solve this problem. i am very stupid

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gunthercox picture gunthercox  ·  3Comments

vkosuri picture vkosuri  ·  4Comments

yuvalBor picture yuvalBor  ·  3Comments

atulanandnitt picture atulanandnitt  ·  3Comments

decode007 picture decode007  ·  4Comments