1

How could I select similar text instead of a random response if no response is found in Chatterbot? Been on this issue for hours, cannot find a solution...

My input is: What's up brotha Similar text found: I'm with you brotha (0.63 confidence) But it does not select it, instead Chatterbot selects a random response

import string
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
import chatterbot
from django.contrib.auth.models import User
from django.utils.crypto import get_random_string

from celery import shared_task

@shared_task
def search_for_reply(input_reply):
    # Create a new chat bot named Charlie
    print(input_reply)
    chatbot = ChatBot('Charlie',
                      read_only=True,
                      storage_adapter='chatterbot.storage.SQLStorageAdapter',
                      database_uri='sqlite:////home/knaitas/myproject/database.sqlite3',
                      logic_adapters=[
                      {
                      "import_path": "chatterbot.logic.BestMatch",
                      'threshold': 0.35,
                      "statement_comparison_function": "chatterbot.comparisons.SentimentComparison",
                      "response_selection_method": "chatterbot.response_selection.get_first_response"
                      }
                      ]
                      )
    response = chatbot.get_response(input_reply)

    return response

Logs:

[2019-12-24 11:43:14,914: WARNING/ForkPoolWorker-1] What's up brotha
[nltk_data] Downloading package stopwords to
[nltk_data]     /home/knaitas/nltk_data...
[nltk_data]   Package stopwords is already up-to-date!
[nltk_data] Downloading package averaged_perceptron_tagger to
[nltk_data]     /home/knaitas/nltk_data...
[nltk_data]   Package averaged_perceptron_tagger is already up-to-
[nltk_data]       date!
[2019-12-24 11:43:18,090: INFO/ForkPoolWorker-1] Beginning search for close text match
[2019-12-24 11:43:18,091: INFO/ForkPoolWorker-1] Processing search results
[2019-12-24 11:43:21,814: INFO/ForkPoolWorker-1] Similar text found: I'm with you brotha 0.63
[2019-12-24 11:43:21,817: INFO/ForkPoolWorker-1] Using "I'm with you brotha" as a close match to "What's up brotha" with a confidence of 0.63
[2019-12-24 11:43:24,753: INFO/ForkPoolWorker-1] No responses found. Generating alternate response list.
[2019-12-24 11:43:25,358: INFO/ForkPoolWorker-1] No known response to the input was found. Selecting a random response.
knaitas
  • 59
  • 3
  • 7
  • I think that threshold in chatterbot is the maximum_similarity_threshold, so it searches possible answers until this threshold. For example if you set it at 0.64 it will probably work. – Thanasis Saxanidis Dec 24 '19 at 12:07
  • Thanks for the answer, I changed threshold to 'maximum_similarity_threshold': 0.35, but still getting the same result, I think the problem is that there is no response available, so should be if no response, use similar, cannot find anything in the documentations :( – knaitas Dec 24 '19 at 12:08
  • You should set the threshold higher too. maximum_similarity_threshold means that It searches an answer with this threshold or lower. Yours is bigger, so you don't get the response even though it exists. – Thanasis Saxanidis Dec 24 '19 at 12:12
  • I see, I changed it to 0.64, still same results. I think it is happening because chatterbot is not registering similar text as a possible response. – knaitas Dec 24 '19 at 12:16
  • I don't get what you mean similar. Do you have a sample of your input_reply ? – Thanasis Saxanidis Dec 24 '19 at 12:26
  • You can see in the logs: "Similar text found" Using response as a close match. and then No responses found???? but chatterbot indicates that it found similar text. Input reply is: What's up brotha – knaitas Dec 24 '19 at 12:41
  • I have no idea how to fix this, but I found a work around. It appears that I did train the chatbot incorrectly and now after a few tests with new training it seems to work. Still sad that it is not able to select similar responses :( – knaitas Dec 24 '19 at 12:59

0 Answers0