Spacy权限错误13

时间:2018-01-09 09:54:51

标签: python nlp spacy

尝试在spacy中保存训练有素的模型时,我收到权限错误13。我也尝试过更改目录。我试图在给定here的情况下重现这个例子,以便在spacy命名的实体识别器中训练自定义实体。

import random 

TRAIN_DATA = [
     ("Uber blew through $1 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'

1 个答案:

答案 0 :(得分:3)

我认为您使用/model的路径可能被视为绝对路径,因此要么退出用户可写入的/model目录,要么尝试使用类似{的路径{1}}这是一个相对路径