Search in sources :

Example 1 with MaskedSoftmaxCrossEntropyLoss

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);
}
Also used : Accuracy(ai.djl.training.evaluator.Accuracy) MaskedSoftmaxCrossEntropyLoss(ai.djl.training.loss.MaskedSoftmaxCrossEntropyLoss) TrainingResult(ai.djl.training.TrainingResult) SaveModelTrainingListener(ai.djl.training.listener.SaveModelTrainingListener) Model(ai.djl.Model) DefaultTrainingConfig(ai.djl.training.DefaultTrainingConfig)

Aggregations

Model (ai.djl.Model)1 DefaultTrainingConfig (ai.djl.training.DefaultTrainingConfig)1 TrainingResult (ai.djl.training.TrainingResult)1 Accuracy (ai.djl.training.evaluator.Accuracy)1 SaveModelTrainingListener (ai.djl.training.listener.SaveModelTrainingListener)1 MaskedSoftmaxCrossEntropyLoss (ai.djl.training.loss.MaskedSoftmaxCrossEntropyLoss)1