Created
November 6, 2016 21:26
-
-
Save robhinds/78ff94ba132a8f25977aaf775ff2e358 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def trainModel() = { | |
val charset = Charset.forName("UTF-8") | |
val lineStream: ObjectStream[String] = new PlainTextByLineStream(new FileInputStream(s"src/main/resources/trainingdata.txt"), charset) | |
val sampleStream = new NameSampleDataStream(lineStream) | |
try { | |
val params = TrainingParameters.defaultParams() | |
params.put(TrainingParameters.ALGORITHM_PARAM, QNTrainer.MAXENT_QN_VALUE) | |
model = NameFinderME.train("en", "food", sampleStream, params, new TokenNameFinderFactory()) | |
} | |
finally { | |
sampleStream.close() | |
} | |
try { | |
modelOut = new BufferedOutputStream(new FileOutputStream(s"src/main/resources/en-ingredients-finder.bin")) | |
model.serialize(modelOut) | |
} finally { | |
if (modelOut != null) | |
modelOut.close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment