Skip to content
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

the prediction is not same as predicted using official c++ #53

Open
ericxsun opened this issue Mar 17, 2019 · 2 comments
Open

the prediction is not same as predicted using official c++ #53

ericxsun opened this issue Mar 17, 2019 · 2 comments

Comments

@ericxsun
Copy link

ericxsun commented Mar 17, 2019

I just tested this repo and the official one to predict a number of samples(with the same model trained by official code, in format of ftz).

c++

fasttext predict-prob test-example.txt

java(this) - api call

(equal represents the label is same, discard the probability)
all samples: 21513
equal: 19236
not-equal: 2219
null(in this repo): 58

java-cmd(this)

java -jar jfasttext-0.4-jar-with-dependencies.jar predict-prob test-example.txt
all samples: 21513
equal: 18825
not-equal: 2688

so, what's wrong?

Another thing: the prediction of java-cmd is unstable , changing every time.

@ericxsun
Copy link
Author

Found this one: https://github.com/linkfluence/fastText4j, the prediction is quite same.

@kun368
Copy link

kun368 commented Feb 25, 2022

Based on what @carschno mentioned in #49, I used this to get the right results:

public Map<String, Double> predictTopLabel(String text, int k) {
    Map<String, Double> scoreMap = new LinkedHashMap<>();
    text = StringUtils.trimToEmpty(text) + "\n";
    final List<JFastText.ProbLabel> pl = model.predictProba(text, k);
    for (JFastText.ProbLabel i : CollectionUtils.emptyIfNull(pl)) {
        final double prob = Math.exp(i.logProb);
        final double score = Math.round(prob * 100000000) / 100000000;
        scoreMap.put(i.label, score);
    }
    return scoreMap;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants