Sunday, May 22Digital Marketing Journals

bert

QnA Chatbot using sentence simi. Introduction | by AI Brewery
5-min-read, ai bot, ai chat, ai chatbot, bert, best chatbot, chatbot, chatbot ai, chatbot app, chatbot online, chatbot website, conversation with ai, creating chatbots, data-science, machine-learning, nlp, robot chat

QnA Chatbot using sentence simi. Introduction | by AI Brewery

When the user enters the query:1. Calculate the sentence vector of the query2. Identify the most matching sentence from the knowledge base using cosine similaritydef calculate_similarity(query):mean_pooled = get_embedding([query]) question = []similarity = []intent = [] for rec in collection.find():question.append(rec[‘Text’])intent.append(rec[‘Intent’])cos_sim = cosine_similarity([mean_pooled[0]],[np.fromiter(rec[‘Embedding’], dtype=np.float32)]) similarity.append(cos_sim) index = np.argmax(similarity)recognized_intent = intent[index]return recognized_intentIntents JSON fileHere we set up an intents JSON file that defines the intentions of the chatbot user.For example:A user may wish to know the name of our chatbot; therefore, we have created an intent called name.A user may wish to...