public void saveMalletModel(Model model, File file) { try { if (model.malletModel != null) { ParallelTopicModel newModel = model.malletModel; newModel.write(file); LOGGER.info("Mallet model is saved in " + file.getName()); } else { LOGGER.info("No Mallet model was found in " + "ModelID: " + model.modelId + ", ModelVersion: " + model.modelVersion); } } catch (Exception e) { e.printStackTrace(); } }
this.write(new File(modelFilename + '.' + iteration));
this.write(new File(modelFilename + '.' + iteration));
this.write(new File(modelFilename + '.' + iteration));
@Override protected void execute(JobSettings settings) throws AnalysisEngineProcessException { InstanceList instances = new InstanceList(new TopicModelPipe(stopwords)); instances.addThruPipe(getDocumentsFromMongo()); ParallelTopicModel model = new ParallelTopicModel(numTopics, 1.0, 0.01); model.setNumThreads(numThreads); model.setNumIterations(numIterations); model.addInstances(instances); try { model.estimate(); } catch (IOException e) { getMonitor().warn("Couldn't estimate topic model"); throw new AnalysisEngineProcessException(e); } File serializedModelFile = new File(modelFile); try { Files.createDirectories(serializedModelFile.toPath().getParent()); model.write(serializedModelFile); writeTopicAssignmentsToMongo(instances, new TopicWords(model), model); } catch (IOException e) { throw new AnalysisEngineProcessException("Error writing model", new Object[0], e); } }
@Override protected void execute(JobSettings settings) throws AnalysisEngineProcessException { InstanceList instances = new InstanceList(new TopicModelPipe(stopwords)); instances.addThruPipe(getDocumentsFromMongo()); ParallelTopicModel model = new ParallelTopicModel(numTopics, 1.0, 0.01); model.setNumThreads(numThreads); model.setNumIterations(numIterations); model.addInstances(instances); try { model.estimate(); } catch (IOException e) { getMonitor().warn("Couldn't estimate topic model"); throw new AnalysisEngineProcessException(e); } File serializedModelFile = new File(modelFile); try { Files.createDirectories(serializedModelFile.toPath().getParent()); model.write(serializedModelFile); writeTopicAssignmentsToMongo(instances, new TopicWords(model), model); } catch (IOException e) { throw new AnalysisEngineProcessException("Error writing model", new Object[0], e); } }
@Override public void collectionProcessComplete() throws AnalysisEngineProcessException { try { ParallelTopicModel model = new ParallelTopicModel(nTopics, alphaSum, beta); model.addInstances(getInstanceList()); model.setNumThreads(getNumThreads()); model.setNumIterations(nIterations); model.setBurninPeriod(burninPeriod); model.setOptimizeInterval(optimizeInterval); model.setRandomSeed(randomSeed); model.setSaveSerializedModel(saveInterval, getTargetLocation()); model.setSymmetricAlpha(useSymmetricAlpha); model.setTopicDisplay(displayInterval, displayNTopicWords); model.estimate(); getLogger().info("Writing model to " + getTargetLocation()); File targetFile = new File(getTargetLocation()); if (targetFile.getParentFile() != null) { targetFile.getParentFile().mkdirs(); } model.write(targetFile); } catch (IOException | SecurityException e) { throw new AnalysisEngineProcessException(e); } }