微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python计数向量化空词汇

如何解决python计数向量化空词汇

我是 nlp 的新手,我一直在尝试使用 ngram 向量化。但是,我收到错误ValueError: empty vocabulary; perhaps the documents only contain stop words

以下代码如下

for index,row in df_valid.iterrows():
  txt1=(txt1)
  txt1 = df_valid['profile'][index]
  txt1 = str(txt1)
  print(txt1)
  txt1=[txt1]

  vectorizer = CountVectorizer(token_pattern = r"(?u)\b\w+\b",stop_words=None,ngram_range=(2,2),analyzer='word')

  X1 = vectorizer.fit_transform(txt1) 
  print("\n\nFeatures : \n",features)
  print("\n\nX1 : \n",X1.toarray())

我尝试添加停止,但我也没有工作。请帮忙。提前致谢

解决方法

首先,尝试在min_df=1内设置参数CountVectorizer()

其次,尝试用空格分隔文本,因为它是迭代列表中的单个。 :)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。