Best Match Behaviour
Hi,
I'm getting some unusual results with the BestMatch logic adaptor. For example, I trained my bot with the following two questions:
"Who wrote The Odyssey?" "Who wrote The Lord of the Rings?"
If I ask the bot "Who wrote The Lord of the Rings?", I get a confidence of 1 and the correct answer. If I drop the first "the" from the question, "Who wrote Lord of the Rings?" I get the answer to "Who wrote The Odyssey?". Looking at the logging I can see that the confidence with of "Who wrote Lord of the Rings?" compared to "Who wrote The Odyssey?" is 0.45 and "Who wrote The Lord of the Rings?" is 0.87.
Shouldn't the BestMatch be returning the answer with the highest confidence?
Looking at the best_match.py script, I think I can locate where this is happening:
# Use the input statement as the closest match if no other results are found
closest_match = next(search_results, input_statement)
# Search for the closest match to the input statement
for result in search_results:
# Stop searching if a match that is close enough is found
if result.confidence >= self.maximum_similarity_threshold:
closest_match = result
break
The maximum_similarity_threshold is set to 0.95 so anything with a confidence above that gets put as the answer. But it looks to me as if the script is keeping the whatever it found first (in my case "Who wrote The Odyssey?") as the closest_match variable, and not updating it if it finds something with a higher confidence.
Is there some other setting that I need to apply to get this to work to find the closest match if the maximum_similarity_threshold isn't reached? I found if I added the following lines of code as seen below, the script worked as intended:
# Use the input statement as the closest match if no other results are found
closest_match = next(search_results, input_statement)
# Search for the closest match to the input statement
for result in search_results:
#set closest_match to result if it has a higher confidence
if result.confidence > closest_match.confidence:
closest_match = result
# Stop searching if a match that is close enough is found
if result.confidence >= self.maximum_similarity_threshold:
closest_match = result
breakI'm using chatterbot version 1.0.5 on Python 3.7.
Thanks in advance for your help.
Source: gunthercox/ChatterBot