每次执行此函数时都会抛出一个UserWarning。在这里,用户输入是一个单词列表,而文章句子是一个单词列表
我已经试着事先把所有的停止词从列表中删除,但这并没有改变任何事情
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/
它应该返回一个排序的句子列表,按照它们与用户输入的匹配程度排序,它会这样做,但它也会抛出这个UserWarning: Your stop_words may be inconsistent with your preprocessing. Tokenizing the stop words generated tokens ['ha', 'le', 'u', 'wa'] not in stop_words
预处理似乎存在问题
根据我个人的经验,预处理中的词干处理步骤会导致某些词干,例如将ing与financing一词分开,以保持词干financ。最终,这些将继续并导致与TFIDF_矢量器不一致->;停止使用单词列表
你可以看到这篇文章来获取更多关于这个-Python stemmer issue: wrong stem
您还可以尝试避免词干生成过程,只进行标记化。这至少可以解决不一致性错误
已讨论了此用户警告问题here。正如@jnothman所说:
相关问题 更多 >
编程相关推荐