Message Boards Message Boards

Normalized softmax in ElementwiseLayer?

Posted 2 years ago

enter image description here

I want to use my softmax as below not SoftmaxLayer[]. I have tried many times. But it still can't work. Below is my code now. How to rewrite it?

ElementwiseLayer[Exp[Normalize[#] &], Total]
POSTED BY: Pei Hsuan Shen
2 Replies
Posted 2 years ago

Thank you.

POSTED BY: Pei Hsuan Shen

ElementwiseLayer applies the function to each element of the inputlist. so it cannot calculate the mean.

You have to use FunctionLayer

In[39]:= soft = FunctionLayer[Exp[#]/Total[Exp[#]] &]
list = N@{1, 2, 3, 4, 5};
Exp[list]/Total[Exp[list]]
soft[list]

Out[39]= FunctionLayer[ <> ]

Out[41]= {0.0116562, 0.0316849, 0.0861285, 0.234122, 0.636409}

Out[42]= {0.0116562, 0.0316849, 0.0861285, 0.234122, 0.636409}
POSTED BY: Martijn Froeling
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract