Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 利用潜在符号分析进行聚类_Python_Nlp_Cluster Analysis_Lsa - Fatal编程技术网

Python 利用潜在符号分析进行聚类

Python 利用潜在符号分析进行聚类,python,nlp,cluster-analysis,lsa,Python,Nlp,Cluster Analysis,Lsa,假设我有一个文档库,并在其上运行LSA算法。如何使用应用SVD后得到的最终矩阵对文档语料库中出现的所有单词进行语义聚类?维基百科说LSA可以用来发现术语之间的关系。Python中是否有任何库可以帮助我完成基于LSA对单词进行语义聚类的任务?尝试gensim(),只需按照以下说明安装即可: 下面是一个代码示例: from gensim import corpora, models, similarities documents = ["Human machine interface for la

假设我有一个文档库,并在其上运行LSA算法。如何使用应用SVD后得到的最终矩阵对文档语料库中出现的所有单词进行语义聚类?维基百科说LSA可以用来发现术语之间的关系。Python中是否有任何库可以帮助我完成基于LSA对单词进行语义聚类的任务?

尝试
gensim
(),只需按照以下说明安装即可:

下面是一个代码示例:

from gensim import corpora, models, similarities

documents = ["Human machine interface for lab abc computer applications",
             "A survey of user opinion of computer system response time",
             "The EPS user interface management system",
             "System and human system engineering testing of EPS",
             "Relation of user perceived response time to error measurement",
             "The generation of random binary unordered trees",
             "The intersection graph of paths in trees",
             "Graph minors IV Widths of trees and well quasi ordering",
             "Graph minors A survey"]

# 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]

# remove words that appear only once
all_tokens = sum(texts, [])
tokens_once = set(word for word in set(all_tokens) if all_tokens.count(word) == 1)

texts = [[word for word in text if word not in tokens_once] for text in texts]

dictionary = corpora.Dictionary(texts)
corp = [dictionary.doc2bow(text) for text in texts]

# extract 400 LSI topics; use the default one-pass algorithm
lsi = models.lsimodel.LsiModel(corpus=corp, id2word=dictionary, num_topics=400)

# print the most contributing words (both positively and negatively) for each of the first ten topics
lsi.print_topics(10)