【发布时间】:2019-11-29 03:22:16
【问题描述】:
每次执行此函数时都会引发 UserWarning。这里 user_input 是单词列表,article_sentences 是单词列表。
我已经尝试预先从列表中删除所有停用词,但这并没有改变任何东西。
def generate_response(user_input):
sidekick_response = ''
article_sentences.append(user_input)
word_vectorizer = TfidfVectorizer(tokenizer=get_processed_text, stop_words='english')
all_word_vectors = word_vectorizer.fit_transform(article_sentences) # this is the problematic line
similar_vector_values = cosine_similarity(all_word_vectors[-1], all_word_vectors)
similar_sentence_number = similar_vector_values.argsort()[0][-2]
这是我在这里找到的一个简单聊天机器人功能的一部分:https://stackabuse.com/python-for-nlp-creating-a-rule-based-chatbot/
它应该返回一个排序的句子列表,按照它们与 user_input 的匹配程度排序,它会这样做,但它也会抛出这个UserWarning: Your stop_words may be inconsistent with your preprocessing. Tokenizing the stop words generated tokens ['ha', 'le', 'u', 'wa'] not in stop_words。
【问题讨论】:
-
这本质上是 stackoverflow.com/questions/57340142/… 的副本,问题更容易回答。
标签: python scikit-learn nlp