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

压缩cpp模型后,java加载模型预测出错 #42

Open
cgpeter96 opened this issue Nov 23, 2021 · 6 comments
Open

压缩cpp模型后,java加载模型预测出错 #42

cgpeter96 opened this issue Nov 23, 2021 · 6 comments

Comments

@cgpeter96
Copy link

cgpeter96 commented Nov 23, 2021

cpp命令行结果
image
java 预测结果
image

java的预测代码

FastText model = FastText.loadCppModel(new File("E:\\Downloads\\model.ftz"));
//        Lexer lexer =Mynlp.instance().bigramLexer();
        long start = System.currentTimeMillis();
        String [] querys = new String[]{"北京大学在哪里","白羊座","金牛座"};
        for(int i=0;i <querys.length;i++){
            List<String> strings = Arrays.asList(querys[i].split(""));
            List<ScoreLabelPair> predict = model.predict(strings,1,0);
            System.out.println(predict.toString());
        }

        long end = System.currentTimeMillis();
        System.out.println("cost time:"+(end-start));

压缩用到的命令

fasttext quantize -input train.txt -output model -qnorm -retrain -epoch 5 -cutoff 100000

想请教下大佬的问题的所在。

@cgpeter96 cgpeter96 reopened this Nov 23, 2021
@cgpeter96 cgpeter96 changed the title 压缩cpp模型 压缩cpp模型后,java加载模型预测出错 Nov 23, 2021
@jimichan
Copy link
Member

暂时看不出问题

  1. 你确定训练也是单字分词?
  2. 在不压缩的情况下,是否正常?

@cgpeter96
Copy link
Author

暂时看不出问题

  1. 你确定训练也是单字分词?
  2. 在不压缩的情况下,是否正常?

确定是单字训练, 不压缩是正常的。

@jimichan
Copy link
Member

该是新版本又变化了

@cgpeter96
Copy link
Author

该是新版本又变化了

意思是建议我用老版本的fasttext编译一版?

@cgpeter96
Copy link
Author

补充下额外的问题,经过一些测试发现,cpp训练的模型,loss除了softmax,像ns,hs都存在类似溢出现象,具体体现就是所有预测结果均集中于第0个标签,且prob为1.00001。

@jimichan
Copy link
Member

感谢
要是能帮我fix这个问题,就太棒了

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