Spacy 权限错误 13

Spacy Permission Error 13

尝试在 spacy 中保存经过训练的模型时出现权限错误 13。我也尝试过更改目录。我正在尝试重现给定 here 的示例,以在 spacy 的命名实体识别器中训练自定义实体。

import random 

TRAIN_DATA = [
     ("Uber blew through  million a week", {'entities': [(0, 4, 'ORG')]}),
     ("Google rebrands its business apps", {'entities': [(0, 6, "ORG")]})
]

nlp = spacy.blank('en')
optimizer = nlp.begin_training()
for i in range(20):
    random.shuffle(TRAIN_DATA)
    for text, annotations in TRAIN_DATA:
        nlp.update([text], [annotations], sgd=optimizer)
nlp.to_disk('/model')

这是我遇到的错误

PermissionError                           Traceback (most recent call last)
<ipython-input-5-115363841730> in <module>()
     14     for text, annotations in TRAIN_DATA:
     15         nlp.update([text], [annotations], sgd=optimizer)
---> 16 nlp.to_disk('/model')

~/anaconda2/envs/py35/lib/python3.5/site-packages/spacy/language.py in to_disk(self, path, disable)
    596             serializers[name] = lambda p, proc=proc: proc.to_disk(p, vocab=False)
    597         serializers['vocab'] = lambda p: self.vocab.to_disk(p)
--> 598         util.to_disk(path, serializers, {p: False for p in disable})
    599 
    600     def from_disk(self, path, disable=tuple()):

~/anaconda2/envs/py35/lib/python3.5/site-packages/spacy/util.py in to_disk(path, writers, exclude)
    508     path = ensure_path(path)
    509     if not path.exists():
--> 510         path.mkdir()
    511     for key, writer in writers.items():
    512         if key not in exclude:

~/anaconda2/envs/py35/lib/python3.5/pathlib.py in mkdir(self, mode, parents, exist_ok)
   1214             self._raise_closed()
   1215         try:
-> 1216             self._accessor.mkdir(self, mode)
   1217         except FileNotFoundError:
   1218             if not parents or self.parent == self:

~/anaconda2/envs/py35/lib/python3.5/pathlib.py in wrapped(pathobj, *args)
    369         @functools.wraps(strfunc)
    370         def wrapped(pathobj, *args):
--> 371             return strfunc(str(pathobj), *args)
    372         return staticmethod(wrapped)
    373 

PermissionError: [Errno 13] Permission denied: '/model'

我认为可能是您使用的路径 /model 被视为绝对路径,因此要么退出用户可写的 /model 目录,要么您可以尝试使用路径像 ./model 这是一个相对路径