我正在使用pyspark的LDAModel从语料库中获取主题.我的目标是找到与每个文档相关的主题.为此,我尝试根据Docs 设置topicDistributionCol.由于我是新手,我不确定本专栏的目的是什么.
from pyspark.ml.clustering import LDA
lda_model = LDA(k=10, optimizer="em").setTopicDistributionCol("topicDistributionCol")
// documents is valid dataset for this lda model
lda_model = lda_model.fit(documents)
transformed = lda_model.transform(documents)
topics = lda_model.describeTopics(maxTermsPerTopic=num_words_per_topic)
print("The topics described by their top-weighted terms:")
print topics.show(truncate=False)
Run Code Online (Sandbox Code Playgroud)
它列出了termIndices和termWeights的所有主题.
下面的代码会给我topicDistributionCol.这里每行都是针对每个文档的.
print transformed.select("topicDistributionCol").show(truncate=False)
Run Code Online (Sandbox Code Playgroud)
我想得到像这样的文档主题矩阵.有没有可能与pysparks LDA模型?
doc | topic
1 | [2,4]
2 | [3,4,6]
Run Code Online (Sandbox Code Playgroud)
注意:我之前使用gensims LDA模型使用以下代码完成了此操作.但我需要使用pysparks LDA模型.
texts = [[word for word in document.lower().split() if word not in stoplist] for document in documents]
dictionary = corpora.Dictionary(texts)
corpus = …
Run Code Online (Sandbox Code Playgroud) 我正在使用PostgreSQL数据库进行实时项目。其中,我有一张有 8 列的表。该表包含数百万行,因此为了从表中更快地进行搜索,我想删除该表中的旧条目并将其存储到另一个新表中。
为此,我知道一种方法:
但是时间太长,效率不高。
所以我想知道在 postgresql 数据库中执行此操作的最佳方法是什么?
Postgresql 版本:9.4.2.
大约行数:8000000
我想移动行:2000000