[SciPy-Dev] Adding logsoftmax function to scipy.special

Takuya Koumura koumura at cycentum.com
Wed Nov 13 00:04:46 EST 2019


Hello,

I raised a GitHub issue (#11058) and was suggested to post it to scipy-dev.

I’m considering to send a PR to add logsoftmax function in scipy.special.
Before that, I would like to hear your opinion (partly because it’s my
first time to send a PR to scipy).

I would like to implement logsoftmax(x) as x-logsumexp(x). Actually,
special.softmax(x) = np.exp(x-logsumexp(x)), so it is trivial for those who
read the source code of softmax, but I think including logsoftmax as a
separate function will be useful for other users. Logsoftmax is more
accurate with inputs that make softmax saturate, eg: When x=[1000, 0],
np.log(softmax(x))=[0, -Inf] (maybe depending on the floating point
precision), while logsoftmax(x)=[0, -1000].

I am planning to add the new function at the bottom of
special/_logsumexp.py following the softmax function, and add some unit
tests in special/test/test_logsumexp.py. If you have comments, I’d
appreciate any.

Best wishes,
--
Takuya KOUMURA
koumura at cycentum.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20191113/59fd3cf0/attachment.html>


More information about the SciPy-Dev mailing list