-
Notifications
You must be signed in to change notification settings - Fork 394
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
Adjust bin values for text features in RFF #99
Changes from 2 commits
da5ba89
1d90e8f
3b6c45f
eea1cf2
b958887
a54131b
dae829d
d6ad74f
d9dee94
1bb28c6
441ab06
546fcfc
13cb288
c47e9bc
e8d616b
e133bb4
20a9c40
e39dad6
1c6d359
5e2857c
a2ffd3a
3c35a13
2f4f77a
6187e55
7ff99fe
bdc0608
dfc1a40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,7 @@ | |
|
||
package com.salesforce.op.filters | ||
|
||
import com.salesforce.op.features.TransientFeature | ||
import com.salesforce.op.stages.impl.feature.{Inclusion, NumericBucketizer} | ||
import com.salesforce.op.stages.impl.feature.{HashAlgorithm, Inclusion, NumericBucketizer} | ||
import com.twitter.algebird.Semigroup | ||
import com.twitter.algebird.Monoid._ | ||
import com.twitter.algebird.Operators._ | ||
|
@@ -142,6 +141,7 @@ case class FeatureDistribution | |
private[op] object FeatureDistribution { | ||
|
||
val MaxBins = 100000 | ||
val AvgBinValue = 5000 | ||
|
||
implicit val semigroup: Semigroup[FeatureDistribution] = new Semigroup[FeatureDistribution] { | ||
override def plus(l: FeatureDistribution, r: FeatureDistribution) = l.reduce(r) | ||
|
@@ -154,18 +154,16 @@ private[op] object FeatureDistribution { | |
* @param summary feature summary | ||
* @param value optional processed sequence | ||
* @param bins number of histogram bins | ||
* @param hasher hashing method to use for text and categorical features | ||
* @return feature distribution given the provided information | ||
*/ | ||
def apply( | ||
featureKey: FeatureKey, | ||
summary: Summary, | ||
value: Option[ProcessedSeq], | ||
bins: Int, | ||
hasher: HashingTF | ||
bins: Int | ||
): FeatureDistribution = { | ||
val (nullCount, (summaryInfo, distribution)): (Int, (Array[Double], Array[Double])) = | ||
value.map(seq => 0 -> histValues(seq, summary, bins, hasher)) | ||
value.map(seq => 0 -> histValues(seq, summary, bins)) | ||
.getOrElse(1 -> (Array(summary.min, summary.max) -> Array.fill(bins)(0.0))) | ||
|
||
FeatureDistribution( | ||
|
@@ -182,18 +180,25 @@ private[op] object FeatureDistribution { | |
* @param values values to bin | ||
* @param sum summary info for feature (max and min) | ||
* @param bins number of bins to produce | ||
* @param hasher hasing function to use for text | ||
* @return the bin information and the binned counts | ||
*/ | ||
// TODO avoid wrapping and unwrapping?? | ||
private def histValues( | ||
values: ProcessedSeq, | ||
sum: Summary, | ||
bins: Int, | ||
hasher: HashingTF | ||
bins: Int | ||
): (Array[Double], Array[Double]) = { | ||
values match { | ||
case Left(seq) => Array(sum.min, sum.max) -> hasher.transform(seq).toArray // TODO use summary info to pick hashes | ||
case Left(seq) => { | ||
val minBins = bins | ||
val maxBins = MaxBins | ||
val numBins = math.min(math.max(bins, sum.max/AvgBinValue), maxBins).toInt | ||
|
||
val hasher: HashingTF = new HashingTF(numFeatures = numBins) | ||
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. do we have to create hasher every time or perhaps we can create it once? 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. the hashing dimension can be different for different features, the minimum number would be 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. let see if we can reuse the hashing function without creating 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. and I think we can. See |
||
.setBinary(false) | ||
.setHashAlgorithm(HashAlgorithm.MurMur3.toString.toLowerCase) | ||
Array(sum.min, sum.max) -> hasher.transform(seq).toArray | ||
} | ||
case Right(seq) => // TODO use kernel fit instead of histogram | ||
if (sum == Summary.empty) { | ||
Array(sum.min, sum.max) -> seq.toArray // the seq will always be empty in this case | ||
|
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.
sum.max / AvgBinValue
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.
instead of
.toInt
perhaps specify the explicit rounding instead.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.
fixed! thanks!!