Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoiding repetitions #148

Closed
SamuelRiversMoore opened this issue Apr 13, 2016 · 4 comments
Closed

Avoiding repetitions #148

SamuelRiversMoore opened this issue Apr 13, 2016 · 4 comments

Comments

@SamuelRiversMoore
Copy link

Hi,
I'm wondering, is there is any simple ways to prevent the bot from repeating itself too much?

Maybe : keeping a record of the two or three previous exchanges and returning an output that could be a bit less appropriate if the most appropriate has been returned too recently… What do you think?

Amazing work, btw! 👍

@gunthercox
Copy link
Owner

I agree with this. There is currently a recent_statements variable which I added so that this could eventually be accomplished. Currently the variable holds a list of the bot's responses for the current session. At some point I would love to make the change so that it avoids repeating the same words frequently.

@t56k
Copy link

t56k commented Apr 18, 2016

+1

@SamuelRiversMoore
Copy link
Author

Ok, maybe it's not the cleanest way to do but I have something. At least it's a start.
I modified two functions : process() in base_match.py and get() in closest_match.py

For get() :

    def get(self, input_statement, statement_list=None):
        """
        Takes a statement string and a list of statement strings.
        Returns the closest matching statement from the list.
        """
        statement_list = self.get_available_statements(statement_list) # entries in json db

        if not statement_list:
            if self.has_storage_context:
                # Use a randomly picked statement
                return [(0, self.context.storage.get_random())]
            else:
                raise EmptyDatasetException

        # Get the text of each statement
        text_of_all_statements = []
        for statement in statement_list:
            text_of_all_statements.append(statement.text)

        # Make a list of matches ordered by confidence
        matches = process.extract(
            input_statement.text,
            text_of_all_statements
        )
        results = [( confidence/100.0, next((s for s in statement_list if s.text == match), None )) for match, confidence in matches]
        return results

For process() :

 def process(self, input_statement):

        recent_statements = self.context.recent_statements[-10:] # get the ten last recent statements

        results = self.get(input_statement)

        for e in results :
            confidence = e[0]
            closest_match = e[1]

            # Save any updates made to the statement by the logic adapter
            self.context.storage.update(closest_match)

            # Get all statements that are in response to the closest match
            response_list = self.context.storage.filter(
                in_response_to__contains=closest_match.text
            )

            if response_list:
                response = self.break_tie(response_list, self.tie_breaking_method)
            else:
                response = self.context.storage.get_random()

            if response not in recent_statements:
                break # break the loop if the response has not been said in the ten last exchanges

        return confidence, response

@gunthercox
Copy link
Owner

A new feature called filters was recently introduced to ChatterBot. A filter called the RepetitiveResponseFilter has been added which eliminates recent responses from the set of possible replies that the chat bot can return. Currently, not all storage adapters support filtering but in the future they will.

See documentation http://chatterbot.readthedocs.io/en/stable/filters/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants