daniel-kukiela / nmt-chatbot

NMT Chatbot
GNU General Public License v3.0
387 stars 214 forks source link

Chatbot only produces 1 answer despite beam width being 20 #169

Open eniteCZ opened 3 years ago

eniteCZ commented 3 years ago

Hello I have tried adding new scoring functions but none have changed the chatbot's responses. After I checked why it is because the model only produces 1 response and therefore the scoring is pointless. I checked the settings and the beam width is at 20 so it should choose from a list of 20 as far as I know. However when I use the deployed version and integrate it and tell it to list all the answers to a user input it only produces 1 answer.

Thank you for helping :)

Nathan-Chell commented 3 years ago

Inference.py returns the highest scoring response. If you look in inference.py you will see a line at the bottom that mentions max (Not at my pc rn cannot confirm line number), that is returning the highest score. If you want to print all responses you'll have to change this section of code.

Hope this helps.

dennorak commented 3 years ago

Does anyone know what line needs to be changed to fix this?

Nathan-Chell commented 3 years ago

On line 308, in inference.py:

for i, _ in enumerate(answers['scores']): print("{}- {}{} [{}] {}{}{}".format(colorama.Fore.GREEN if answers['scores'][i] == max(answers['scores']) and answers['scores'][i] >= score_settings['bad_response_threshold'] else colorama.Fore.YELLOW if answers['scores'][i] >= score_settings['bad_response_threshold'] else colorama.Fore.RED, answers['answers'][i], colorama.Fore.RESET, answers['scores'][i], colorama.Fore.BLUE, answers['score_modifiers'][i] if score_settings['show_score_modifiers'] else '', colorama.Fore.RESET))

If you just want all the answers produced, try changing this to print(answers['answers'])

That should print out all the answers that inference returns

aditya543 commented 2 years ago

Hey everyone! I finally solved this issue after doing a lot of R&D on the nmt package. The reason why your chatbot produces only one response is due to the hyper-parameter: 'infer-mode' set to 'greedy'. Go to setup/settings.py and in the hparams dict add a new key: 'infer-mode' and set it to 'beam-search'. This will solve your issue, thanks! Check out the image below.

Screen Shot 2022-06-19 at 3 09 08 PM