explosion / spaCy

💫 Industrial-strength Natural Language Processing (NLP) in Python

Home Page:https://spacy.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

williamleif opened this issue · comments

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.

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

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

Ok found it, so it's using pathlib .

try:

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

should work!

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.

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

commented

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.