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

Consider adding the one-hot array creation function #787

Open
NeilGirdhar opened this issue Apr 12, 2024 · 1 comment
Open

Consider adding the one-hot array creation function #787

NeilGirdhar opened this issue Apr 12, 2024 · 1 comment

Comments

@NeilGirdhar
Copy link

NeilGirdhar commented Apr 12, 2024

One-hot is a very common array creation function in machine learning. It might be worth considering its addition.

Various implementations have different semantics:

  • pytorch (Optionally infers the number of classes, cannot select axis)
  • tensorflow (can choose on and off values)
  • jax

From an organization standpoint, I think it probably would belong alongside other creation functions like eye.

Alternatively, one-hot could be generalized to a broadcastable unit-impulse, which is already in scipy. Whereas one-hot chooses one element in a vector to be on, unit-impulse chooses one element in an array to be on.

One-hot is a generalization of the standard (elementary) basis vector that is sometimes requested—a generalization because it supports broadcasting.

@kgryte
Copy link
Contributor

kgryte commented Apr 18, 2024

Thanks, @NeilGirdhar, for opening this issue. This might be another candidate for a "deep learning" extension (ref: #158). Both PyTorch and Jax, which have similar APIs, place it in their nn namespace. While one-hot creation is certainly common, we'd probably need to see a bit more ecosystem uptake and alignment (e.g., CuPy, Dask, NumPy) before consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants