Skip to content

Commit

Permalink
[fasttext] keep __label__ prefix (#1196)
Browse files Browse the repository at this point in the history
Change-Id: I06ea826ea37d367ea75ca257bd640583b1660fc2
  • Loading branch information
frankfliu authored Aug 30, 2021
1 parent e278a05 commit 887bc6f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ public Classifications predictProba(String text, int topK) {
List<String> classes = new ArrayList<>(size);
List<Double> probabilities = new ArrayList<>(size);
for (int i = 0; i < size; ++i) {
String label = labels[i];
if (label.startsWith("__label__")) {
label = label.substring(9);
}
classes.add(label);
classes.add(labels[i]); // NOPMD
probabilities.add((double) probs[i]);
}
return new Classifications(classes, probabilities);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void testTextClassification()
String input = "Which baking dish is best to bake a banana bread ?";
FtModel ftModel = (FtModel) model.getWrappedModel();
Classifications result = ftModel.classify(input, 8);
Assert.assertEquals(result.item(0).getClassName(), "bread");
Assert.assertEquals(result.item(0).getClassName(), "__label__bread");
}
}

Expand Down

0 comments on commit 887bc6f

Please sign in to comment.