({{, (RefLink[TrainingProgressFunction, paclet:ref/TrainingProgressFunction]) 
is an option for (RefLink[NetTrain, paclet:ref/NetTrain]) that specifies a function to run periodically during training.}})

OpenersNotesSection(Spacer1)Details

With the default value of (RefLink[TrainingProgressFunction, paclet:ref/TrainingProgressFunction])->(RefLink[None, paclet:ref/None]), no function is run.

Setting (RefLink[TrainingProgressFunction, paclet:ref/TrainingProgressFunction])->f specifies that f[assoc] is evaluated after every training round, where assoc is an association with the following keys:

The keys "ValidationLoss", "LowestValidationLoss", etc. are applicable only in the case that the option (RefLink[ValidationSet, paclet:ref/ValidationSet]) was specified to (RefLink[NetTrain, paclet:ref/NetTrain]).

Setting (RefLink[TrainingProgressFunction, paclet:ref/TrainingProgressFunction])->{f,"Interval"->(RefLink[Quantity, paclet:ref/Quantity])[n,"unit"]} specifies the interval at which to apply f. Possible forms of "unit" include:

The suboption {f,…,"MinimumInterval"->n} specifies that f should not be applied more frequently than once every n seconds. If unspecified, there is no limit on how frequently f is applied.

Setting (RefLink[TrainingProgressFunction, paclet:ref/TrainingProgressFunction])->{(Subscript[spec, 1]),(Subscript[spec, 2]),…} specifies multiple functions to evaluate, which can have different intervals.

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Use (RefLink[TrainingProgressFunction, paclet:ref/TrainingProgressFunction]) to append information about the state of training to a file. Create a log file:

logFile=CreateTemporary[]

Define functions to append the batch number and loss to the log file:

appendToLog=PutAppend[<|"Batch"->#AbsoluteBatch,"Loss"->#RoundLoss|>,logFile]&;

Define the training data and perform training:

trainingData={#1,#2}->{#1+Sin[#1*#2]}&@@@RandomReal[{-1,1},{50000,2}];

NetTrain[
NetChain[{1000,Tanh,1},"Input"->2],
trainingData,MaxTrainingRounds->Quantity[10,"Seconds"],
TrainingProgressFunction->appendToLog];

Read the log file:

logData=ReadList[logFile];
Take[logData,3]

Put the saved data into a (RefLink[Dataset, paclet:ref/Dataset]):

dataset=Dataset[logData]

Plot the loss over value over time:

ListLinePlot[dataset,PlotRange->All,ScalingFunctions->"Log"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[NetTrain, paclet:ref/NetTrain])  ▪  (RefLink[NetTrainResultsObject, paclet:ref/NetTrainResultsObject])  ▪  (RefLink[TrainingProgressReporting, paclet:ref/TrainingProgressReporting])  ▪  (RefLink[TrainingProgressCheckpointing, paclet:ref/TrainingProgressCheckpointing])  ▪  (RefLink[ClassifierMeasurements, paclet:ref/ClassifierMeasurements])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Neural Networks in the Wolfram Language, paclet:tutorial/NeuralNetworksOverview])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Neural Networks, paclet:guide/NeuralNetworks])}})}})