# Normalized softmax in ElementwiseLayer?

**URL:** <https://community.wolfram.com/t/normalized-softmax-in-elementwiselayer/19502>\
**Category:** Questions\
**Tags:** data-science, statistics-and-probability, neural-networks\
**Created:** [January 26, 2022, 8:46am UTC](https://community.wolfram.com/t/normalized-softmax-in-elementwiselayer/19502 "2022-01-26T08:46:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![karen](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@karen](https://community.wolfram.com/u/karen)\
**Post date:** [January 26, 2022, 8:46am UTC](https://community.wolfram.com/t/normalized-softmax-in-elementwiselayer/19502/1 "2022-01-26T08:46:40Z")

</div>

![螢幕擷取畫面2022-01-26163212.png](https://global.discourse-cdn.com/wolfram/original/3X/0/4/04669d31ee2ecdee792f6a7cd3910cf21f601deb.png)

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]

```

---

<div class="post-metadata">

**Author:** ![mfroeling](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mfroeling/32/23010_2.png) [@mfroeling](https://community.wolfram.com/u/mfroeling)\
**Post date:** [January 26, 2022, 3:32pm UTC](https://community.wolfram.com/t/normalized-softmax-in-elementwiselayer/19502/2 "2022-01-26T15:32:48Z")

</div>

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}

```

---

<div class="post-metadata">

**Author:** ![karen](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@karen](https://community.wolfram.com/u/karen)\
**Post date:** [January 27, 2022, 1:41am UTC](https://community.wolfram.com/t/normalized-softmax-in-elementwiselayer/19502/3 "2022-01-27T01:41:11Z")

</div>

Thank you.
