1
$\begingroup$

I'm trying to learn neural networks in the Wolfram language, so I've written the following code. The input is a $2*3$ matrix, split into two parts. The parts are given to distinct linear layers, then the results concatenated and soft-maxed.

g1 = NetGraph[<|  "c" -> CatenateLayer[], "s" -> SoftmaxLayer[],
    "p1" -> PartLayer[1,"Input" -> {2, 3}], "p2" -> PartLayer[2, "Input" -> {2, 3}],
     "l1" -> LinearLayer[1], "l2" ->  LinearLayer[1]|>,
   {NetPort["input"] -> "p1" -> "l1", 
    NetPort["input"] -> "p2" -> "l2", 
    {"l1", "l2"} -> "c" -> "s" ->  NetPort["output"]}];

g2 = NetInitialize[g1]
g2[{{1, 2, 3}, {4, 5, 6}}]
NetTrain[g2, {{{1, 2, 3}, {4,5,6}} -> {0.2, 0.8}}]

Initializations and initial evaluations work, but training does not. This gives the following error: network error I don't know what's causing it or how to fix it. The network seems correct as far as I can tell.

$\endgroup$

1 Answer 1

1
$\begingroup$

See this answer: NetTrain & SoftmaxLayer: Expected a vector of indices.

$\endgroup$
5
  • $\begingroup$ I've missed the bracket in the post but not in the actual notebook code I was running. I've corrected it now. Try and run the code to see if the bug occurs. $\endgroup$ Commented Mar 7, 2021 at 0:09
  • $\begingroup$ Works for me on 12.1.1.0 (OS X). Maybe try restarting WL. $\endgroup$ Commented Mar 7, 2021 at 0:11
  • $\begingroup$ I am using 12.2. I will try restarting. $\endgroup$ Commented Mar 7, 2021 at 0:16
  • 1
    $\begingroup$ Ok, wait, I see what you mean (my messages window was hidden). Does this post resolve the issue for you? mathematica.stackexchange.com/questions/175575/… $\endgroup$ Commented Mar 7, 2021 at 0:20
  • $\begingroup$ Yes. Explicitly specifying the loss function does fix the error. Thank you. $\endgroup$ Commented Mar 7, 2021 at 0:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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