use of ai.djl.training.loss.MaskedSoftmaxCrossEntropyLoss in project djl by deepjavalibrary.
the class TrainSeq2Seq method setupTrainingConfig.
public static DefaultTrainingConfig setupTrainingConfig(Arguments arguments, ExecutorService executorService) {
String outputDir = arguments.getOutputDir();
SaveModelTrainingListener listener = new SaveModelTrainingListener(outputDir);
listener.setSaveModelCallback(trainer -> {
TrainingResult result = trainer.getTrainingResult();
Model model = trainer.getModel();
float accuracy = result.getValidateEvaluation("Accuracy");
model.setProperty("Accuracy", String.format("%.5f", accuracy));
model.setProperty("Loss", String.format("%.5f", result.getValidateLoss()));
});
return new DefaultTrainingConfig(new MaskedSoftmaxCrossEntropyLoss()).addEvaluator(new Accuracy("Accuracy", 2)).optDevices(Engine.getInstance().getDevices(arguments.getMaxGpus())).optExecutorService(executorService).addTrainingListeners(TrainingListener.Defaults.logging(outputDir)).addTrainingListeners(listener);
}
Aggregations