Spacy Permission Error 13


I am getting Permission error 13 when trying to save a trained model in spacy. I have tried changing the directory as well. I am trying to reproduce this example given here, to train custom entities in spacy`s named entity recognizer.

import random 

     ("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):
    for text, annotations in TRAIN_DATA:
        nlp.update([text], [annotations], sgd=optimizer)

Here is the error I am getting

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/ 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})
    600     def from_disk(self, path, disable=tuple()):

~/anaconda2/envs/py35/lib/python3.5/site-packages/spacy/ 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/ 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/ in wrapped(pathobj, *args)
    369         @functools.wraps(strfunc)
    370         def wrapped(pathobj, *args):
--> 371             return strfunc(str(pathobj), *args)
    372         return staticmethod(wrapped)

PermissionError: [Errno 13] Permission denied: '/model'
Asked By: joel



I think that it can be that the path you use /model is seen as an absolute path, so either exits a /model directory writeable by the user or you can try to use a path like ./model which is a relative path

Answered By: Gianluca
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.