sparsemax | R Documentation |
Normalizing sparse transform (a la softmax).
sparsemax(dim = -1L)
sparsemax15(dim = -1L, k = NULL)
dim |
The dimension along which to apply sparsemax. |
k |
The number of largest elements to partial-sort input over. For optimal
performance, |
Solves the projection:
\min_P ||input - P||_2 \text{ s.t. } P \geq0, \sum(P) ==1
The projection result, such that \sum_{dim} P = 1 \forall dim
elementwise.
input <- torch::torch_randn(10, 5, requires_grad = TRUE)
# create a top3 alpha=1.5 sparsemax on last input dimension
nn_sparsemax <- sparsemax15(dim=1, k=3)
result <- nn_sparsemax(input)
print(result)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.