简体   繁体   中英

unable to load NER pipeline with nlp.from_disk()

I am trying to load a pre-trained pipeline into my code like this:

nlp = de_core_news_sm.load()
nlp = nlp.from_disk('./TRAINED/Background/')

but I get a versos error saying:

ValueError                                Traceback (most recent call last)
<ipython-input-4-1f41fefa6daa> in <module>
      1 nlp = de_core_news_sm.load()
----> 2 nlp = nlp.from_disk('./TRAINED/Background/')
      3 print(nlp)

/opt/anaconda3/lib/python3.8/site-packages/spacy/language.py in from_disk(self, path, exclude, disable)
    972             # Convert to list here in case exclude is (default) tuple
    973             exclude = list(exclude) + ["vocab"]
--> 974         util.from_disk(path, deserializers, exclude)
    975         self._path = path
    976         return self

/opt/anaconda3/lib/python3.8/site-packages/spacy/util.py in from_disk(path, readers, exclude)
    688         # Split to support file names like meta.json
    689         if key.split(".")[0] not in exclude:
--> 690             reader(path / key)
    691     return path
    692 

/opt/anaconda3/lib/python3.8/site-packages/spacy/language.py in deserialize_vocab(path)
    948         def deserialize_vocab(path):
    949             if path.exists():
--> 950                 self.vocab.from_disk(path)
    951             _fix_pretrained_vectors_name(self)
    952 

vocab.pyx in spacy.vocab.Vocab.from_disk()

strings.pyx in spacy.strings.StringStore.from_disk()

/opt/anaconda3/lib/python3.8/site-packages/srsly/_json_api.py in read_json(location)
     48         data = sys.stdin.read()
     49         return ujson.loads(data)
---> 50     file_path = force_path(location)
     51     with file_path.open("r", encoding="utf8") as f:
     52         return ujson.load(f)

/opt/anaconda3/lib/python3.8/site-packages/srsly/util.py in force_path(location, require_exists)
     19         location = Path(location)
     20     if require_exists and not location.exists():
---> 21         raise ValueError("Can't read file: {}".format(location))
     22     return location
     23 

ValueError: Can't read file: TRAINED/Background/vocab/strings.json

If I open the Vocab folder on my macOS, there's no string.json file. Just a few exec files. What can I do to properly read the model?

You need to have a directory structure like below in order to load a spacy model. In your case, there is not strings.json file in the directory which is throwing the error. 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM