我正在使用 Java language-detection库的方式如下:
Detector detector = DetectorFactory.create(); //profiles are in the default location
detector.append("What language is this text?");
List<Language> languages = detector.getProbabilities();
Language mostProbable = languages.get(0);
System.out.println(mostProbable.lang + " - " + mostProbable.prob);
在输入完全相同的情况下,prob
值在不同的执行过程中略有不同。这是“正常”吗?这取决于什么?
最佳答案
如果库使用的算法/方法不确定,则每次执行的值可能会有所不同。
例如,某些算法需要给予初始种子才能开始。在很多情况下,这个种子是(伪)随机选择的。这会影响最终输出。
编辑:看起来该库正在使用朴素贝叶斯分类器(可能是或)。
关于Java 语言检测在给定相同输入的情况下返回不同的概率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19717535/