【问题标题】:how to fix stopwords preprocessing inconsistency?如何修复停用词预处理不一致?
【发布时间】: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

【问题讨论】:

标签: python scikit-learn nlp


【解决方案1】:

已在here 讨论过此用户警告问题。正如@jnothman 所说:

...确保您预处理停止列表以确保它像您的标记一样被规范化,并将规范化单词列表作为 stop_words 传递给矢量化器。

【讨论】:

    【解决方案2】:

    预处理似乎有问题。

    根据我的个人经验,预处理中的词干提取步骤会导致某些词干,例如将 ing 与单词 financing 分开以保留词干 financ。最终,这些会继续并导致与 TFIDF_Vectorizer -> stop_words 列表不一致。

    您可以查看此帖子以获取更多信息 - Python stemmer issue: wrong stem

    您也可以尝试避免词干提取过程而只进行标记化。这至少可以解决不一致的错误。

    【讨论】:

      猜你喜欢
      • 2021-11-20
      • 1970-01-01
      • 1970-01-01
      • 2018-11-21
      • 2022-11-12
      • 2019-03-03
      • 2020-08-26
      • 2020-07-09
      • 2023-03-06
      相关资源
      最近更新 更多