在 Python 中计算单词

编程入门 行业动态 更新时间:2024-10-27 13:26:46
本文介绍了在 Python 中计算单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 python 中有一个字符串列表.

I have a list of strings in python.

list = [ "Sentence1.Sentence2...", "Sentence1.Sentence2...",...]

我想删除停用词并计算所有不同字符串组合的每个词的出现次数.有什么简单的方法吗?

I want to remove stop words and count occurrence of each word of all different strings combined. Is there a simple way to do it?

我目前正在考虑使用 scikit 中的 CountVectorizer(),而不是对每个单词进行迭代并组合结果

I am currently thinking of using CountVectorizer() from scikit and than iterating for each word and combining the results

推荐答案

如果你不介意安装一个新的 python 库,我建议你使用 gensim.第一个教程完全符合您的要求:

If you don't mind installing a new python library, I suggest you use gensim. The first tutorial does exactly what you ask:

# remove common words and tokenize stoplist = set('for a of the and to in'.split()) texts = [[word for word in document.lower().split() if word not in stoplist] for document in documents]

然后您需要为您的文档语料库创建字典并创建词袋.

You will then need to create the dictionary for your corpus of document and create the bag-of-words.

dictionary = corpora.Dictionary(texts) dictionary.save('/tmp/deerwester.dict') # store the dictionary, for future print(dictionary)

您可以使用 tf-idf 和其他东西对结果进行加权,然后很容易地进行 LDA.

You can weight the result using tf-idf and stuff and do LDA quite easily after.

查看教程 1 此处

更多推荐

在 Python 中计算单词

本文发布于:2023-05-27 09:59:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/285810.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单词   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!