【问题标题】:Clustering Using Latent Symantic Analysis使用潜在语义分析进行聚类
【发布时间】:2013-04-19 10:21:51
【问题描述】:

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

【问题讨论】:

    标签: python nlp cluster-analysis lsa


    【解决方案1】:

    尝试gensim (http://radimrehurek.com/gensim/index.html),只需按照以下说明安装即可:http://radimrehurek.com/gensim/install.html

    然后这里是代码示例:

    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)
    

    【讨论】:

      猜你喜欢
      • 2013-09-30
      • 2016-10-15
      • 2016-01-25
      • 2019-02-11
      • 2011-10-26
      • 1970-01-01
      • 1970-01-01
      • 2011-09-23
      • 2014-10-08
      相关资源
      最近更新 更多