文本处理—LSA、 LDA

本文介绍了几种流行的主题模型算法,包括Tf-Idf、LSA(Latent Semantic Indexing)、PLSA(Probabilistic Latent Semantic Analysis)和LDA(Latent Dirichlet Allocation)。LSA利用SVD分解文档矩阵,而PLSA和LDA则基于概率模型。LDA被视为PLSA的贝叶斯版本,适用于发现文本数据中的主题结构。此外,还讨论了如何计算文档之间的相似度和主题模型的并行化方法。
摘要由CSDN通过智能技术生成

几个流行的VSM算法:

Term Frequency * Inverse Document Frequency, Tf-Idf

from gensim import corpora, models, similarities

dictionary = corpora.Dictionary(texts)
corpus = [dictionary.doc2bow(text) for text in texts]
tfidf = models.TfidfModel(corpus)
corpus_tfidf = tfidf[corpus]

Latent Semantic Indexing, LSI (or sometimes LSA)

LSA是SVD在文本数据上的变体。

Those days we know that most current LSI models are not based on mere local weights, but on models that incorporate local, global and document normalization weights. Others incorporate entropy weights and link weights. We also know that modern models ignore stop words and terms that occur once in document. Term stemming and sorting in alphabetical order is optional.

lsi = models.LsiModel(corpus_tfidf, id2word=dictionary, num_topics=200)
corpus_lsi = lsi[corpus_tfidf]

举例:用LSI来为docments和query排序:

  • step 1. 计算文档向量矩阵A和查询矩阵q
  • step 2. 对矩阵A进行SVD分解
  • step 3. 用秩为N的矩阵来近似表示A,文档向量可以用V来表示。
  • Step 4. 同样的对查询q进行表示: q=qTUkS1k q = q T U k S k − 1
  • Step 5. 计算query-document的余弦相似度
doc = "Human computer interaction"
vec_bow = dictionary.doc2bow(doc.lower().split())
vec_lsi = lsi[vec_bow] # convert the query to LSI space

index = similarities.MatrixSimilarity(lsi[corpus]) # transform corpus to LSI space and index it

sims = index[vec_lsi] # perform a similarity query against the corpus
print(list(enumerate(sims))) # print (document_number, document_similarity) 2-tuples

sims = sorted(enumerate(sims), key=lambda item: -item[1])
print(sims) # print sorted (document number, similarity score) 2-tuples

Probabilistic Latent Semantic Analysis, PLSA

Hoffman 于 1999 年提出的PLSA,Hoffman 认为一篇文档(Document) 可以由多个主题(Topic) 混合而成, 而每个Topic 都是词汇上的概率分布,文章中的每个词都是由一个固定的 Topic 生成的。

文档和文档之间是独立可交换的,同一个文档内的词也是独立可交换的,这是一个 bag-of-words 模型。 存在K个topic-word的分布,我们可以记为 φ1,,φK φ 1 , ⋯ , φ K 对于包含M篇文档的语料 C=(d1,d2,,dM) C = ( d 1 , d 2 , ⋯ , d M ) 中的每篇文档 dm d m ,都会有一个特定的doc-topic分布 θm θ m 。于是在 PLSA 这个模型中,第m篇文档 dm 中的每个词的生成概率为

p(w|dm)=z=1Kp(w|z)p(z|dm)=z=1Kφzwθmz p ( w | d m ) = ∑ z = 1 K p ( w | z
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值