Skip to content

Commit

Permalink
Now KBP KB thingy works. Kinda
Browse files Browse the repository at this point in the history
  • Loading branch information
Arun Tejasvi Chaganty authored and Stanford NLP committed Sep 17, 2015
1 parent f4597ee commit 4a18212
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions src/edu/stanford/nlp/classify/LinearClassifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,8 @@ public Counter<L> scoresOf(RVFDatum<L, F> example) {
*/
private Counter<L> scoresOfRVFDatum(RVFDatum<L, F> example) {
Counter<L> scores = new ClassicCounter<L>();
// Index the features in the datum
Counter<F> asCounter = example.asFeaturesCounter();
Counter<Integer> asIndexedCounter = new ClassicCounter<>(asCounter.size());
for (Map.Entry<F, Double> entry : asCounter.entrySet()) {
asIndexedCounter.setCount(featureIndex.indexOf(entry.getKey()), entry.getValue());
}
// Set the scores appropriately
for (L l : labels()) {
scores.setCount(l, scoreOfRVFDatum(asIndexedCounter, l));
scores.setCount(l, scoreOfRVFDatum(example, l));
}
//System.out.println("Scores are: " + scores + " (gold: " + example.label() + ")");
return scores;
Expand All @@ -235,20 +228,8 @@ private double scoreOfRVFDatum(RVFDatum<L, F> example, L label) {
int iLabel = labelIndex.indexOf(label);
double score = 0.0;
Counter<F> features = example.asFeaturesCounter();
for (Map.Entry<F, Double> entry : features.entrySet()) {
score += weight(entry.getKey(), iLabel) * entry.getValue();
}
return score + thresholds[iLabel];
}

/** Returns the score of the RVFDatum for the specified label.
* Ignores the true label of the RVFDatum.
*/
private double scoreOfRVFDatum(Counter<Integer> features, L label) {
int iLabel = labelIndex.indexOf(label);
double score = 0.0;
for (Map.Entry<Integer, Double> entry : features.entrySet()) {
score += weight(entry.getKey(), iLabel) * entry.getValue();
for (F f : features.keySet()) {
score += weight(f, iLabel) * features.getCount(f);
}
return score + thresholds[iLabel];
}
Expand Down

0 comments on commit 4a18212

Please sign in to comment.