Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Spark LDA instance

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Spark LDA instance

First, prepare data

The data format is: documents: RDD [(Long, Vector)], where: Long is the word vector after the article is segmented by ID,Vector.

It can be converted to RDD [(Long, Vector)] through word segmentation and data format conversion.

Second, establish a model

Import org.apache.spark.mllib.clustering._val ldaOptimizer = new OnlineLDAOptimizer (). SetOptimizeDocConcentration (true) val lda = new LDA () lda.setK (params.k) .setMaxIterations (params.maxIterations). SetDocConcentration (params.docConcentration) .setTopicConcentration (params.topicConcentration) .setOptimizer (ldaOptimizer) .setCheckpointInterval (10) .setSeed (1234) val modelLDA: LDAModel = lda.run (corpus) modelLDA.save (sc.sparkContext, params.modelPath)

Third, model parameters

Case class NewsParams (k: Int = 100, maxIterations: Int = 100, docConcentration: Double =-1, topicConcentration: Double =-1, stopWordFile: String = "zh_stopwords.txt", modelPath: String = "LDAModel.14.100", ldaJsonPath:String = "ldaModel.14.200.json", vocabPath: String = "vocab_info")

IV. Result output

TopicsMatrix and topics (word,topic)) output. Lda on mllib is not distributed. Currently, only topic information is stored, not doc information. If you can only use lda in ml or use the following code to get it.

Val ldaModel = lda.run (documents) val distLDAModel = ldaModel.asInstanceOf [DistributedLDAModel] distLDAModel.topicDistributions

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report