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

Vocab.load throws error due to "/" operator usage with strings. #617

Closed
williamleif opened this issue Nov 10, 2016 · 6 comments
Closed

Vocab.load throws error due to "/" operator usage with strings. #617

williamleif opened this issue Nov 10, 2016 · 6 comments
Labels
bug Bugs and behaviour differing from documentation

Comments

@williamleif
Copy link

williamleif commented Nov 10, 2016

When I attempt to run Vocab.load(path) I get the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-81-2ca5fe3111cd> in <module>()
----> 1 Vocab.load(str(constants.DATA_HOME + "spacy_comments/vocab.bin"))

/afs/cs.stanford.edu/u/wleif/anaconda/lib/python2.7/site-packages/spacy/vocab.pyx in spacy.vocab.Vocab.load (spacy/vocab.cpp:3559)()
     77                 "vectors argument to Vocab.load() deprecated. "
     78                 "Install vectors after loading.")
---> 79         if tag_map is True and (path / 'vocab' / 'tag_map.json').exists():
     80             with (path / 'vocab' / 'tag_map.json').open('r', encoding='utf8') as file_:
     81                 tag_map = json.load(file_)

TypeError: unsupported operand type(s) for /: 'str' and 'unicode'

Looking at error and code it appears that '/' operator is being applied to strings, which my Python does not agree with. Is this an issue with my Python version or something similar? I've tested the use of '/' with strings in Python 3 as well and get the same error.

Thanks!!

Environment

  • Operating System: CentOs 6.8
  • Python Version Used: Python 2.7
  • spaCy Version Used: 1.2.0
  • Environment Information: Standard Anaconda packages.
@williamleif
Copy link
Author

It seems like this / idiom is used throughout your code, so obviously I am missing something... Apologies.

@amn41
Copy link

amn41 commented Nov 10, 2016

Am running into a similar issue trying to load a saved EntityRecogniser.

@amn41
Copy link

amn41 commented Nov 10, 2016

Ok found it, so it's using pathlib .

try:

import pathlib
mypath = pathlib.Path('path/as/string')
mypath / 'file.json'

should work!

@honnibal honnibal added the bug Bugs and behaviour differing from documentation label Nov 10, 2016
@honnibal
Copy link
Member

For future reference: All .load() methods are supposed to take either strings or Path objects. If you pass in a string, it's supposed to be immediately converted to a Path. So, this is a bug.

honnibal added a commit that referenced this issue Nov 10, 2016
@savv
Copy link
Contributor

savv commented Nov 28, 2016

FYI, this is not fixed for loading a saved EntityRecognizer (also ran into same issue)

@lock
Copy link

lock bot commented May 9, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bugs and behaviour differing from documentation
Projects
None yet
Development

No branches or pull requests

4 participants