October 2018
Intermediate to advanced
472 pages
10h 57m
English
We create a sorted dictionary of similarities for a query:
dict_sim= dict(enumerate(XX_sim_scores))sorted_dict_sim = sorted(dict_sim.items(), key=operator.itemgetter(1), reverse =True)
Finally, in the sorted dictionary, we check for the index of the most similar question, and the response with the value at that index in the answers column. If nothing is found, then we can return our default answer:
if sorted_dict_sim[0][1]==0: print("Sorry I have no answer, please try asking again in a nicer way :)")elif sorted_dic_sim[0][1]>0: print answer_list [sorted_dic_sim[0][0]]
Read now
Unlock full access