Exemplo n.º 1
0
 def find_intent_match(self, responses, user_message):
   bow_user_message=Counter(preprocess(user_message))
   processed_responses=[Counter(preprocess(response)) for response in responses]
   similarity_list=[compare_overlap(response, bow_user_message) for response in processed_responses]
   print(similarity_list)
   response_index=similarity_list.index(max(similarity_list))
   return responses[response_index]
Exemplo n.º 2
0
 def find_intent_match(self, questions, user_message):
     bow_user_message = Counter(preprocess(user_message))
     processed_questions = [
         Counter(preprocess(question)) for question in questions
     ]
     # define similarity_list here:
     similarity_list = [
         compare_overlap(bow_user_message, question)
         for question in processed_questions
     ]
     # define response_index here:
     response_index = similarity_list.index(max(similarity_list))
     return faq[questions[response_index]]
Exemplo n.º 3
0
 def find_intent_match(self, responses, user_message):
     # create a Bag-of-Words model
     bow_user_message = Counter(preprocess(user_message))
     processed_responses = [
         Counter(preprocess(response)) for response in responses
     ]
     # select the response that best matches the intent of the user message
     similarity_list = [
         compare_overlap(item, bow_user_message)
         for item in processed_responses
     ]
     # select the index of the highest similarity score
     response_index = similarity_list.index(max(similarity_list))
     return responses[response_index]
    def find_entities(self, user_message):
        tagged_user_message = pos_tag(preprocess(user_message))
        message_nouns = extract_nouns(tagged_user_message)

        tokens = word2vec(" ".join(message_nouns))
        category = word2vec(blank_spot)
        word2vec_result = compute_similarity(tokens, category)
        word2vec_result.sort(key=lambda x: x[2])
        return word2vec_result[-1][0]
Exemplo n.º 5
0
 def find_entities(self, user_message):
     tagged_user_message = pos_tag(preprocess(user_message))
     message_nouns = extract_nouns(tagged_user_message)
     # fit a word2vec model on our candidate entities
     tokens = word2vec(" ".join(message_nouns))
     category = word2vec(blank_spot)
     word2vec_result = compute_similarity(tokens, category)
     # select the entity with the highest similarity score
     word2vec_result.sort(key=lambda x: x[2])
     if len(word2vec_result) > 0:
         return word2vec_result[-1][0]
     else:
         return blank_spot
from user_functions import preprocess, compare_overlap, pos_tag, extract_nouns, word2vec, compute_similarity
from collections import Counter

user_message = "Good morning... will it rain in Chicago later this week?"

blank_spot = "illinois city"
response_a = "The average temperature this weekend in {} with be 88 degrees. Bring your sunglasses!"
response_b = "Forget about your umbrella; there is no rain forecasted in {} this weekend."
response_c = "This weekend, a warm front from the southeast will keep skies near {} clear."
responses = [response_a, response_b, response_c]

#preprocess documents
bow_user_message = Counter(preprocess(user_message))
processed_responses = [Counter(preprocess(response)) for response in responses]

#determine intent with BoW
similarity_list = [
    compare_overlap(doc, bow_user_message) for doc in processed_responses
]

#extract entities with word2vec
tagged_user_message = pos_tag(preprocess(user_message))
message_nouns = extract_nouns(tagged_user_message)

#execute word2vec below
tokens = word2vec(" ".join(message_nouns))
category = word2vec(blank_spot)
word2vec_result = compute_similarity(tokens, category)

#select final response below