softmax
¶
Functions:
| Name | Description |
|---|---|
softmax |
Computes a sparsely evaluated softmax: the entries of |
softmax
¶
softmax(
src: array,
index: Optional[array] = None,
ptr: Optional[array] = None,
num_nodes: Optional[int] = None,
axis: int = 0,
) -> array
Computes a sparsely evaluated softmax: the entries of src are grouped
by index along axis and normalized within each group (e.g. the
attention scores of the incoming edges of each node).
PyG-named version of scatter_softmax().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
array
|
The values to normalize. |
required |
index
|
Optional[array]
|
The group of each entry of |
None
|
ptr
|
Optional[array]
|
Alternatively to |
None
|
num_nodes
|
Optional[int]
|
Number of groups. Inferred from |
None
|
axis
|
int
|
The axis along which to group. Default: |
0
|
Returns:
| Type | Description |
|---|---|
array
|
An array of the shape of |
Example:
src = mx.array([1.0, 1.0, 1.0, 1.0])
index = mx.array([0, 0, 1, 2])
softmax(src, index)
# mx.array([0.5, 0.5, 1.0, 1.0])
Source code in mlx_graphs/utils/softmax.py
from mlx_graphs.utils import softmax · mlx_graphs/utils/softmax.py