Search code examples
pythonchatterbot

Chatter bot returns wrong response when question string reversed


yaml file:

- - Invalid Password
  - contact [email protected]

I am using python Chatterbot library, if I ask Invalid Password it returns the response contact [email protected], but if I ask Password Invalid it gives me the default response which I have set while creating the chat bot instance.

bot = ChatBot(
    'Norman',
    storage_adapter='chatterbot.storage.SQLStorageAdapter',
    input_adapter='chatterbot.input.TerminalAdapter',
    output_adapter='chatterbot.output.TerminalAdapter',
    logic_adapters=[
        {
            'import_path': 'my_logic_adapter.MyLogicAdapter',
            "statement_comparison_function": "chatterbot.comparisons.JaccardSimilarity",
            "response_selection_method": "chatterbot.response_selection.get_random_response",
            'threshold': 0.65,
            'default_response': 'I am sorry, but I do not understand.'
        }
    ],
    filters=["chatterbot.filters.RepetitiveResponseFilter"],
    preprocessors=[
        'chatterbot.preprocessors.clean_whitespace',
        'chatterbot.preprocessors.unescape_html',
        'chatterbot.preprocessors.convert_to_ascii'
    ],
    database='./database.sqlite3',
    trainer='chatterbot.trainers.ListTrainer'
)
bot.set_trainer(ListTrainer)

Solution

  • The thing is Chatterbot stores unstructured and untrained data into SQLite DB. If you enter a reverse string and the response is not stored in the YAML file, it will not be able to understand, hence it will fetch some random response. You need to train such data (increase the frequency). Also as per my understanding, Jaccard Similarity won't help in this case.

    if you only insert password and no other password word stored in YAML then I think it will give the correct reply. Chatterbot itself created with NLP and but you need to change the code of Logic adapter as per your requirement.