stan-dev / stan-dev/math

a more efficient (log)sofmax

Open
#2,802 17 comments 0 reactions 1 assignee View on GitHub

@bob-carpenter is already working on this.

Since Aug 10, 2022.

Dominant language
C++
Stars
839
Forks
220
Avg merge
2d 4h
Merged PRs (30d)
14

Description

I've just recently read https://academic.oup.com/imajna/article/41/4/2311/5893596?login=false
which shows that for log-softmax implemented as

a <- max(x); log(exp(x - a)/sum(exp(x-a)))

is more accurate than this version (which as far as I understand the hpp files is the one that Stan uses)

x - matrixStats::logSumExp(x)

(Sorry for the R code, but the point is the same).

I just thought it was worth to point this out. If there are good reasons for the way softmax is implemented, please just close and ignore, otherwise it might be useful...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.