Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for softmax with axis overloads #13

Open
taless474 opened this issue Mar 8, 2019 · 0 comments
Open

Request for softmax with axis overloads #13

taless474 opened this issue Mar 8, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@taless474
Copy link
Contributor

Blaze supports the softmax operation and its rowwise and columnwise overloads (ref).
I like to request for the blaze_tensor to support this operation for tensors. As an example:

#include <iostream>
#include <blaze/Math.h>
int main()
{
    blaze::StaticTensor<double, 2UL, 3UL, 3UL> A{ { { 1.0, 2.0, 3.0 }
                                     , { 4.0, 1.0, 2.0 }
                                     , { 3.0, 4.0, 1.0 } },
                                      { { 3.0, 6.0, 2.0}
                                     , { -2.0, 2.0, 0.0 }
                                     , { 1.0, 1.0, 3.0 } } };
    blaze::StaticTensor<double, 2UL, 3UL, 3UL> B;
    B = blaze::softmax<blaze::columnwise>(A);     
    std::cout << B << "\n";
    return 0;
}

results in

[[[ 0.09003057,  0.24472847,  0.66524096],
[ 0.84379473,  0.04201007,  0.1141952 ],
[ 0.25949646,  0.70538451,  0.03511903]],

[[ 0.04661262,  0.93623955,  0.01714783],
[ 0.01587624,  0.86681333,  0.11731043],
[ 0.10650698,  0.10650698,  0.78698604]]]

An example of possible python implementation is:

import numpy as np
def softmax(x, axis=-1):
    y = np.exp(x - np.max(x, axis, keepdims=True))
    return y / np.sum(y, axis, keepdims=True)

however, the blaze implementation would be mappped on the above function if we use softmax<rowwise> as axis=1 and softmax<columnwise> as axis=0.

@taless474 taless474 added the enhancement New feature or request label Mar 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant