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

TypeError in random.sample(np.array()), word2vec_basic.py with Python3.5 #1760

Closed
DSLituiev opened this issue Apr 4, 2016 · 4 comments
Closed

Comments

@DSLituiev
Copy link

Environment info

Operating System:
MacOS10.10.5 (14F1713)

  1. Which pip package you installed.
    pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp35-none-any.whl

    git clone https://github.com/tensorflow/tensorflow
    git checkout r0.7

  2. The output from python -c "import tensorflow; print(tensorflow.version)".
    0.7.1

  3. numpy.version.full_version

    Out[4]: '1.11.0'

    Installed as described above with pip3, running script from commit 263d00d

Steps to reproduce

  python3 tensorflow/examples/tutorials/word2vec/word2vec_basic.py

What have you tried?

  1. This simple example fails:
    random.sample(np.arange(1000), 60)

it looks like it relates to this numpy issue

Logs or other output that would be helpful

(If logs are large, please upload as attachment).

Found and verified text8.zip
Data size 17005207
Most common words (+UNK) [['UNK', 418391], (b'the', 1061396), (b'of', 593677), (b'and', 416629), (b'one', 411764)]
Sample data [5240, 3084, 12, 6, 195, 2, 3135, 46, 59, 156]
3084 -> 5240
b'originated' -> b'anarchism'
3084 -> 12
b'originated' -> b'as'
12 -> 6
b'as' -> b'a'
12 -> 3084
b'as' -> b'originated'
6 -> 12
b'a' -> b'as'
6 -> 195
b'a' -> b'term'
195 -> 2
b'term' -> b'of'
195 -> 6
b'term' -> b'a'
Traceback (most recent call last):
  File "tensorflow/examples/tutorials/word2vec/word2vec_basic.py", line 131, in <module>
    valid_examples = np.array(random.sample(np.arange(valid_window), valid_size))
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/random.py", line 311, in sample
    raise TypeError("Population must be a sequence or set.  For dicts, use list(d).")
TypeError: Population must be a sequence or set.  For dicts, use list(d).
@DSLituiev
Copy link
Author

Fix: line 131:
before

 valid_examples = np.array(random.sample(np.arange(valid_window), valid_size))

after

 valid_examples = np.array(random.sample(range(valid_window), valid_size))

@vrv
Copy link

vrv commented Apr 4, 2016

Cool, thanks! Do you want to send us a PR?

@DSLituiev
Copy link
Author

Yes I will

@vrv
Copy link

vrv commented Apr 4, 2016

Thanks!

@vrv vrv closed this as completed Apr 4, 2016
fsx950223 pushed a commit to fsx950223/tensorflow that referenced this issue Nov 28, 2023
…upstream-sync-220711

Develop upstream sync 220711
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