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

Saving and Loading model can be tricky due to NullPointerExceptions. May I add documentation for this? #6

Closed
cruxcode opened this issue Jun 12, 2019 · 3 comments

Comments

@cruxcode
Copy link

Adding to documentation.

@yoavartzi
Copy link
Member

yoavartzi commented Jun 12, 2019

Maybe best to write about it here. Not sure how to add it to the README, and we are currently not actively maintaining SPF.

@cruxcode
Copy link
Author

Ok!
Writing Model is easy

            File savedModel = new File("SavedModels/mdl1");
            boolean fvar = savedModel.createNewFile();
            Model.<Sentence, LogicalExpression>write(model, savedModel);

Loading model
Be sure to instantiate all services (LogicLanguageService) before reading saved model file. Below code copied from geoquery example. Remember not to close ontology.

			LogicLanguageServices.setInstance(new LogicLanguageServices.Builder(
					new TypeRepository(typesFile), new FlexibleTypeComparator())
							.addConstantsToOntology(simpleOntology)
							.addConstantsToOntology(predOntology)
							.setUseOntology(true).setNumeralTypeName("i")
							.build());

Initialize log if needed.
Build a parser. This parser may not be same as the parser used during training. Look at GeoSimpleExp for example.
Now you are ready to read the model.

                        savedModelFile = new File(filename);
                        model = Model.<Sentence, LogicalExpression>readModel(savedModelFile);

Predict
Here's an example:

        public static IGraphParserOutput<LogicalExpression> predict(String sentence) {
                Sentence dataItem = new Sentence(sentence);
                return parser.parse(dataItem, new DataItemModel<Sentence, LogicalExpression>(model, dataItem), true);
        }

@yoavartzi
Copy link
Member

This is great. Thanks! I linked to this issue for the README.

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