Bruce
Bruce

Reputation: 8849

OpenNLP save a trained model

I used OpenNLP for Name Entity Recognition(NER). They have their own models here. But their NER domain is not suitable with myone. So trained my own model using this code

            FileReader fileReader = new FileReader("res/review_train");
            ObjectStream fileStream = new PlainTextByLineStream(fileReader);
            ObjectStream sampleStream = new NameSampleDataStream(fileStream);
            TokenNameFinderModel model = NameFinderME.train("pt-br", "train", sampleStream, Collections.<String, Object>emptyMap());
            nfm = new NameFinderME(model);

Here review_train is the text file containing trained text.Problem is Every time when i run it takes too much time to train the data. Is there any way to save this trained model and reuse it?

Upvotes: 1

Views: 887

Answers (1)

Bruce
Bruce

Reputation: 8849

You can save model using this code and reuse without train again and again

BufferedOutputStream modelOut = new BufferedOutputStream(new FileOutputStream("filename"));
model.serialize(modelOut);

Upvotes: 1

Related Questions