<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 11.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 4.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/BNNSActivationFunction/BNNSActivationFunctionSoftmax",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration Case",
  "symbol" : {
    "kind" : "Enumeration Case",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@EA@BNNSActivationFunction@BNNSActivationFunctionSoftmax"
  },
  "title" : "BNNSActivationFunctionSoftmax"
}
-->

# BNNSActivationFunctionSoftmax

An activation function that returns the softmax function of its input.

```
BNNSActivationFunctionSoftmax
```

## Discussion

This constant defines an activation function that returns values using the following formula:

![General formula that describes mathematically the softmax activation function. s open bracket x sub i close bracket equals  the exponential of x sub i over summation from j equals one to n times the exponential of x sub j.](images/com.apple.accelerate/media-3401551@2x.png)

The softmax function transforms a vector of real numbers into a vector of probabilities. Each probability in the result is in the range 0…1, and the sum of the probabilities is 1.

The following code shows how to apply the softmax function to a vector that contains seven elements:

```swift
let inputs: [Float] = [3, 5, 1, 6, 2, 1, 4]
let count = inputs.count
var outputs = [Float](repeating: 0,
                      count: count)

var inDescription = BNNSVectorDescriptor(size: count,
                                         data_type: .float)
var outDescription = BNNSVectorDescriptor(size: count,
                                          data_type: .float)
var activation = BNNSActivation(function: .softmax)
var filterParameters = BNNSFilterParameters()

let activationLayer = BNNSFilterCreateVectorActivationLayer(&inDescription,
                                                            &outDescription,
                                                            &activation,
                                                            &filterParameters)

BNNSFilterApply(activationLayer, inputs, &outputs)
```

On return, the softmax function calculates the following values:

|Inputs|Outputs      |
|------|-------------|
|`3.0` |`0.031415492`|
|`5.0` |`0.23213086` |
|`1.0` |`0.004251625`|
|`6.0` |`0.63099706` |
|`2.0` |`0.011557114`|
|`1.0` |`0.004251625`|
|`4.0` |`0.08539616` |

Changing the fourth element in `inputs` to 10 increases its probability to almost 1.0:

|Inputs|Outputs        |
|------|---------------|
|`3.0` |`0.00090221845`|
|`5.0` |`0.0066665425` |
|`1.0` |`0.00012210199`|
|`10.0`|`0.98940265`   |
|`2.0` |`0.00033190762`|
|`1.0` |`0.00012210199`|
|`4.0` |`0.002452484`  |

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)