2

How to load the downloaded pretrained pipeline and where is it explained in the document?

import spacy
spacy.cli.download("en_core_web_sm", False, False, "--target", "/tmp/spacy")
nlp = spacy.load("/tmp/spacy/en_core_web_sm")
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Cell In[9], line 1
----> 1 nlp = spacy.load("/tmp/spacy/en_core_web_sm")

File ~/venv/tf/lib/python3.9/site-packages/spacy/__init__.py:54, in load(name, vocab, disable, enable, exclude, config)
     30 def load(
     31     name: Union[str, Path],
     32     *,
   (...)
     37     config: Union[Dict[str, Any], Config] = util.SimpleFrozenDict(),
     38 ) -> Language:
     39     """Load a spaCy model from an installed package or a local path.
     40 
     41     name (str): Package name or model path.
   (...)
     52     RETURNS (Language): The loaded nlp object.
     53     """
---> 54     return util.load_model(
     55         name,
     56         vocab=vocab,
     57         disable=disable,
     58         enable=enable,
     59         exclude=exclude,
     60         config=config,
     61     )

File ~/venv/tf/lib/python3.9/site-packages/spacy/util.py:434, in load_model(name, vocab, disable, enable, exclude, config)
    432         return load_model_from_package(name, **kwargs)  # type: ignore[arg-type]
    433     if Path(name).exists():  # path to model data directory
--> 434         return load_model_from_path(Path(name), **kwargs)  # type: ignore[arg-type]
    435 elif hasattr(name, "exists"):  # Path or Path-like to model data
    436     return load_model_from_path(name, **kwargs)  # type: ignore[arg-type]

File ~/venv/tf/lib/python3.9/site-packages/spacy/util.py:505, in load_model_from_path(model_path, meta, vocab, disable, enable, exclude, config)
    503 config_path = model_path / "config.cfg"
    504 overrides = dict_to_dot(config)
--> 505 config = load_config(config_path, overrides=overrides)
    506 nlp = load_model_from_config(
    507     config,
    508     vocab=vocab,
   (...)
    512     meta=meta,
    513 )
    514 return nlp.from_disk(model_path, exclude=exclude, overrides=overrides)

File ~/venv/tf/lib/python3.9/site-packages/spacy/util.py:681, in load_config(path, overrides, interpolate)
    679 else:
    680     if not config_path or not config_path.is_file():
--> 681         raise IOError(Errors.E053.format(path=config_path, name="config file"))
    682     return config.from_disk(
    683         config_path, overrides=overrides, interpolate=interpolate
    684     )

OSError: [E053] Could not read config file from /tmp/spacy/en_core_web_sm/config.cfg

Below worked but it depends on the version, hence should not be the correct way.

nlp = spacy.load("/tmp/spacy/en_core_web_sm/en_core_web_sm-3.5.0/")

Environmnet

python 3.9.13
spacy 3.5.0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.