2
$\begingroup$

New to neural network models in Mathematica and working my way through documentation and examples:

Have a model where I would like to map real number vectors of length 15 to predict an output vector of length 108. I am using a MeanSquaredLossLayer to calculate the error between the network output and the target data (weeklyReturns).

Here is my code:

Dimensions[features]
{15, 1611}
Dimensions[weeklyReturns]
{108, 1611}

coder = NetChain[{LogisticSigmoid, 15, DropoutLayer[0.1], 
   LogisticSigmoid, 108, LogisticSigmoid, 108}]
      trainer = 
 NetGraph[{coder, MeanSquaredLossLayer[]}, {1 -> NetPort[2, "Input"]},
   "Input" -> 15]
trainer = NetInitialize[trainer]

 {trainedNet, lowestVal} = 
 NetTrain[trainer, <|"Input" -> features, 
   "Target" -> weeklyReturns|>, {"TrainedNet", 
   "LowestValidationLoss"}, TargetDevice -> "GPU", 
  MaxTrainingRounds -> 500000, Method -> "ADAM", 
  ValidationSet -> Scaled[0.1], BatchSize -> 64]

Getting the following error:

During evaluation of In[377]:= NetTrain::invinlen: Inconsistent numbers of examples provided to ports: lengths were <|Input->15,Target->108|>.

During evaluation of In[377]:= Set::shape: Lists {trainedNet,lowestVal} and $Failed are not the same shape.

Out[377]= $Failed

Can anyone explain this error and how I can fix the problem? Many thanks.

$\endgroup$
2
$\begingroup$

The error means that you have different numbers of data points for the "Input" port and the "Target" port. You can fix the problem by:

NetTrain[trainer, <|"Input" -> Transpose@features, 
  "Target" -> Transpose@weeklyReturns|>, {"TrainedNet", "LowestValidationLoss"},
  TargetDevice -> "GPU", MaxTrainingRounds -> 500000, 
 Method -> "ADAM", ValidationSet -> Scaled[0.1], BatchSize -> 64]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.