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

[bug]: np.bincount prepends zeros in data/emnist.py #85

Open
mariovas3 opened this issue Mar 22, 2024 · 0 comments
Open

[bug]: np.bincount prepends zeros in data/emnist.py #85

mariovas3 opened this issue Mar 22, 2024 · 0 comments

Comments

@mariovas3
Copy link

mariovas3 commented Mar 22, 2024

I checked this issue has not been duplicated.

Hi @charlesfrye , I'm not sure if this repo is accepting PRs, but I spotted a bug in the data/emnist.py file. It concerns the _sample_to_balance function and the usage of np.bincount in it here.

Because you offset the labels by NUM_SPECIAL_TOKENS here and here before calling the subsampling function, np.bincount will prepend zeros to the missing elements from 0 to y_min_element-1 inclusive and will bias the mean towards zero. This could lead to a smaller dataset.

Example behaviour of np.bincount:

>>> import numpy as np
>>> y = np.array([0, 1, 0, 2, 1])
>>> np.bincount(y)
array([2, 2, 1])
>>> NUM_SPECIAL_TOKENS = 4
>>> np.bincount(y + NUM_SPECIAL_TOKENS)
array([0, 0, 0, 0, 2, 2, 1])

I have proposed a solution to the described bug in this PR.

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

1 participant