-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-5565] [ML] LDA wrapper for Pipelines API #9513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c053d0a
partly done adding LDA
jkbradley 23d40c4
done adding LDA. need to add tests
jkbradley 583e173
fix indentation
jkbradley ffb68c5
Added test suite for spark.ml LDA
jkbradley 9589e01
scala style fix
jkbradley 3acc9e0
updates per code review, mostly minor
jkbradley 631d407
fixed unit tests
jkbradley 16a061c
removed optimizers and changed optimizer param to be a String
jkbradley be67704
changed concentration Params not to use -1 as special value, and to b…
jkbradley a55de6d
tiny fix
jkbradley 8eaa596
Renamed kappa, tau0 to learningDecay, learningOffset
jkbradley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixed unit tests
- Loading branch information
commit 631d40759e88c84dfffe4805a7834c353caa341b
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,6 +171,14 @@ private[clustering] trait LDAParams extends Params with HasFeaturesCol with HasM | |
| SchemaUtils.checkColumnType(schema, $(featuresCol), new VectorUDT) | ||
| SchemaUtils.appendColumn(schema, $(topicDistributionCol), new VectorUDT) | ||
| } | ||
|
|
||
| override def validateParams(): Unit = { | ||
| if (getDocConcentration.length != 1) { | ||
| require(getDocConcentration.length == getK, s"LDA docConcentration was of length" + | ||
| s" ${getDocConcentration.length}, but k = $getK. docConcentration must be either" + | ||
| s" length 1 (scalar) or an array of length k.") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: either a length 1 vector or a vector of length k
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, I forgot to make this update. I'll fix it now. |
||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -195,14 +203,6 @@ class LDAModel private[ml] ( | |
| @Since("1.6.0") @transient protected val sqlContext: SQLContext) | ||
| extends Model[LDAModel] with LDAParams with Logging { | ||
|
|
||
| override def validateParams(): Unit = { | ||
| if (getDocConcentration.length != 1) { | ||
| require(getDocConcentration.length == getK, s"LDA docConcentration was of length" + | ||
| s" ${getDocConcentration.length}, but k = $getK. docConcentration must be either" + | ||
| s" length 1 (scalar) or an array of length k.") | ||
| } | ||
| } | ||
|
|
||
| /** Returns underlying spark.mllib model */ | ||
| @Since("1.6.0") | ||
| protected def getModel: OldLDAModel = oldLocalModel match { | ||
|
|
@@ -328,7 +328,7 @@ class LDAModel private[ml] ( | |
| def describeTopics(maxTermsPerTopic: Int): DataFrame = { | ||
| val topics = getModel.describeTopics(maxTermsPerTopic).zipWithIndex.map { | ||
| case ((termIndices, termWeights), topic) => | ||
| (topic, termIndices, termWeights) | ||
| (topic, termIndices.toSeq, termWeights.toSeq) | ||
| } | ||
| sqlContext.createDataFrame(topics).toDF("topic", "termIndices", "termWeights") | ||
| } | ||
|
|
@@ -463,8 +463,8 @@ class LDA @Since("1.6.0") ( | |
| @Since("1.6.0") | ||
| def this() = this(Identifiable.randomUID("lda")) | ||
|
|
||
| setDefault(k -> 10, docConcentration -> Array(-1.0), topicConcentration -> -1.0, | ||
| optimizer -> new OnlineLDAOptimizer) | ||
| setDefault(maxIter -> 20, k -> 10, docConcentration -> Array(-1.0), topicConcentration -> -1.0, | ||
| optimizer -> new OnlineLDAOptimizer, checkpointInterval -> 10) | ||
|
|
||
| /** | ||
| * The features for LDA should be a [[Vector]] representing the word counts in a document. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we prominently document that features have to be
Vectors with integer-quantized Double values? A novice user could easily assume that LDA takes text as input. Also, I'm not terribly keen on continuing to useVectors and implicitly requiring integer tokens for words:Array[Int]using catalyst'sArrayTypewould be nicer IMO. We should fix this decision before merging since it will affect the public API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it should be documented, but we can later support Array of Int or even Strings without breaking the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should provide the
VectorAPI at all if the vector can only contain integer arguments since we really just meanArray[Int]. Making the change now would allow us to drop this legacy API altogether. If we need to merge this quickly, can we make the public API supportArray[Int]and do a conversion to vector internally?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bigger issue might be that the relevant feature transformers (CountVectorizer) produce Vectors, so we need to support Vector. It also might be reasonable to have weighted docs (someday), which would change the Int values to Doubles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think I completely understand how weighted docs makes these Doubles, but good point about
CountVectorizer(although I have feelings about that one as well, but it's too late to change that >.<). Let's leave this asVectorthen